linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hciconfig: add LE_SET_ADVERTISE_ENABLE cmd
@ 2010-08-19 20:52 Anderson Briglia
  2010-09-06  7:22 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Anderson Briglia @ 2010-08-19 20:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia

This patch implements two new hciconfig commands: leadv and noleadv.
These new hciconfig flags are responsible to LE_SET_ADVERTISE_ENABLE
command implementation.
---
 tools/hciconfig.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 87dd127..1e04193 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -149,6 +149,45 @@ static void cmd_scan(int ctl, int hdev, char *opt)
 	}
 }
 
+static void cmd_le_adv(int ctl, int hdev, char *opt)
+{
+	struct hci_request rq;
+	le_set_advertise_enable_cp advertise_cp;
+	uint8_t status, enable;
+	int dd, ret;
+
+	if (hdev < 0)
+		hdev = hci_get_route(NULL);
+
+	dd = hci_open_dev(hdev);
+	if (dd < 0) {
+		perror("Could not open device");
+		exit(1);
+	}
+
+	enable = 0x01;
+	if (!strcmp(opt, "noleadv"))
+		enable = 0x00;
+
+	memset(&advertise_cp, 0, sizeof(advertise_cp));
+	advertise_cp.enable = enable;
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LE_CTL;
+	rq.ocf = OCF_LE_SET_ADVERTISE_ENABLE;
+	rq.cparam = &advertise_cp;
+	rq.clen = LE_SET_ADVERTISE_ENABLE_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen = 1;
+
+	ret = hci_send_req(dd, &rq, 100);
+	if (status || ret < 0)
+		fprintf(stderr, "Can't set advertise mode on hci%d: %s (%d)\n",
+						hdev, strerror(errno), errno);
+
+	hci_close_dev(dd);
+}
+
 static void cmd_iac(int ctl, int hdev, char *opt)
 {
 	int s = hci_open_dev(hdev);
@@ -1728,6 +1767,8 @@ static struct {
 	{ "revision",	cmd_revision,	0,		"Display revision information" },
 	{ "block",	cmd_block,	"<bdaddr>",	"Add a device to the blacklist" },
 	{ "unblock",	cmd_unblock,	"<bdaddr>",	"Remove a device from the blacklist" },
+	{ "leadv",	cmd_le_adv,	0,		"Enable LE advertising" },
+	{ "noleadv",	cmd_le_adv,	0,		"Disable LE advertising" },
 	{ NULL, NULL, 0 }
 };
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] hciconfig: add LE_SET_ADVERTISE_ENABLE cmd
  2010-08-19 20:52 [PATCH v2] hciconfig: add LE_SET_ADVERTISE_ENABLE cmd Anderson Briglia
@ 2010-09-06  7:22 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2010-09-06  7:22 UTC (permalink / raw)
  To: Anderson Briglia; +Cc: linux-bluetooth

Hi Anderson,

On Thu, Aug 19, 2010, Anderson Briglia wrote:
> This patch implements two new hciconfig commands: leadv and noleadv.
> These new hciconfig flags are responsible to LE_SET_ADVERTISE_ENABLE
> command implementation.
> ---
>  tools/hciconfig.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 41 insertions(+), 0 deletions(-)

Sorry for the delay with this patch, seems I've missed it.

> +static void cmd_le_adv(int ctl, int hdev, char *opt)
> +{
> +	struct hci_request rq;
> +	le_set_advertise_enable_cp advertise_cp;
> +	uint8_t status, enable;
> +	int dd, ret;
> +
> +	if (hdev < 0)
> +		hdev = hci_get_route(NULL);
> +
> +	dd = hci_open_dev(hdev);
> +	if (dd < 0) {
> +		perror("Could not open device");
> +		exit(1);
> +	}
> +
> +	enable = 0x01;
> +	if (!strcmp(opt, "noleadv"))
> +		enable = 0x00;
> +
> +	memset(&advertise_cp, 0, sizeof(advertise_cp));
> +	advertise_cp.enable = enable;

I know that the other functions in the file have similar logic, but
could we still simplify this a little bit. I.e. get rid of the enable
variable completely and move the checking for "noleadv" after the
memset:

	if (strcmp(opt, "noleadv") == 0)
		advertise_cp.enable = 0x00;
	else
		advertise_cp.enable = 0x01;

Other than that the patch seems fine to me.

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-06  7:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-19 20:52 [PATCH v2] hciconfig: add LE_SET_ADVERTISE_ENABLE cmd Anderson Briglia
2010-09-06  7:22 ` Johan Hedberg

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).