linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@codecoup.pl>
To: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ 5/6] tools/btpclient: Add start, stop discovery commands
Date: Fri, 22 Dec 2017 11:48:26 +0100	[thread overview]
Message-ID: <1718429.lz8PR2LJZV@ix> (raw)
In-Reply-To: <20171221164720.20925-5-grzegorz.kolodziejczyk@codecoup.pl>

On Thursday, 21 December 2017 17:47:19 CET Grzegorz Kolodziejczyk wrote:
> This patch adds start and stop discovery command for btp client.
> ---
>  tools/btpclient.c | 220
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220
> insertions(+)
> 
> diff --git a/tools/btpclient.c b/tools/btpclient.c
> index c0ad03b68..f4b930a51 100644
> --- a/tools/btpclient.c
> +++ b/tools/btpclient.c
> @@ -122,6 +122,8 @@ static void btp_gap_read_commands(uint8_t index, const
> void *param, commands |= (1 << BTP_OP_GAP_SET_POWERED);
>  	commands |= (1 << BTP_OP_GAP_SET_DISCOVERABLE);
>  	commands |= (1 << BTP_OP_GAP_SET_BONDABLE);
> +	commands |= (1 << BTP_OP_GAP_START_DISCOVERY);
> +	commands |= (1 << BTP_OP_GAP_STOP_DISCOVERY);
> 
>  	commands = L_CPU_TO_LE16(commands);
> 
> @@ -399,6 +401,218 @@ failed:
>  	btp_send_error(btp, BTP_GAP_SERVICE, index, status);
>  }
> 
> +static void start_discovery_reply(struct l_dbus_proxy *proxy,
> +						struct l_dbus_message *result,
> +						void *user_data)
> +{
> +	struct btp_adapter *adapter = find_adapter_by_proxy(proxy);
> +
> +	if (!adapter) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, BTP_INDEX_NON_CONTROLLER,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	if (l_dbus_message_is_error(result)) {
> +		const char *name, *desc;
> +
> +		l_dbus_message_get_error(result, &name, &desc);
> +		l_error("Failed to start discovery (%s), %s", name, desc);
> +
> +		btp_send_error(btp, BTP_GAP_SERVICE, adapter->index,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_START_DISCOVERY,
> +						adapter->index, 0, NULL);
> +}
> +
> +static void set_start_discovery_filter_setup(struct l_dbus_message
> *message, +							void *user_data)
> +{
> +	uint8_t flags = L_PTR_TO_UINT(user_data);
> +	struct l_dbus_message_builder *builder;

Add basic sanity check here for flags ie at least one of LE or BR should be 
set.

> +
> +	builder = l_dbus_message_builder_new(message);
> +
> +	l_dbus_message_builder_enter_array(builder, "{sv}");
> +	l_dbus_message_builder_enter_dict(builder, "sv");
> +
> +	/* Be in observer mode or in general mode (default in Bluez) */
> +	if (flags & BTP_GAP_DISCOVERY_FLAG_OBSERVATION) {
> +		l_dbus_message_builder_append_basic(builder, 's', "Transport");
> +		l_dbus_message_builder_enter_variant(builder, "s");
> +
> +		if (flags & (BTP_GAP_DISCOVERY_FLAG_LE |
> +						BTP_GAP_DISCOVERY_FLAG_BREDR))
> +			l_dbus_message_builder_append_basic(builder, 's',
> +									"auto");
> +		else if (flags & BTP_GAP_DISCOVERY_FLAG_LE)
> +			l_dbus_message_builder_append_basic(builder, 's', "le");
> +		else if (flags & BTP_GAP_DISCOVERY_FLAG_BREDR)
> +			l_dbus_message_builder_append_basic(builder, 's',
> +								"bredr");
> +
> +		l_dbus_message_builder_leave_variant(builder);
> +	}
> +
> +	l_dbus_message_builder_leave_dict(builder);
> +	l_dbus_message_builder_leave_array(builder);
> +
> +	/* TODO add passive, limited discovery */
> +	l_dbus_message_builder_finalize(builder);
> +	l_dbus_message_builder_destroy(builder);
> +}
> +
> +static void set_start_discovery_filter_reply(struct l_dbus_proxy *proxy,
> +						struct l_dbus_message *result,
> +						void *user_data)
> +{
> +	struct btp_adapter *adapter = find_adapter_by_proxy(proxy);
> +
> +	if (!adapter) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, BTP_INDEX_NON_CONTROLLER,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	if (l_dbus_message_is_error(result)) {
> +		const char *name, *desc;
> +
> +		l_dbus_message_get_error(result, &name, &desc);
> +		l_error("Failed to set discovery filter (%s), %s", name, desc);
> +
> +		btp_send_error(btp, BTP_GAP_SERVICE, adapter->index,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	l_dbus_proxy_method_call(adapter->proxy, "StartDiscovery", NULL,
> +					start_discovery_reply, NULL, NULL);
> +}
> +
> +static void btp_gap_start_discovery(uint8_t index, const void *param,
> +					uint16_t length, void *user_data)
> +{
> +	struct btp_adapter *adapter = find_adapter_by_index(index);
> +	const struct btp_gap_start_discovery_cp *cp = param;
> +	bool prop;
> +
> +	if (!adapter) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, index,
> +						BTP_ERROR_INVALID_INDEX);
> +		return;
> +	}
> +
> +	/* Adapter needs to be powered to start discovery */
> +	if (!l_dbus_proxy_get_property(adapter->proxy, "Powered", "b", &prop) ||
> +									!prop) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, index, BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	l_dbus_proxy_method_call(adapter->proxy, "SetDiscoveryFilter",
> +					set_start_discovery_filter_setup,
> +					set_start_discovery_filter_reply,

nitpick: Name it set_discovery_filer_setup/reply.

> +					L_UINT_TO_PTR(cp->flags), NULL);
> +}
> +
> +static void set_stop_discovery_filter_setup(struct l_dbus_message *message,
> +							void *user_data)
> +{
> +	struct l_dbus_message_builder *builder;
> +
> +	builder = l_dbus_message_builder_new(message);
> +
> +	/* Clear discovery filter setup */
> +	l_dbus_message_builder_enter_array(builder, "{sv}");
> +	l_dbus_message_builder_enter_dict(builder, "sv");
> +	l_dbus_message_builder_leave_dict(builder);
> +	l_dbus_message_builder_leave_array(builder);
> +	l_dbus_message_builder_finalize(builder);
> +	l_dbus_message_builder_destroy(builder);
> +}
> +
> +static void set_stop_discovery_filter_reply(struct l_dbus_proxy *proxy,
> +						struct l_dbus_message *result,
> +						void *user_data)
> +{
> +	struct btp_adapter *adapter = find_adapter_by_proxy(proxy);
> +
> +	if (!adapter) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, BTP_INDEX_NON_CONTROLLER,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	if (l_dbus_message_is_error(result)) {
> +		const char *name, *desc;
> +
> +		l_dbus_message_get_error(result, &name, &desc);
> +		l_error("Failed to set discovery filter (%s), %s", name, desc);
> +
> +		btp_send_error(btp, BTP_GAP_SERVICE, adapter->index,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_STOP_DISCOVERY,
> +						adapter->index, 0, NULL);
> +}
> +
> +static void stop_discovery_reply(struct l_dbus_proxy *proxy,
> +						struct l_dbus_message *result,
> +						void *user_data)
> +{
> +	struct btp_adapter *adapter = find_adapter_by_proxy(proxy);
> +
> +	if (!adapter) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, BTP_INDEX_NON_CONTROLLER,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	if (l_dbus_message_is_error(result)) {
> +		const char *name;
> +
> +		l_dbus_message_get_error(result, &name, NULL);
> +		l_error("Failed to stop discovery (%s)", name);
> +
> +		btp_send_error(btp, BTP_GAP_SERVICE, adapter->index,
> +								BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	l_dbus_proxy_method_call(adapter->proxy, "SetDiscoveryFilter",
> +						set_stop_discovery_filter_setup,
> +						set_stop_discovery_filter_reply,

Name those clear_discovery_filter_setup/reply.

> +						NULL, NULL);
> +}
> +
> +static void btp_gap_stop_discovery(uint8_t index, const void *param,
> +					uint16_t length, void *user_data)
> +{
> +	struct btp_adapter *adapter = find_adapter_by_index(index);
> +	bool prop;
> +
> +	if (!adapter) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, index,
> +						BTP_ERROR_INVALID_INDEX);
> +		return;
> +	}
> +
> +	/* Adapter needs to be powered to be able to remove devices */
> +	if (!l_dbus_proxy_get_property(adapter->proxy, "Powered", "b", &prop) ||
> +									!prop) {
> +		btp_send_error(btp, BTP_GAP_SERVICE, index, BTP_ERROR_FAIL);
> +		return;
> +	}
> +
> +	l_dbus_proxy_method_call(adapter->proxy, "StopDiscovery", NULL,
> +					stop_discovery_reply, NULL, NULL);
> +}
> +
>  static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
>  {
>  	struct btp_device_found_ev ev;
> @@ -453,6 +667,12 @@ static void register_gap_service(void)
> 
>  	btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_SET_BONDABLE,
>  					btp_gap_set_bondable, NULL, NULL);
> +
> +	btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_START_DISCOVERY,
> +					btp_gap_start_discovery, NULL, NULL);
> +
> +	btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_STOP_DISCOVERY,
> +					btp_gap_stop_discovery, NULL, NULL);
>  }
> 
>  static void btp_core_read_commands(uint8_t index, const void *param,


-- 
pozdrawiam
Szymon Janc

  reply	other threads:[~2017-12-22 10:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 16:47 [PATCH BlueZ 1/6] shared/btp: define gap device found flags as bit mask Grzegorz Kolodziejczyk
2017-12-21 16:47 ` [PATCH BlueZ 2/6] tools/btpclient: Move string to address conversion to helper Grzegorz Kolodziejczyk
2017-12-22 10:48   ` Szymon Janc
2017-12-22 13:49     ` Grzegorz Kołodziejczyk
2017-12-21 16:47 ` [PATCH BlueZ 3/6] tools/btpclient: Add advertising proxy to adapter Grzegorz Kolodziejczyk
2017-12-22 10:48   ` Szymon Janc
2017-12-22 13:50     ` Grzegorz Kołodziejczyk
2017-12-21 16:47 ` [PATCH BlueZ 4/6] tools/btpclient: Add device found event Grzegorz Kolodziejczyk
2017-12-22 10:48   ` Szymon Janc
2017-12-22 13:51     ` Grzegorz Kołodziejczyk
2017-12-21 16:47 ` [PATCH BlueZ 5/6] tools/btpclient: Add start, stop discovery commands Grzegorz Kolodziejczyk
2017-12-22 10:48   ` Szymon Janc [this message]
2017-12-22 13:53     ` Grzegorz Kołodziejczyk
2017-12-21 16:47 ` [PATCH BlueZ 6/6] tools/btpclient: Add set connectable command Grzegorz Kolodziejczyk
2017-12-22 10:49 ` [PATCH BlueZ 1/6] shared/btp: define gap device found flags as bit mask Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1718429.lz8PR2LJZV@ix \
    --to=szymon.janc@codecoup.pl \
    --cc=grzegorz.kolodziejczyk@codecoup.pl \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).