All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add option to set LE random address to hciconfig
@ 2011-01-28 22:33 Claudio Takahasi
  2011-01-28 22:33 ` [PATCH 2/2] Add option to enable privacy during scanning to hcitool Claudio Takahasi
  0 siblings, 1 reply; 6+ messages in thread
From: Claudio Takahasi @ 2011-01-28 22:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 tools/hciconfig.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 6e5117f..c271d14 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -195,6 +195,49 @@ static void cmd_scan(int ctl, int hdev, char *opt)
 	}
 }
 
+static void cmd_le_addr(int ctl, int hdev, char *opt)
+{
+	struct hci_request rq;
+	le_set_random_address_cp cp;
+	uint8_t status;
+	int dd, err, ret;
+
+	if (!opt)
+		return;
+
+	if (hdev < 0)
+		hdev = hci_get_route(NULL);
+
+	dd = hci_open_dev(hdev);
+	if (dd < 0) {
+		err = errno;
+		fprintf(stderr, "Could not open device: %s(%d)\n",
+							strerror(err), err);
+		exit(1);
+	}
+
+	memset(&cp, 0, sizeof(cp));
+
+	str2ba(opt, &cp.bdaddr);
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LE_CTL;
+	rq.ocf = OCF_LE_SET_RANDOM_ADDRESS;
+	rq.cparam = &cp;
+	rq.clen = LE_SET_RANDOM_ADDRESS_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen = 1;
+
+	ret = hci_send_req(dd, &rq, 1000);
+	if (status || ret < 0) {
+		err = errno;
+		fprintf(stderr, "Can't set random address for hci%d: "
+					"%s (%d)\n", hdev, strerror(err), err);
+	}
+
+	hci_close_dev(dd);
+}
+
 static void cmd_le_adv(int ctl, int hdev, char *opt)
 {
 	struct hci_request rq;
@@ -1879,6 +1922,7 @@ 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" },
+	{ "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" },
 	{ "lestates",	cmd_le_states,	0,		"Display the supported LE states" },
-- 
1.7.4.rc2


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

end of thread, other threads:[~2011-01-31 18:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 22:33 [PATCH 1/2] Add option to set LE random address to hciconfig Claudio Takahasi
2011-01-28 22:33 ` [PATCH 2/2] Add option to enable privacy during scanning to hcitool Claudio Takahasi
2011-01-31  8:40   ` Johan Hedberg
2011-01-31 13:50     ` Claudio Takahasi
2011-01-31 15:46       ` Luiz Augusto von Dentz
2011-01-31 18:09         ` Claudio Takahasi

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.