Re: [PATCH] Dbus: sending device information in DeviceFound event.

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

 



On Thu, 2016-06-16 at 20:06 +0530, Nishant Chaprana wrote:
> This sends basic device information in DeviceFound event as a{sv}.
> It is similar to device information provided in P2P-DEVICE-FOUND
> event.
> This will enable any applicaiton to extract peer information from
> event,
> and it would not require calling GetAll for peer properties which
> would be creating extra load over supplicant as well on applicaiton.

This changes the D-Bus signature of the DeviceFound signal, which is an
API break.  We can't really do that, we'd need an additional signal to
convey properties that clients could listen to instead.

It also doesn't update the introspection information (struct
wpas_dbus_interface_properties), which would have indicated that this
is an API break.

Dan

> Signed-off-by: Nishant Chaprana <n.chaprana@xxxxxxxxxxx>
> ---
>  wpa_supplicant/dbus/dbus_dict_helpers.c |  18 +++++
>  wpa_supplicant/dbus/dbus_dict_helpers.h |   3 +
>  wpa_supplicant/dbus/dbus_new.c          | 123
> ++++++++++++++++++++++----------
>  wpa_supplicant/dbus/dbus_new.h          |   2 +-
>  wpa_supplicant/notify.c                 |   6 +-
>  wpa_supplicant/notify.h                 |   3 +-
>  wpa_supplicant/p2p_supplicant.c         |   2 +-
>  7 files changed, 114 insertions(+), 43 deletions(-)
> 
> diff --git a/wpa_supplicant/dbus/dbus_dict_helpers.c
> b/wpa_supplicant/dbus/dbus_dict_helpers.c
> index e4e9b8d..75da950 100644
> --- a/wpa_supplicant/dbus/dbus_dict_helpers.c
> +++ b/wpa_supplicant/dbus/dbus_dict_helpers.c
> @@ -205,6 +205,24 @@ dbus_bool_t
> wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
>  
>  
>  /**
> + * Add a byte entry to the dict.
> + *
> + * @param iter_dict A valid DBusMessageIter returned from
> + *    wpa_dbus_dict_open_write()
> + * @param key The key of the dict item
> + * @param value The byte(u8) value
> + * @return TRUE on success, FALSE on failure
> + *
> + */
> +dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict,
> +				      const char *key, u8 value)
> +{
> +	return _wpa_dbus_add_dict_entry_basic(iter_dict, key,
> +					      DBUS_TYPE_BYTE,
> &value);
> +}
> +
> +
> +/**
>   * Add a boolean entry to the dict.
>   *
>   * @param iter_dict A valid DBusMessageIter returned from
> diff --git a/wpa_supplicant/dbus/dbus_dict_helpers.h
> b/wpa_supplicant/dbus/dbus_dict_helpers.h
> index 94a0efd..e441c2c 100644
> --- a/wpa_supplicant/dbus/dbus_dict_helpers.h
> +++ b/wpa_supplicant/dbus/dbus_dict_helpers.h
> @@ -26,6 +26,9 @@ const char * wpa_dbus_type_as_string(const int
> type);
>  dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
>  					const char *key, const char
> *value);
>  
> +dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict,
> +					const char *key, u8 value);
> +
>  dbus_bool_t wpa_dbus_dict_append_bool(DBusMessageIter *iter_dict,
>  				      const char *key,
>  				      const dbus_bool_t value);
> diff --git a/wpa_supplicant/dbus/dbus_new.c
> b/wpa_supplicant/dbus/dbus_new.c
> index 0263b2c..308adf2 100644
> --- a/wpa_supplicant/dbus/dbus_new.c
> +++ b/wpa_supplicant/dbus/dbus_new.c
> @@ -3793,24 +3793,20 @@ static const struct wpa_dbus_signal_desc
> wpas_dbus_p2p_peer_signals[] = {
>  };
>  
>  /**
> - * wpas_dbus_signal_peer - Send a peer related event signal
> + * wpas_dbus_signal_peer_found - Send a peer found signal
>   * @wpa_s: %wpa_supplicant network interface data
>   * @dev: peer device object
> - * @interface: name of the interface emitting this signal.
> - *	In case of peer objects, it would be emitted by either
> - *	the "interface object" or by "peer objects"
> - * @sig_name: signal name - DeviceFound
>   *
> - * Notify listeners about event related with newly found p2p peer
> device
> + * Notify listeners about find a p2p peer device found
>   */
> -static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
> -				  const u8 *dev_addr, const char
> *interface,
> -				  const char *sig_name)
> +void wpas_dbus_signal_peer_device_found(struct wpa_supplicant
> *wpa_s,
> +					const struct p2p_peer_info
> *info)
>  {
>  	struct wpas_dbus_priv *iface;
>  	DBusMessage *msg;
> -	DBusMessageIter iter;
> +	DBusMessageIter iter, dict_iter;
>  	char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
> +	int error_ret = 1;
>  
>  	if (wpa_s->p2p_mgmt)
>  		wpa_s = wpa_s->parent;
> @@ -3823,53 +3819,106 @@ static void wpas_dbus_signal_peer(struct
> wpa_supplicant *wpa_s,
>  
>  	os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
>  		    "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
> COMPACT_MACSTR,
> -		    wpa_s->dbus_new_path, MAC2STR(dev_addr));
> +		    wpa_s->dbus_new_path, MAC2STR(info-
> >p2p_device_addr));
>  
> -	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
> interface,
> -				      sig_name);
> +	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
> +				      WPAS_DBUS_NEW_IFACE_P2PDEVICE,
> +				      "DeviceFound");
>  	if (msg == NULL)
>  		return;
>  
>  	dbus_message_iter_init_append(msg, &iter);
>  	path = peer_obj_path;
> -	if (!dbus_message_iter_append_basic(&iter,
> DBUS_TYPE_OBJECT_PATH,
> -					    &path))
> -		wpa_printf(MSG_ERROR, "dbus: Failed to construct
> signal");
> -	else
> -		dbus_connection_send(iface->con, msg, NULL);
> +	if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
> +			!wpa_dbus_dict_append_object_path(&dict_iter
> ,
> +				"peer_object",
> +				path) ||
> +			!wpa_dbus_dict_append_string(&dict_iter,
> +				"device_name",
> +				info->device_name) ||
> +			!wpa_dbus_dict_append_uint16(&dict_iter,
> +				"config_method",
> +				info->config_methods) ||
> +			!wpa_dbus_dict_append_byte(&dict_iter,
> +				"device_capability",
> +				info->dev_capab) ||
> +			!wpa_dbus_dict_append_byte(&dict_iter,
> +				"group_capability",
> +				info->group_capab) ||
> +			!wpa_dbus_dict_append_byte_array(&dict_iter,
> +				"primary_dev_type",
> +				(const char *) info->pri_dev_type,
> +				WPS_DEV_TYPE_LEN)) {
> +		goto error;
> +	}
>  
> -	dbus_message_unref(msg);
> -}
> +	if (info->wfd_subelems && info->wfd_subelems->buf) {
> +		if (!wpa_dbus_dict_append_byte_array(&dict_iter,
> +				"WFDIEs", (const char *) info-
> >wfd_subelems->buf,
> +				info->wfd_subelems->size)) {
> +			goto error;
> +		}
> +	}
>  
> +	if (info->vendor_elems) {
> +		if (!wpa_dbus_dict_append_bool(&dict_iter,
> "vendor_elems", 1))
> +			goto error;
> +	}
>  
> -/**
> - * wpas_dbus_signal_peer_found - Send a peer found signal
> - * @wpa_s: %wpa_supplicant network interface data
> - * @dev_addr: Peer P2P Device Address
> - *
> - * Notify listeners about find a p2p peer device found
> - */
> -void wpas_dbus_signal_peer_device_found(struct wpa_supplicant
> *wpa_s,
> -					const u8 *dev_addr)
> -{
> -	wpas_dbus_signal_peer(wpa_s, dev_addr,
> -			      WPAS_DBUS_NEW_IFACE_P2PDEVICE,
> -			      "DeviceFound");
> +	error_ret = !(wpa_dbus_dict_close_write(&iter, &dict_iter));
> +
> +error:
> +        if (!error_ret)
> +		dbus_connection_send(iface->con, msg, NULL);
> +	else
> +		wpa_printf(MSG_ERROR, "dbus: Failed to construct
> signal");
> +
> +	dbus_message_unref(msg);
>  }
>  
>  /**
>   * wpas_dbus_signal_peer_lost - Send a peer lost signal
>   * @wpa_s: %wpa_supplicant network interface data
> - * @dev_addr: Peer P2P Device Address
> + * @dev: peer device object
>   *
>   * Notify listeners about lost a p2p peer device
>   */
>  void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
>  				       const u8 *dev_addr)
>  {
> -	wpas_dbus_signal_peer(wpa_s, dev_addr,
> -			      WPAS_DBUS_NEW_IFACE_P2PDEVICE,
> -			      "DeviceLost");
> +	struct wpas_dbus_priv *iface;
> +	DBusMessage *msg;
> +	DBusMessageIter iter;
> +	char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
> +
> +	if (wpa_s->p2p_mgmt)
> +		wpa_s = wpa_s->parent;
> +
> +	iface = wpa_s->global->dbus;
> +
> +	/* Do nothing if the control interface is not turned on */
> +	if (iface == NULL || !wpa_s->dbus_new_path)
> +		return;
> +
> +	os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
> +		    "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
> COMPACT_MACSTR,
> +		    wpa_s->dbus_new_path, MAC2STR(dev_addr));
> +
> +	msg = dbus_message_new_signal(wpa_s->dbus_new_path,
> +				      WPAS_DBUS_NEW_IFACE_P2PDEVICE,
> +				      "DeviceLost");
> +	if (msg == NULL)
> +		return;
> +
> +	dbus_message_iter_init_append(msg, &iter);
> +	path = peer_obj_path;
> +	if (!dbus_message_iter_append_basic(&iter,
> DBUS_TYPE_OBJECT_PATH,
> +					    &path))
> +		wpa_printf(MSG_ERROR, "dbus: Failed to construct
> signal");
> +	else
> +		dbus_connection_send(iface->con, msg, NULL);
> +
> +	dbus_message_unref(msg);
>  }
>  
>  /**
> diff --git a/wpa_supplicant/dbus/dbus_new.h
> b/wpa_supplicant/dbus/dbus_new.h
> index d64fcee..23d2994 100644
> --- a/wpa_supplicant/dbus/dbus_new.h
> +++ b/wpa_supplicant/dbus/dbus_new.h
> @@ -172,7 +172,7 @@ void
> wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global);
>  int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8
> *dev_addr);
>  void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant
> *wpa_s);
>  void wpas_dbus_signal_peer_device_found(struct wpa_supplicant
> *wpa_s,
> -					   const u8 *dev_addr);
> +					const struct p2p_peer_info
> *info);
>  int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
>  				  const u8 *dev_addr);
>  void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
> diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
> index 67e36ae..da76e2b 100644
> --- a/wpa_supplicant/notify.c
> +++ b/wpa_supplicant/notify.c
> @@ -570,15 +570,15 @@ void wpas_notify_p2p_find_stopped(struct
> wpa_supplicant *wpa_s)
>  
>  
>  void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
> -				  const u8 *dev_addr, int
> new_device)
> +				  const struct p2p_peer_info *info,
> int new_device)
>  {
>  	if (new_device) {
>  		/* Create the new peer object */
> -		wpas_dbus_register_peer(wpa_s, dev_addr);
> +		wpas_dbus_register_peer(wpa_s, info-
> >p2p_device_addr);
>  	}
>  
>  	/* Notify a new peer has been detected*/
> -	wpas_dbus_signal_peer_device_found(wpa_s, dev_addr);
> +	wpas_dbus_signal_peer_device_found(wpa_s, info);
>  }
>  
>  
> diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h
> index 8cce0f3..f8ca7ff 100644
> --- a/wpa_supplicant/notify.h
> +++ b/wpa_supplicant/notify.h
> @@ -88,7 +88,8 @@ void wpas_notify_sta_authorized(struct
> wpa_supplicant *wpa_s,
>  				const u8 *p2p_dev_addr);
>  void wpas_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s);
>  void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
> -				  const u8 *dev_addr, int
> new_device);
> +				  const struct p2p_peer_info *info,
> +				  int new_device);
>  void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s,
>  				 const u8 *dev_addr);
>  void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s,
> diff --git a/wpa_supplicant/p2p_supplicant.c
> b/wpa_supplicant/p2p_supplicant.c
> index 8c5af5e..c0bfbe3 100644
> --- a/wpa_supplicant/p2p_supplicant.c
> +++ b/wpa_supplicant/p2p_supplicant.c
> @@ -2360,7 +2360,7 @@ done:
>  	os_free(wfd_dev_info_hex);
>  #endif /* CONFIG_NO_STDOUT_DEBUG */
>  
> -	wpas_notify_p2p_device_found(ctx, info->p2p_device_addr,
> new_device);
> +	wpas_notify_p2p_device_found(ctx, info, new_device);
>  }
>  
>  

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




[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