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

* [PATCH 2/2] Add option to enable privacy during scanning to hcitool
  2011-01-28 22:33 [PATCH 1/2] Add option to set LE random address to hciconfig Claudio Takahasi
@ 2011-01-28 22:33 ` Claudio Takahasi
  2011-01-31  8:40   ` Johan Hedberg
  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

When privacy is enabled, random address is used during active scanning.
The non-resolvable private address shall be set using hciconfig.
---
 tools/hcitool.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/hcitool.c b/tools/hcitool.c
index d50adaf..536d407 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -2349,25 +2349,30 @@ done:
 
 static struct option lescan_options[] = {
 	{ "help",	0, 0, 'h' },
+	{ "privacy",	0, 0, 'p' },
 	{ 0, 0, 0, 0 }
 };
 
 static const char *lescan_help =
 	"Usage:\n"
-	"\tlescan\n";
+	"\tlescan [--privacy] enable privacy\n";
 
 static void cmd_lescan(int dev_id, int argc, char **argv)
 {
 	int err, opt, dd;
+	uint8_t own_type = 0x00;
 
 	for_each_opt(opt, lescan_options, NULL) {
 		switch (opt) {
+		case 'p':
+			own_type = 0x01; /* Random */
+			break;
 		default:
 			printf("%s", lescan_help);
 			return;
 		}
 	}
-	helper_arg(0, 0, &argc, &argv, lescan_help);
+	helper_arg(0, 1, &argc, &argv, lescan_help);
 
 	if (dev_id < 0)
 		dev_id = hci_get_route(NULL);
@@ -2378,8 +2383,8 @@ static void cmd_lescan(int dev_id, int argc, char **argv)
 		exit(1);
 	}
 
-	err = hci_le_set_scan_parameters(dd, 0x01, htobs(0x0010), htobs(0x0010),
-								0x00, 0x00);
+	err = hci_le_set_scan_parameters(dd, 0x01, htobs(0x0010),
+					htobs(0x0010), own_type, 0x00);
 	if (err < 0) {
 		perror("Set scan parameters failed");
 		exit(1);
-- 
1.7.4.rc2


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

* Re: [PATCH 2/2] Add option to enable privacy during scanning to hcitool
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Hedberg @ 2011-01-31  8:40 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Fri, Jan 28, 2011, Claudio Takahasi wrote:
> When privacy is enabled, random address is used during active scanning.
> The non-resolvable private address shall be set using hciconfig.
> ---
>  tools/hcitool.c |   13 +++++++++----
>  1 files changed, 9 insertions(+), 4 deletions(-)

Both patches have been pushed upstream. Thanks.

Any plans how to represent this feature in the official APIs? I suppose
the random address can be generated automatically using some appropriate
source such as the HCI_LE_Rand command but how do we represent the
public vs random address selection using the D-Bus API? Or do we even
need to do that?

Johan

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

* Re: [PATCH 2/2] Add option to enable privacy during scanning to hcitool
  2011-01-31  8:40   ` Johan Hedberg
@ 2011-01-31 13:50     ` Claudio Takahasi
  2011-01-31 15:46       ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 6+ messages in thread
From: Claudio Takahasi @ 2011-01-31 13:50 UTC (permalink / raw)
  To: Claudio Takahasi, linux-bluetooth

Hi Johan,

On Mon, Jan 31, 2011 at 6:40 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Claudio,
>
> On Fri, Jan 28, 2011, Claudio Takahasi wrote:
>> When privacy is enabled, random address is used during active scanning.
>> The non-resolvable private address shall be set using hciconfig.
>> ---
>>  tools/hcitool.c |   13 +++++++++----
>>  1 files changed, 9 insertions(+), 4 deletions(-)
>
> Both patches have been pushed upstream. Thanks.
>
> Any plans how to represent this feature in the official APIs? I suppose
> the random address can be generated automatically using some appropriate
> source such as the HCI_LE_Rand command but how do we represent the
> public vs random address selection using the D-Bus API? Or do we even
> need to do that?
>
> Johan
>

I added these changes to investigate the PTS  test result, it is not
mandatory. I am was planning to focus on Register Application API
first instead of privacy for central. The implementation is simple, if
someone in the community wants to help us, here are some guidelines:

My idea is add a new property in the adapter interface called:
Privacy. The changes will be:
1. Add Privacy property with persistent storage =>
adapter.SetProperty("Privacy", True/False)
2. Generate a non-resolvable private address. My suggestion is to read
the data directly from "/dev/random" instead of use HCI_LE_Rand
command(needs to wait for command complete).
3. Trigger the LE scanning based on this property.

PS: For LE Create Connection command the own address type must be set
based on privacy value, however this change requires changes in the
kernel. Currently, Own_Address_Type is hard-coded in the kernel(public
address only).

Regards,
Claudio.

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

* Re: [PATCH 2/2] Add option to enable privacy during scanning to hcitool
  2011-01-31 13:50     ` Claudio Takahasi
@ 2011-01-31 15:46       ` Luiz Augusto von Dentz
  2011-01-31 18:09         ` Claudio Takahasi
  0 siblings, 1 reply; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2011-01-31 15:46 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Mon, Jan 31, 2011 at 3:50 PM, Claudio Takahasi
<claudio.takahasi@openbossa.org> wrote:
> Hi Johan,
>
> On Mon, Jan 31, 2011 at 6:40 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>> Hi Claudio,
>>
>> On Fri, Jan 28, 2011, Claudio Takahasi wrote:
>>> When privacy is enabled, random address is used during active scanning.
>>> The non-resolvable private address shall be set using hciconfig.
>>> ---
>>>  tools/hcitool.c |   13 +++++++++----
>>>  1 files changed, 9 insertions(+), 4 deletions(-)
>>
>> Both patches have been pushed upstream. Thanks.
>>
>> Any plans how to represent this feature in the official APIs? I suppose
>> the random address can be generated automatically using some appropriate
>> source such as the HCI_LE_Rand command but how do we represent the
>> public vs random address selection using the D-Bus API? Or do we even
>> need to do that?
>>
>> Johan
>>
>
> I added these changes to investigate the PTS  test result, it is not
> mandatory. I am was planning to focus on Register Application API
> first instead of privacy for central. The implementation is simple, if
> someone in the community wants to help us, here are some guidelines:
>
> My idea is add a new property in the adapter interface called:
> Privacy. The changes will be:
> 1. Add Privacy property with persistent storage =>
> adapter.SetProperty("Privacy", True/False)

Can this be unset, I mean can a device really use a random/private and
than latter switch to public? For what I understand if anyone pair
using the random/private address they don't store the actual address
but a key to resolve the address, so switching on runtime is IMO not a
good idea, perhaps a parameter on main.conf is enough?

Actually the spec say that there could be at least 3 types of random address:

- Static
- Private Non-resolvable
- Private Resolvable

> 2. Generate a non-resolvable private address. My suggestion is to read
> the data directly from "/dev/random" instead of use HCI_LE_Rand
> command(needs to wait for command complete).

I remember someone saying that the controller should be able to
generate a more random number because it uses the RF signal
interference for that, but Im not sure if this is actually true or
not, or if enough to give up the idea of using /dev/random.

> 3. Trigger the LE scanning based on this property.
>
> PS: For LE Create Connection command the own address type must be set
> based on privacy value, however this change requires changes in the
> kernel. Currently, Own_Address_Type is hard-coded in the kernel(public
> address only).

Yep, we probably need to start by fixing this, it seems some device
will already come with random addresses so it will be nice to have
this fixed asap.


-- 
Luiz Augusto von Dentz
Computer Engineer

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

* Re: [PATCH 2/2] Add option to enable privacy during scanning to hcitool
  2011-01-31 15:46       ` Luiz Augusto von Dentz
@ 2011-01-31 18:09         ` Claudio Takahasi
  0 siblings, 0 replies; 6+ messages in thread
From: Claudio Takahasi @ 2011-01-31 18:09 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

On Mon, Jan 31, 2011 at 1:46 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Claudio,
>
> On Mon, Jan 31, 2011 at 3:50 PM, Claudio Takahasi
> <claudio.takahasi@openbossa.org> wrote:
>> Hi Johan,
>>
>> On Mon, Jan 31, 2011 at 6:40 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>>> Hi Claudio,
>>>
>>> On Fri, Jan 28, 2011, Claudio Takahasi wrote:
>>>> When privacy is enabled, random address is used during active scanning.
>>>> The non-resolvable private address shall be set using hciconfig.
>>>> ---
>>>>  tools/hcitool.c |   13 +++++++++----
>>>>  1 files changed, 9 insertions(+), 4 deletions(-)
>>>
>>> Both patches have been pushed upstream. Thanks.
>>>
>>> Any plans how to represent this feature in the official APIs? I suppose
>>> the random address can be generated automatically using some appropriate
>>> source such as the HCI_LE_Rand command but how do we represent the
>>> public vs random address selection using the D-Bus API? Or do we even
>>> need to do that?
>>>
>>> Johan
>>>
>>
>> I added these changes to investigate the PTS  test result, it is not
>> mandatory. I am was planning to focus on Register Application API
>> first instead of privacy for central. The implementation is simple, if
>> someone in the community wants to help us, here are some guidelines:
>>
>> My idea is add a new property in the adapter interface called:
>> Privacy. The changes will be:
>> 1. Add Privacy property with persistent storage =>
>> adapter.SetProperty("Privacy", True/False)
>
> Can this be unset, I mean can a device really use a random/private and
> than latter switch to public? For what I understand if anyone pair
> using the random/private address they don't store the actual address
> but a key to resolve the address, so switching on runtime is IMO not a
> good idea, perhaps a parameter on main.conf is enough?

Yes, there isn't such restriction. At least, I didn't find it.
For central, if I understood correctly a non-resolvable private(or
random static for reconnection address) address can be used when a new
discovery session starts. We can always use a non-resolvable private
address during the scanning, I don't see an use case that we need to
use a random static for it.

Indeed the random static needs to be stored, otherwise the white
list/reconnection address will not work, but this will affect
advertising only. How to use random static address needs further
investigation from my side, but I don't think that it needs to be
exposed to the users.

>
> Actually the spec say that there could be at least 3 types of random address:
>
> - Static
> - Private Non-resolvable
> - Private Resolvable
>
>> 2. Generate a non-resolvable private address. My suggestion is to read
>> the data directly from "/dev/random" instead of use HCI_LE_Rand
>> command(needs to wait for command complete).
>
> I remember someone saying that the controller should be able to
> generate a more random number because it uses the RF signal
> interference for that, but Im not sure if this is actually true or
> not, or if enough to give up the idea of using /dev/random.
>
>> 3. Trigger the LE scanning based on this property.
>>
I forgot to add some items
4. Use/Set the reconnection address when necessary

5. While list management for peripheral

BR,
Claudio

>> PS: For LE Create Connection command the own address type must be set
>> based on privacy value, however this change requires changes in the
>> kernel. Currently, Own_Address_Type is hard-coded in the kernel(public
>> address only).
>
> Yep, we probably need to start by fixing this, it seems some device
> will already come with random addresses so it will be nice to have
> this fixed asap.
>
>
> --
> Luiz Augusto von Dentz
> Computer Engineer
>

^ permalink raw reply	[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.