[PATCH 2/2] dbus: Add API for USD

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



USD had a control interface commands and events defined for it. Extend
this by providing similar USD APIs through the dbus control interface.

Signed-off-by: Lo,Chin-Ran <chin-ran.lo@xxxxxxx>
---
 wpa_supplicant/dbus/dbus_new.c          | 271 +++++++++++++++
 wpa_supplicant/dbus/dbus_new.h          |  40 +++
 wpa_supplicant/dbus/dbus_new_handlers.c | 419 ++++++++++++++++++++++++
 wpa_supplicant/dbus/dbus_new_handlers.h |  12 +
 wpa_supplicant/dbus/dbus_new_helpers.h  |  14 +
 wpa_supplicant/notify.c                 |  11 +
 6 files changed, 767 insertions(+)

diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 76e42ffbcc77..4274a82bb56f 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -3648,6 +3648,45 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
 	  }
 	},
 #endif /* CONFIG_AUTOSCAN */
+#ifdef CONFIG_NAN_USD
+	{ "NANPublish", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  (WPADBusMethodHandler) wpas_dbus_handler_nan_publish,
+	  {
+		  { "nan_args", "s", ARG_IN },
+		  { "publish_id", "i", ARG_OUT },
+		  END_ARGS
+	  }
+	},
+	{ "NANCancelPublish", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  (WPADBusMethodHandler) wpas_dbus_handler_nan_cancel_publish,
+	  {
+		  { "nan_args", "s", ARG_IN },
+		  END_ARGS
+	  }
+	},
+	{ "NANSubscribe", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  (WPADBusMethodHandler) wpas_dbus_handler_nan_subscribe,
+	  {
+		  { "nan_args", "s", ARG_IN },
+		  { "subscribe_id", "i", ARG_OUT },
+		  END_ARGS
+	  }
+	},
+	{ "NANCancelSubscribe", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  (WPADBusMethodHandler) wpas_dbus_handler_nan_cancel_subscribe,
+	  {
+		  { "nan_args", "s", ARG_IN },
+		  END_ARGS
+	  }
+	},
+	{ "NANTransmit", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  (WPADBusMethodHandler) wpas_dbus_handler_nan_transmit,
+	  {
+		  { "nan_args", "s", ARG_IN },
+		  END_ARGS
+	  }
+	},
+#endif /* CONFIG_NAN_USD */
 #ifdef CONFIG_TDLS
 	{ "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
 	  (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
@@ -4038,6 +4077,38 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
 		  END_ARGS
 	  }
 	},
+#ifdef CONFIG_NAN_USD
+	{ "NANDiscoveryresult", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  {
+		  { "success", "b", ARG_OUT },
+		  { "discov_info", "a{sv}", ARG_OUT },
+		  { "ssi", "a{sv}", ARG_OUT },
+		  END_ARGS
+	  }
+	},
+	{ "NANReceive", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  {
+		  { "nanrx_info", "a{sv}", ARG_OUT },
+		  { "ssi", "a{sv}", ARG_OUT },
+		  END_ARGS
+	  }
+	},
+	{ "NanPublishterminated", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  {
+		  { "publish_id", "i", ARG_OUT },
+		  { "reason", "i", ARG_OUT },
+		  END_ARGS
+	  }
+	},
+	{ "NanSubscribeterminated", WPAS_DBUS_NEW_IFACE_INTERFACE,
+	  {
+		  { "term_subscribe_id", "i", ARG_OUT },
+		  { "reason", "i", ARG_OUT },
+		  END_ARGS
+	  }
+	},
+
+#endif /* CONFIG_NAN_USD */
 	{ "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
 	  {
 		  { "path", "o", ARG_OUT },
@@ -5243,3 +5314,203 @@ void wpas_dbus_signal_hs20_t_c_acceptance(struct wpa_supplicant *wpa_s,
 	dbus_message_unref(msg);
 }
 #endif /* CONFIG_HS20 */
+
+
+#ifdef CONFIG_NAN_USD
+
+/**
+ * wpas_dbus_signal_nan_discoveryresult - Send NAN discovery result signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @subscribe_id: Subscribe id of the session
+ * @peer_publish_id: Publish id of the sender
+ * @peer_addr: MAC address of the peer device
+ * @ssi: Service specific information payload
+ * @ssi_len: Length of the SSI field
+ *
+ * Notify the discovery-result
+ */
+void wpas_dbus_signal_nan_discovery_result(struct wpa_supplicant *wpa_s,
+					   int subscribe_id,
+					   int peer_publish_id,
+					   const u8 *peer_addr,
+					   const u8 *ssi, size_t ssi_len)
+{
+	struct wpas_dbus_priv *iface;
+	DBusMessage *msg;
+	DBusMessageIter iter, dict_iter;
+	dbus_bool_t succ;
+	struct wpa_dbus_discov_info disc_info;
+
+	iface = wpa_s->global->dbus;
+
+	/* Do nothing if the interface is not turned on */
+	if (!iface || !wpa_s->dbus_new_path)
+		return;
+
+	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+				      WPAS_DBUS_NEW_IFACE_INTERFACE,
+				      "NanDiscoveryresult");
+	if (!msg)
+		return;
+
+	dbus_message_iter_init_append(msg, &iter);
+	succ = TRUE;
+	disc_info.subscribe_id = subscribe_id;
+	disc_info.peer_publish_id = peer_publish_id;
+	memcpy(disc_info.peer_addr, peer_addr, ETH_ALEN);
+	disc_info.ssi_len = ssi_len;
+
+	if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &succ) ||
+		!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
+		!wpa_dbus_dict_append_byte_array(&dict_iter, "discov_info",
+						 (const char *) &disc_info,
+						 sizeof(disc_info)) ||
+		!wpa_dbus_dict_append_byte_array(&dict_iter, "ssi",
+						 (const char *) ssi,
+						 ssi_len) ||
+		!wpa_dbus_dict_close_write(&iter, &dict_iter))
+		wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+	else
+		dbus_connection_send(iface->con, msg, NULL);
+	dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_nan_receive - Send receive NAN USD packet signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @id: Subscribe id
+ * @peer_id: Id of the sender
+ * @peer_addr: address of the sender
+ * @ssi: Service specific information payload
+ * @ssi_len: Length of the SSID
+ *
+ * Notify while getting the follow-up packet
+ */
+void wpas_dbus_signal_nan_receive(struct wpa_supplicant *wpa_s,
+				  int id, int peer_id, const u8 *peer_addr,
+				  const u8 *ssi, size_t ssi_len)
+{
+	struct wpas_dbus_priv *iface;
+	DBusMessage *msg;
+	DBusMessageIter iter, dict_iter;
+	struct wpa_dbus_nanrx_info nanrx_info;
+
+	iface = wpa_s->global->dbus;
+
+	/* Do nothing if the interface is not turned on */
+	if (!iface || !wpa_s->dbus_new_path)
+		return;
+
+	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+				      WPAS_DBUS_NEW_IFACE_INTERFACE,
+				      "NanReceive");
+	if (!msg)
+		return;
+
+	dbus_message_iter_init_append(msg, &iter);
+	nanrx_info.id = id;
+	nanrx_info.peer_id = peer_id;
+	memcpy(nanrx_info.peer_addr, peer_addr, ETH_ALEN);
+	nanrx_info.ssi_len = ssi_len;
+
+	if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
+		!wpa_dbus_dict_append_byte_array(&dict_iter, "nanrx_info",
+					     (const char *) &nanrx_info,
+					     sizeof(nanrx_info)) ||
+		!wpa_dbus_dict_append_byte_array(&dict_iter, "ssi",
+					     (const char *) ssi,
+					     ssi_len) ||
+		!wpa_dbus_dict_close_write(&iter, &dict_iter))
+		wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+	else
+		dbus_connection_send(iface->con, msg, NULL);
+	dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_nan_publish_terminated - Send publish-terminated signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @publish_id: The publish_id of the session
+ * @reason: The reason of the termination
+ *
+ * Notify while the session is expired
+ */
+void wpas_dbus_signal_nan_publish_terminated(struct wpa_supplicant *wpa_s,
+					     int publish_id, int reason)
+{
+	struct wpas_dbus_priv *iface;
+	DBusMessage *msg;
+	dbus_int32_t dpub_id = publish_id;
+	dbus_int32_t dreason = reason;
+
+	iface = wpa_s->global->dbus;
+
+	/* Do nothing if the interface is not turned on */
+	if (!iface || !wpa_s->dbus_new_path)
+		return;
+
+	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+				      WPAS_DBUS_NEW_IFACE_INTERFACE,
+				      "NanPublishterminated");
+	if (!msg)
+		return;
+
+	if (!dbus_message_append_args(msg, DBUS_TYPE_INT32, &dpub_id,
+				     DBUS_TYPE_INVALID) ||
+		!dbus_message_append_args(msg, DBUS_TYPE_INT32, &dreason,
+				     DBUS_TYPE_INVALID))
+		wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+	else {
+		dbus_connection_send(iface->con, msg, NULL);
+		wpa_msg(wpa_s, MSG_INFO, NAN_SUBSCRIBE_TERMINATED
+			"wpas_dbus_signal_nan_subscribe_terminated() dbus_connection_send (int)");
+	}
+	dbus_message_unref(msg);
+}
+
+
+/**
+ * wpas_dbus_signal_nan_subscribe_terminated - Send subscribe-terminated signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @subscribe_id: The subscribe_id of the session
+ * @reason: The reason of the termination
+ *
+ * Notify while the session is expired.
+ */
+void wpas_dbus_signal_nan_subscribe_terminated(struct wpa_supplicant *wpa_s,
+					       int subscribe_id, int reason)
+{
+	struct wpas_dbus_priv *iface;
+	DBusMessage *msg;
+	dbus_int32_t dsub_id = subscribe_id;
+	dbus_int32_t dreason = reason;
+
+	iface = wpa_s->global->dbus;
+
+	/* Do nothing if the interface is not turned on */
+	if (!iface || !wpa_s->dbus_new_path)
+		return;
+
+	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+				      WPAS_DBUS_NEW_IFACE_INTERFACE,
+				      "NanSubscribeterminated");
+	if (!msg)
+		return;
+
+	if (!dbus_message_append_args(msg, DBUS_TYPE_INT32, &dsub_id,
+				     DBUS_TYPE_INVALID) ||
+		!dbus_message_append_args(msg, DBUS_TYPE_INT32, &dreason,
+				     DBUS_TYPE_INVALID))
+		wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+	else {
+		dbus_connection_send(iface->con, msg, NULL);
+		wpa_msg(wpa_s, MSG_INFO, NAN_SUBSCRIBE_TERMINATED
+			"wpas_dbus_signal_nan_subscribe_terminated() dbus_connection_send (int)");
+	}
+
+	dbus_message_unref(msg);
+}
+
+#endif /* CONFIG_NAN_USD */
diff --git a/wpa_supplicant/dbus/dbus_new.h b/wpa_supplicant/dbus/dbus_new.h
index 952bb422a6d6..9765c3690d1d 100644
--- a/wpa_supplicant/dbus/dbus_new.h
+++ b/wpa_supplicant/dbus/dbus_new.h
@@ -21,6 +21,7 @@ struct wpa_bss;
 struct wps_event_m2d;
 struct wps_event_fail;
 struct wps_credential;
+struct wpa_dbus_discov_info;
 
 enum wpas_dbus_prop {
 	WPAS_DBUS_PROP_AP_SCAN,
@@ -284,6 +285,18 @@ void wpas_dbus_signal_anqp_query_done(struct wpa_supplicant *wpa_s,
 				      const u8 *dst, const char *result);
 void wpas_dbus_signal_hs20_t_c_acceptance(struct wpa_supplicant *wpa_s,
 					  const char *url);
+void wpas_dbus_signal_nan_discovery_result(struct wpa_supplicant *wpa_s,
+					   int subscribe_id,
+					   int peer_publish_id,
+					   const u8 *peer_addr,
+					   const u8 *ssi, size_t ssi_len);
+void wpas_dbus_signal_nan_receive(struct wpa_supplicant *wpa_s,
+				  int id, int peer_id, const u8 *peer_addr,
+				  const u8 *ssi, size_t ssi_len);
+void wpas_dbus_signal_nan_publish_terminated(struct wpa_supplicant *wpa_s,
+					     int publish_id, int reason);
+void wpas_dbus_signal_nan_subscribe_terminated(struct wpa_supplicant *wpa_s,
+					       int subscribe_id, int reason);
 
 #else /* CONFIG_CTRL_IFACE_DBUS_NEW */
 
@@ -667,6 +680,33 @@ void wpas_dbus_signal_hs20_t_c_acceptance(struct wpa_supplicant *wpa_s,
 {
 }
 
+static inline void
+wpas_dbus_signal_nan_discovery_result(struct wpa_supplicant *wpa_s,
+				      int subscribe_id,
+				      int peer_publish_id, const u8 *peer_addr,
+				      const u8 *ssi, size_t ssi_len)
+{
+}
+
+static inline void
+wpas_dbus_signal_nan_receive(struct wpa_supplicant *wpa_s,
+			     int id, int peer_id, const u8 *peer_addr,
+			     const u8 *ssi, size_t ssi_len)
+{
+}
+
+static inline void
+wpas_dbus_signal_nan_publish_terminated(struct wpa_supplicant *wpa_s,
+					int publish_id, int reason)
+{
+}
+
+static inline void
+wpas_dbus_signal_nan_subscribe_terminated(struct wpa_supplicant *wpa_s,
+					  int subscribe_id, int reason)
+{
+}
+
 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
 
 #endif /* CTRL_IFACE_DBUS_H_NEW */
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
index 960b3069b49d..713bb22d2603 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -12,6 +12,7 @@
 
 #include "common.h"
 #include "common/ieee802_11_defs.h"
+#include "common/nan_de.h"
 #include "eap_peer/eap_methods.h"
 #include "eapol_supp/eapol_supp_sm.h"
 #include "rsn_supp/wpa.h"
@@ -27,6 +28,7 @@
 #include "../autoscan.h"
 #include "../ap.h"
 #include "../interworking.h"
+#include "../nan_usd.h"
 #include "dbus_new_helpers.h"
 #include "dbus_new.h"
 #include "dbus_new_handlers.h"
@@ -2814,6 +2816,423 @@ DBusMessage * wpas_dbus_handler_eap_logon(DBusMessage *message,
 }
 
 
+#ifdef CONFIG_NAN_USD
+
+/*
+ * wpas_dbus_handler_nan_publish - Send out NAN publish packets
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL indicating success or DBus error message on failure
+ *
+ * Handler function for "NANPublish" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_nan_publish(DBusMessage *message,
+					    struct wpa_supplicant *wpa_s)
+{
+	const char *cmd;
+	struct wpabuf *cmdbuf = NULL;
+	char *token, *context = NULL;
+	int publish_id;
+	struct nan_publish_params params;
+	const char *service_name = NULL;
+	struct wpabuf *ssi = NULL;
+	enum nan_service_protocol_type srv_proto_type = 3;
+	int *freq_list = NULL;
+
+	wpa_printf(MSG_INFO, "DBUS NAN_PUBLISH:");
+	if (!dbus_message_get_args(message, NULL,
+				  DBUS_TYPE_STRING, &cmd,
+				  DBUS_TYPE_INVALID)) {
+		wpa_printf(MSG_DEBUG, " DBUS NAN_PUBLISH, failed to get args ");
+		return NULL;
+	}
+	wpa_printf(MSG_DEBUG, "DBUS NAN_PUBLISH: args: [%s]", cmd);
+
+	os_memset(&params, 0, sizeof(params));
+	/* USD shall use both solicited and unsolicited transmissions */
+	params.unsolicited = true;
+	params.solicited = true;
+	/* USD shall require FSD without GAS */
+	params.fsd = true;
+	params.freq = NAN_USD_DEFAULT_FREQ;
+	cmdbuf = wpabuf_alloc(strlen(cmd)+1);
+	if (cmdbuf == NULL) {
+		goto fail;
+	}
+	strcpy((char*)cmdbuf->buf, cmd);
+	while ((token = str_token((char*)cmdbuf->buf, " ", &context))) {
+		if (os_strncmp(token, "service_name=", 13) == 0) {
+			service_name = token + 13;
+			wpa_printf(MSG_DEBUG, "DBUS NAN_PUBLISH, service_name=[%s]", service_name);
+			continue;
+		}
+
+		if (os_strncmp(token, "ttl=", 4) == 0) {
+			params.ttl = atoi(token + 4);
+			wpa_printf(MSG_DEBUG, "DBUS NAN_PUBLISH, ttl=[%d]", params.ttl);
+			continue;
+		}
+
+		if (os_strncmp(token, "freq=", 5) == 0) {
+			params.freq = atoi(token + 5);
+			wpa_printf(MSG_DEBUG, "DBUS NAN_PUBLISH, freq=[%d]", params.freq);
+			continue;
+		}
+
+		if (os_strncmp(token, "freq_list=", 10) == 0) {
+			char *pos = token + 10;
+			if (os_strcmp(pos, "all") == 0) {
+				os_free(freq_list);
+				freq_list = wpas_nan_usd_all_freqs(wpa_s);
+				params.freq_list = freq_list;
+				continue;
+			}
+
+			while (pos && pos[0]) {
+				int_array_add_unique(&freq_list, atoi(pos));
+				pos = os_strchr(pos, ',');
+				if (pos)
+					pos++;
+			}
+
+			params.freq_list = freq_list;
+			continue;
+		}
+
+		if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
+			srv_proto_type = atoi(token + 15);
+			wpa_printf(MSG_DEBUG, " DBUS NAN_PUBLISH, srv_proto_type=[%d]", srv_proto_type);
+			continue;
+		}
+
+		if (os_strncmp(token, "ssi=", 4) == 0) {
+			if (ssi)
+				goto fail;
+			ssi = wpabuf_parse_bin(token + 4);
+			if (!ssi)
+				goto fail;
+			continue;
+		}
+
+		if (os_strcmp(token, "solicited=0") == 0) {
+			params.solicited = false;
+			continue;
+		}
+
+		if (os_strcmp(token, "unsolicited=0") == 0) {
+			params.unsolicited = false;
+			continue;
+		}
+
+		if (os_strcmp(token, "fsd=0") == 0) {
+			params.fsd = false;
+			continue;
+		}
+
+		wpa_printf(MSG_DEBUG, "CTRL: Invalid NAN_PUBLISH parameter: %s",
+			token);
+		goto fail;
+	}
+	wpabuf_free(cmdbuf);
+	cmdbuf = NULL;
+	publish_id = wpas_nan_usd_publish(wpa_s, service_name, srv_proto_type,
+					  ssi, &params);
+	if (publish_id > 0) {
+		DBusMessage *reply;
+		reply = dbus_message_new_method_return(message);
+		dbus_message_append_args(reply, DBUS_TYPE_INT32,
+					 &publish_id, DBUS_TYPE_INVALID);
+		return reply;
+	}
+fail:
+	wpabuf_free(cmdbuf);
+	wpabuf_free(ssi);
+	os_free(freq_list);
+	return NULL;
+}
+
+/*
+ * wpas_dbus_handler_nan_cancel_publish - Cancel the publish
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL indicating success or DBus error message on failure
+ *
+ * Handler function for "NANCancelPublish" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_nan_cancel_publish(DBusMessage *message,
+						   struct wpa_supplicant *wpa_s)
+{
+	const char *cmd;
+	struct wpabuf *cmdbuf = NULL;
+	char *token, *context = NULL;
+	int publish_id = -1;
+
+	wpa_printf(MSG_INFO, "DBUS NAN_CANCEL_PUBLISH:");
+	if (!dbus_message_get_args(message, NULL,
+				   DBUS_TYPE_STRING, &cmd,
+				   DBUS_TYPE_INVALID)) {
+		wpa_printf(MSG_DEBUG, " DBUS NAN_CANCEL_PUBLISH, failed to get args ");
+		return NULL;
+	}
+	wpa_printf(MSG_DEBUG, "DBUS NAN_CANCEL_PUBLISH: args: [%s]", cmd);
+	cmdbuf = wpabuf_alloc(strlen(cmd)+1);
+	if (cmdbuf == NULL) {
+		goto fail;
+	}
+	strcpy((char*)cmdbuf->buf, cmd);
+	while ((token = str_token((char*)cmdbuf->buf, " ", &context))) {
+		if (os_strncmp(token, "publish_id=", 11) == 0) {
+			publish_id = atoi(token + 11);
+			wpa_printf(MSG_DEBUG, "DBUS NAN_CANCEL_PUBLISH, publish_id=[%d]", publish_id);
+			break;
+		}
+		wpa_printf(MSG_DEBUG, "CTRL: Invalid NAN_CANCEL_PUBLISH parameter: %s",
+			token);
+		goto fail;
+	}
+	wpabuf_free(cmdbuf);
+	cmdbuf = NULL;
+	if ((!wpa_s->nan_de) || (publish_id == -1))
+		return NULL;
+	nan_de_cancel_publish(wpa_s->nan_de, publish_id);
+fail:
+	wpabuf_free(cmdbuf);
+	return NULL;
+}
+
+
+/*
+ * wpas_dbus_handler_nan_subscribe - Send out nan-subscribe packets
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL indicating success or DBus error message on failure
+ *
+ * Handler function for "NANSubscribe" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_nan_subscribe(DBusMessage *message,
+					      struct wpa_supplicant *wpa_s)
+{
+	const char *cmd;
+	struct wpabuf *cmdbuf = NULL;
+	char *token, *context = NULL;
+	int subscribe_id;
+	struct nan_subscribe_params params;
+	const char *service_name = NULL;
+	struct wpabuf *ssi = NULL;
+	enum nan_service_protocol_type srv_proto_type = 3;
+
+	wpa_printf(MSG_INFO, "DBUS NAN_SUBSCRIBE: ");
+	if (!dbus_message_get_args(message, NULL,
+				   DBUS_TYPE_STRING, &cmd,
+				   DBUS_TYPE_INVALID)) {
+		wpa_printf(MSG_DEBUG, "DBUS NAN_SUBSCRIBE, failed to get args ");
+		return NULL;
+	}
+	wpa_printf(MSG_DEBUG, "DBUS NAN_SUBSCRIBE, args: [%s]", cmd);
+	os_memset(&params, 0, sizeof(params));
+	params.freq = NAN_USD_DEFAULT_FREQ;
+	cmdbuf = wpabuf_alloc(strlen(cmd)+1);
+	if (cmdbuf == NULL) {
+		goto fail;
+	}
+	strcpy((char*)cmdbuf->buf, cmd);
+	while ((token = str_token((char*)cmdbuf->buf, " ", &context))) {
+		if (os_strncmp(token, "service_name=", 13) == 0) {
+			service_name = token + 13;
+			continue;
+		}
+
+		if (os_strcmp(token, "active=1") == 0) {
+			params.active = true;
+			continue;
+		}
+
+		if (os_strncmp(token, "ttl=", 4) == 0) {
+			params.ttl = atoi(token + 4);
+			continue;
+		}
+
+		if (os_strncmp(token, "freq=", 5) == 0) {
+			params.freq = atoi(token + 5);
+			continue;
+		}
+
+		if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
+			srv_proto_type = atoi(token + 15);
+			continue;
+		}
+
+		if (os_strncmp(token, "ssi=", 4) == 0) {
+			if (ssi)
+				goto fail;
+			ssi = wpabuf_parse_bin(token + 4);
+			if (!ssi)
+				goto fail;
+			continue;
+		}
+		wpa_printf(MSG_INFO,
+			   "DBUS: Invalid NAN_SUBSCRIBE parameter: %s",
+			   token);
+		goto fail;
+	}
+	wpabuf_free(cmdbuf);
+	cmdbuf = NULL;
+	subscribe_id = wpas_nan_usd_subscribe(wpa_s, service_name,
+					      srv_proto_type, ssi,
+					      &params);
+	if (subscribe_id > 0) {
+		DBusMessage *reply;
+		reply = dbus_message_new_method_return(message);
+		dbus_message_append_args(reply, DBUS_TYPE_INT32,
+					 &subscribe_id, DBUS_TYPE_INVALID);
+		return reply;
+	}
+fail:
+	wpabuf_free(cmdbuf);
+	wpabuf_free(ssi);
+	return NULL;
+}
+
+
+/*
+ * wpas_dbus_handler_nan_cancel_publish - Cancel the subscription
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL indicating success or DBus error message on failure
+ *
+ * Handler function for "NANCancelSubscribe" method call of network interface.
+ */
+DBusMessage *
+wpas_dbus_handler_nan_cancel_subscribe(DBusMessage *message,
+				       struct wpa_supplicant *wpa_s)
+{
+	const char *cmd;
+	struct wpabuf *cmdbuf = NULL;
+	char *token, *context = NULL;
+	int subscribe_id = -1;
+
+	wpa_printf(MSG_INFO, "DBUS NAN_CANCEL_SUBSCRIBE:");
+	if (!dbus_message_get_args(message, NULL,
+				   DBUS_TYPE_STRING, &cmd,
+				   DBUS_TYPE_INVALID)) {
+		wpa_printf(MSG_DEBUG, " DBUS NAN_CANCEL_SUBSCRIBE, failed to get args ");
+		return NULL;
+	}
+	wpa_printf(MSG_DEBUG, "DBUS NAN_CANCEL_SUBSCRIBE: args: [%s]", cmd);
+	cmdbuf = wpabuf_alloc(strlen(cmd)+1);
+	if (cmdbuf == NULL) {
+		goto fail;
+	}
+	strcpy((char*)cmdbuf->buf, cmd);
+	while ((token = str_token((char*)cmdbuf->buf, " ", &context))) {
+		if (os_strncmp(token, "subscribe_id=", 13) == 0) {
+			subscribe_id = atoi(token + 13);
+			wpa_printf(MSG_DEBUG, "DBUS NAN_CANCEL_SUBSCRIBE, publish_id=[%d]", subscribe_id);
+			break;
+		}
+		wpa_printf(MSG_DEBUG, "DBUS: Invalid NAN_CANCEL_SUBSCRIBE parameter: %s",
+			token);
+		goto fail;
+	}
+	wpabuf_free(cmdbuf);
+	cmdbuf = NULL;
+	if ((!wpa_s->nan_de)||(subscribe_id == -1))
+		return NULL;
+	nan_de_cancel_subscribe(wpa_s->nan_de, subscribe_id);
+fail:
+	wpabuf_free(cmdbuf);
+	return NULL;
+}
+
+
+/*
+ * wpas_dbus_handler_nan_transmit - Send out nan-followup packets
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: NULL indicating success or DBus error message on failure
+ *
+ * Handler function for "NANTransmit" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_nan_transmit(DBusMessage *message,
+					     struct wpa_supplicant *wpa_s)
+{
+	const char *cmd;
+	struct wpabuf *cmdbuf = NULL;
+	char *token, *context = NULL;
+	int handle = 0;
+	int req_instance_id = 0;
+	struct wpabuf *ssi = NULL;
+	u8 peer_addr[ETH_ALEN];
+	int ret = -1;
+
+	wpa_printf(MSG_INFO, "DBUS NAN_TRANSMIT:");
+	if (!dbus_message_get_args(message, NULL,
+				   DBUS_TYPE_STRING, &cmd,
+				   DBUS_TYPE_INVALID)) {
+		wpa_printf(MSG_DEBUG, "DBUS NAN_TRANSMIT, failed to get args ");
+		return NULL;
+	}
+	wpa_printf(MSG_DEBUG, "DBUS NAN_TRANSMIT, args: [%s]", cmd);
+	os_memset(peer_addr, 0, ETH_ALEN);
+	cmdbuf = wpabuf_alloc(strlen(cmd)+1);
+	if (cmdbuf == NULL) {
+		goto fail;
+	}
+	strcpy((char*)cmdbuf->buf, cmd);
+	while ((token = str_token((char*)cmdbuf->buf, " ", &context))) {
+		if (sscanf(token, "handle=%i", &handle) == 1)
+			continue;
+
+		if (sscanf(token, "req_instance_id=%i", &req_instance_id) == 1)
+			continue;
+
+		if (os_strncmp(token, "address=", 8) == 0) {
+			if (hwaddr_aton(token + 8, peer_addr) < 0)
+				return NULL;
+			continue;
+		}
+
+		if (os_strncmp(token, "ssi=", 4) == 0) {
+			if (ssi)
+				goto fail;
+			ssi = wpabuf_parse_bin(token + 4);
+			if (!ssi)
+				goto fail;
+			continue;
+		}
+
+		wpa_printf(MSG_INFO,
+			"CTRL: Invalid NAN_TRANSMIT parameter: %s",
+			token);
+		goto fail;
+	}
+	wpabuf_free(cmdbuf);
+	cmdbuf = NULL;
+
+	if (handle <= 0) {
+		wpa_printf(MSG_INFO,
+			"CTRL: Invalid or missing NAN_TRANSMIT handle");
+		goto fail;
+	}
+
+	if (is_zero_ether_addr(peer_addr)) {
+		wpa_printf(MSG_INFO,
+			"CTRL: Invalid or missing NAN_TRANSMIT address");
+		goto fail;
+	}
+
+	ret = wpas_nan_usd_transmit(wpa_s, handle, ssi, NULL, peer_addr,
+				    req_instance_id);
+fail:
+	wpa_printf(MSG_INFO, "DBUS NAN_TRANSMIT Done, %d", ret);
+	wpabuf_free(cmdbuf);
+	wpabuf_free(ssi);
+	return NULL;
+}
+
+#endif /* CONFIG_NAN_USD */
+
+
 #ifdef CONFIG_TDLS
 
 static int get_peer_hwaddr_helper(DBusMessage *message, const char *func_name,
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h
index acd6af7ffa38..875f98d188cc 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.h
+++ b/wpa_supplicant/dbus/dbus_new_handlers.h
@@ -289,4 +289,16 @@ DBusMessage * wpas_dbus_handler_subscribe_preq(
 DBusMessage * wpas_dbus_handler_unsubscribe_preq(
 	DBusMessage *message, struct wpa_supplicant *wpa_s);
 
+DBusMessage * wpas_dbus_handler_nan_publish(DBusMessage *message,
+					    struct wpa_supplicant *wpa_s);
+DBusMessage * wpas_dbus_handler_nan_cancel_publish(
+	DBusMessage *message, struct wpa_supplicant *wpa_s);
+DBusMessage * wpas_dbus_handler_nan_subscribe(DBusMessage *message,
+					      struct wpa_supplicant *wpa_s);
+DBusMessage *
+wpas_dbus_handler_nan_cancel_subscribe(DBusMessage *message,
+				       struct wpa_supplicant *wpa_s);
+DBusMessage * wpas_dbus_handler_nan_transmit(DBusMessage *message,
+					     struct wpa_supplicant *wpa_s);
+
 #endif /* CTRL_IFACE_DBUS_HANDLERS_NEW_H */
diff --git a/wpa_supplicant/dbus/dbus_new_helpers.h b/wpa_supplicant/dbus/dbus_new_helpers.h
index c8d44a00bee8..ca2a1ae1b6da 100644
--- a/wpa_supplicant/dbus/dbus_new_helpers.h
+++ b/wpa_supplicant/dbus/dbus_new_helpers.h
@@ -112,6 +112,20 @@ struct wpa_dbus_property_desc {
 #define WPA_DBUS_PROPERTIES_SET "Set"
 #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
 
+struct wpa_dbus_discov_info {
+	u32 subscribe_id;
+	u32 peer_publish_id;
+	u8 peer_addr[ETH_ALEN];
+	u32 ssi_len;
+};
+
+struct wpa_dbus_nanrx_info {
+	u32 id;
+	u32 peer_id;
+	u8 peer_addr[ETH_ALEN];
+	u32 ssi_len;
+};
+
 void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
 
 int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index e44382341f00..c93d82924c7c 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -1084,6 +1084,10 @@ void wpas_notify_nan_discovery_result(struct wpa_supplicant *wpa_s,
 		subscribe_id, peer_publish_id, MAC2STR(peer_addr),
 		fsd, fsd_gas, srv_proto_type, ssi_hex);
 	os_free(ssi_hex);
+
+	wpas_dbus_signal_nan_discovery_result(wpa_s, subscribe_id,
+					      peer_publish_id, peer_addr,
+					      ssi, ssi_len);
 }
 
 
@@ -1124,6 +1128,9 @@ void wpas_notify_nan_receive(struct wpa_supplicant *wpa_s, int id,
 		"id=%d peer_instance_id=%d address=" MACSTR " ssi=%s",
 		id, peer_instance_id, MAC2STR(peer_addr), ssi_hex);
 	os_free(ssi_hex);
+
+	wpas_dbus_signal_nan_receive(wpa_s, id, peer_instance_id, peer_addr,
+				     ssi, ssi_len);
 }
 
 
@@ -1149,6 +1156,8 @@ void wpas_notify_nan_publish_terminated(struct wpa_supplicant *wpa_s,
 	wpa_msg(wpa_s, MSG_INFO, NAN_PUBLISH_TERMINATED
 		"publish_id=%d reason=%s",
 		publish_id, nan_reason_txt(reason));
+
+	wpas_dbus_signal_nan_publish_terminated(wpa_s, publish_id, reason);
 }
 
 
@@ -1159,6 +1168,8 @@ void wpas_notify_nan_subscribe_terminated(struct wpa_supplicant *wpa_s,
 	wpa_msg(wpa_s, MSG_INFO, NAN_SUBSCRIBE_TERMINATED
 		"subscribe_id=%d reason=%s",
 		subscribe_id, nan_reason_txt(reason));
+
+	wpas_dbus_signal_nan_subscribe_terminated(wpa_s, subscribe_id, reason);
 }
 
 #endif /* CONFIG_NAN_USD */
-- 
2.34.1


--t3wOoFPUoRX12ndg
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap

--t3wOoFPUoRX12ndg--





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux