All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] hciconfig: Add an option to set which advertise type will be on
@ 2012-11-21 14:09 Jefferson Delfes
  2012-11-21 18:51 ` Johan Hedberg
  2012-11-21 20:16 ` [PATCH BlueZ v2] " Jefferson Delfes
  0 siblings, 2 replies; 5+ messages in thread
From: Jefferson Delfes @ 2012-11-21 14:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

There are some advertise types that can be used, so we need a way to
tell which one we want. The default one is ADV_IND.
---
 tools/hciconfig.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 64f2650..e107bff 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -254,8 +254,31 @@ static void cmd_le_adv(int ctl, int hdev, char *opt)
 		exit(1);
 	}
 
+	if (opt == NULL || strcmp(opt, "noleadv")) {
+		le_set_advertising_parameters_cp adv_params_cp;
+
+		memset(&adv_params_cp, 0, sizeof(adv_params_cp));
+		adv_params_cp.min_interval = 0x0800;
+		adv_params_cp.max_interval = 0x0800;
+		if (opt)
+			adv_params_cp.advtype = atoi(opt);
+		adv_params_cp.chan_map = 7;
+
+		memset(&rq, 0, sizeof(rq));
+		rq.ogf = OGF_LE_CTL;
+		rq.ocf = OCF_LE_SET_ADVERTISING_PARAMETERS;
+		rq.cparam = &adv_params_cp;
+		rq.clen = LE_SET_ADVERTISING_PARAMETERS_CP_SIZE;
+		rq.rparam = &status;
+		rq.rlen = 1;
+
+		ret = hci_send_req(dd, &rq, 1000);
+		if (ret < 0)
+			goto done;
+	}
+
 	memset(&advertise_cp, 0, sizeof(advertise_cp));
-	if (strcmp(opt, "noleadv") == 0)
+	if (opt && strcmp(opt, "noleadv") == 0)
 		advertise_cp.enable = 0x00;
 	else
 		advertise_cp.enable = 0x01;
@@ -270,6 +293,7 @@ static void cmd_le_adv(int ctl, int hdev, char *opt)
 
 	ret = hci_send_req(dd, &rq, 1000);
 
+done:
 	hci_close_dev(dd);
 
 	if (ret < 0) {
@@ -1932,7 +1956,9 @@ static struct {
 	{ "block",	cmd_block,	"<bdaddr>",	"Add a device to the blacklist" },
 	{ "unblock",	cmd_unblock,	"<bdaddr>",	"Remove a device from the blacklist" },
 	{ "lerandaddr", cmd_le_addr,	"<bdaddr>",	"Set LE Random Address" },
-	{ "leadv",	cmd_le_adv,	0,		"Enable LE advertising" },
+	{ "leadv",	cmd_le_adv,	"[type]",	"Enable LE advertising"
+		"\n\t\t\t0 - Connectable undirected advertising (default)"
+		"\n\t\t\t3 - Non connectable undirected advertising"},
 	{ "noleadv",	cmd_le_adv,	0,		"Disable LE advertising" },
 	{ "lestates",	cmd_le_states,	0,		"Display the supported LE states" },
 	{ NULL, NULL, 0 }
-- 
1.8.0


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

* Re: [PATCH BlueZ] hciconfig: Add an option to set which advertise type will be on
  2012-11-21 14:09 [PATCH BlueZ] hciconfig: Add an option to set which advertise type will be on Jefferson Delfes
@ 2012-11-21 18:51 ` Johan Hedberg
  2012-11-21 19:04   ` Jefferson Delfes
  2012-11-21 20:16 ` [PATCH BlueZ v2] " Jefferson Delfes
  1 sibling, 1 reply; 5+ messages in thread
From: Johan Hedberg @ 2012-11-21 18:51 UTC (permalink / raw)
  To: Jefferson Delfes; +Cc: linux-bluetooth

Hi Jefferson,

On Wed, Nov 21, 2012, Jefferson Delfes wrote:
> +	if (opt == NULL || strcmp(opt, "noleadv")) {

Wouldn't it be more intuitive to compare against "leadv" here instead of
"noleadv". Also whenever doing strcmp comparisons please use an explicit
== 0 or != 0. Also, if the logic (and length) of this function starts
growing too much you should really consider splitting it into one per
command.

Johan

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

* Re: [PATCH BlueZ] hciconfig: Add an option to set which advertise type will be on
  2012-11-21 18:51 ` Johan Hedberg
@ 2012-11-21 19:04   ` Jefferson Delfes
  0 siblings, 0 replies; 5+ messages in thread
From: Jefferson Delfes @ 2012-11-21 19:04 UTC (permalink / raw)
  To: Jefferson Delfes, linux-bluetooth

Hi Johan.

I did compare with "noleadv" because if you have some param in
command.opt, main function drops one argument (command name) and it
will pass only the parameter of the command. So or it will be empty,
or it will have the argument for leadv.

I can split this function. Probably it will be more intuitive.

Thanks.

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

* [PATCH BlueZ v2] hciconfig: Add an option to set which advertise type will be on
  2012-11-21 14:09 [PATCH BlueZ] hciconfig: Add an option to set which advertise type will be on Jefferson Delfes
  2012-11-21 18:51 ` Johan Hedberg
@ 2012-11-21 20:16 ` Jefferson Delfes
  2012-11-22  8:15   ` Johan Hedberg
  1 sibling, 1 reply; 5+ messages in thread
From: Jefferson Delfes @ 2012-11-21 20:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

There are some advertise types that can be used, so we need a way to
tell which one we want. The default one is ADV_IND.
---
 tools/hciconfig.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 6 deletions(-)

diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 64f2650..99d15c2 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -242,6 +242,71 @@ static void cmd_le_adv(int ctl, int hdev, char *opt)
 {
 	struct hci_request rq;
 	le_set_advertise_enable_cp advertise_cp;
+	le_set_advertising_parameters_cp adv_params_cp;
+	uint8_t status;
+	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);
+	}
+
+	memset(&adv_params_cp, 0, sizeof(adv_params_cp));
+	adv_params_cp.min_interval = htobs(0x0800);
+	adv_params_cp.max_interval = htobs(0x0800);
+	if (opt)
+		adv_params_cp.advtype = atoi(opt);
+	adv_params_cp.chan_map = 7;
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LE_CTL;
+	rq.ocf = OCF_LE_SET_ADVERTISING_PARAMETERS;
+	rq.cparam = &adv_params_cp;
+	rq.clen = LE_SET_ADVERTISING_PARAMETERS_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen = 1;
+
+	ret = hci_send_req(dd, &rq, 1000);
+	if (ret < 0)
+		goto done;
+
+	memset(&advertise_cp, 0, sizeof(advertise_cp));
+	advertise_cp.enable = 0x01;
+
+	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, 1000);
+
+done:
+	hci_close_dev(dd);
+
+	if (ret < 0) {
+		fprintf(stderr, "Can't set advertise mode on hci%d: %s (%d)\n",
+						hdev, strerror(errno), errno);
+		exit(1);
+	}
+
+	if (status) {
+		fprintf(stderr, "LE set advertise enable on hci%d returned status %d\n",
+						hdev, status);
+		exit(1);
+	}
+}
+
+static void cmd_no_le_adv(int ctl, int hdev, char *opt)
+{
+	struct hci_request rq;
+	le_set_advertise_enable_cp advertise_cp;
 	uint8_t status;
 	int dd, ret;
 
@@ -255,10 +320,6 @@ static void cmd_le_adv(int ctl, int hdev, char *opt)
 	}
 
 	memset(&advertise_cp, 0, sizeof(advertise_cp));
-	if (strcmp(opt, "noleadv") == 0)
-		advertise_cp.enable = 0x00;
-	else
-		advertise_cp.enable = 0x01;
 
 	memset(&rq, 0, sizeof(rq));
 	rq.ogf = OGF_LE_CTL;
@@ -1932,8 +1993,10 @@ static struct {
 	{ "block",	cmd_block,	"<bdaddr>",	"Add a device to the blacklist" },
 	{ "unblock",	cmd_unblock,	"<bdaddr>",	"Remove a device from the blacklist" },
 	{ "lerandaddr", cmd_le_addr,	"<bdaddr>",	"Set LE Random Address" },
-	{ "leadv",	cmd_le_adv,	0,		"Enable LE advertising" },
-	{ "noleadv",	cmd_le_adv,	0,		"Disable LE advertising" },
+	{ "leadv",	cmd_le_adv,	"[type]",	"Enable LE advertising"
+		"\n\t\t\t0 - Connectable undirected advertising (default)"
+		"\n\t\t\t3 - Non connectable undirected advertising"},
+	{ "noleadv",	cmd_no_le_adv,	0,		"Disable LE advertising" },
 	{ "lestates",	cmd_le_states,	0,		"Display the supported LE states" },
 	{ NULL, NULL, 0 }
 };
-- 
1.8.0


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

* Re: [PATCH BlueZ v2] hciconfig: Add an option to set which advertise type will be on
  2012-11-21 20:16 ` [PATCH BlueZ v2] " Jefferson Delfes
@ 2012-11-22  8:15   ` Johan Hedberg
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2012-11-22  8:15 UTC (permalink / raw)
  To: Jefferson Delfes; +Cc: linux-bluetooth

Hi Jefferson,

On Wed, Nov 21, 2012, Jefferson Delfes wrote:
> There are some advertise types that can be used, so we need a way to
> tell which one we want. The default one is ADV_IND.
> ---
>  tools/hciconfig.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 69 insertions(+), 6 deletions(-)

Applied. Thanks.

Johan

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

end of thread, other threads:[~2012-11-22  8:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-21 14:09 [PATCH BlueZ] hciconfig: Add an option to set which advertise type will be on Jefferson Delfes
2012-11-21 18:51 ` Johan Hedberg
2012-11-21 19:04   ` Jefferson Delfes
2012-11-21 20:16 ` [PATCH BlueZ v2] " Jefferson Delfes
2012-11-22  8:15   ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.