2013-10-04 10:19:14

by Marcel Holtmann

[permalink] [raw]
Subject: [PATCH 1/2] Bluetooth: Make LE scan interval and window a controller option

The scan interval and window for LE passive scanning and connection
establishment should be configurable on a per controller basis. So
introduce a setting that later on will allow modifying it.

This setting does not affect LE active scanning during device
discovery phase. As long as that phase uses interleaved discovery,
it will will continuously scan.

Signed-off-by: Marcel Holtmann <[email protected]>
---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_conn.c | 4 ++--
net/bluetooth/hci_core.c | 3 +++
3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index e09c305..7442ece 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -164,6 +164,8 @@ struct hci_dev {
__u16 page_scan_interval;
__u16 page_scan_window;
__u8 page_scan_type;
+ __u16 le_scan_interval;
+ __u16 le_scan_window;

__u16 devid_source;
__u16 devid_vendor;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 08e601c..c5b115e 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -55,8 +55,8 @@ static void hci_le_create_connection(struct hci_conn *conn)
struct hci_cp_le_create_conn cp;

memset(&cp, 0, sizeof(cp));
- cp.scan_interval = __constant_cpu_to_le16(0x0060);
- cp.scan_window = __constant_cpu_to_le16(0x0030);
+ cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
+ cp.scan_window = cpu_to_le16(hdev->le_scan_window);
bacpy(&cp.peer_addr, &conn->dst);
cp.peer_addr_type = conn->dst_type;
cp.conn_interval_min = __constant_cpu_to_le16(0x0028);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 82dbdc6..6c2eff0 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2223,6 +2223,9 @@ struct hci_dev *hci_alloc_dev(void)
hdev->sniff_max_interval = 800;
hdev->sniff_min_interval = 80;

+ hdev->le_scan_interval = 0x0060;
+ hdev->le_scan_window = 0x0030;
+
mutex_init(&hdev->lock);
mutex_init(&hdev->req_lock);

--
1.8.3.1



2013-10-07 22:19:00

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: Make LE scan interval and window a controller option

Hi Andre,

>>>> The scan interval and window for LE passive scanning and connection
>>>> establishment should be configurable on a per controller basis. So
>>>> introduce a setting that later on will allow modifying it.
>>>
>>> Each remote device has their particular set of parameters based on the profiles it support. So, these parameters should be per device, not per controller.
>>>
>>> IIRC, we discussed about this in New Orleans and the connection parameters will be informed to the kernel through the Mgmt command to load the connection list. This way, we'll have the parameters set per device.
>>>
>>> So I don't understand exactly what is the purpose of this command you are introducing. Am I missing something?
>>
>> I looked through the core specification and also the scan parameters profile. And actually the way I read it is that these two values are pretty much controller centric.
>>
>> So yes, depending on the profile you are running you can change them. Or if you are running on an active device or if your device is in sleep mode. However at the end of day, the kernel does not really care much what these two values are. It can not make any smart decision about it.
>
> The way I see it, for connection (including background scan), the scan window and interval are Peripheral centric. I'll explain.
>
> Each profile specification recommends the set of parameters for connection establishment (see the "Connection Establishment" section of the profiles specification, for instance HoGP, PXP, FMP). At that section we find the advertising parameters the profile recommends for those who are implementing the Peripheral side and the connection parameters (scan window, scan interval, connection maximum and minimum interval) recommended for those who are implementing the Central side. The profiles may have different connection parameters (e.g. HoGP and FMP).
>
> So, based on the scanning parameters defined by the profiles the Central supports, we should configure the background scan. For instance, let's say we have three devices with the following scanning parameters:
> - Device A (HoGP): interval 22.5ms window 11.25ms
> - Device B (PXP): interval 60ms window 30ms
> - Device C (FMP): interval 60ms window 30ms
>
> For that list of devices, the background scan should be configured with interval 22.5ms window 11.25ms. Now, let's say Device A connects. Then the background scan should be configured with interval 60ms window 30ms.

so I wonder if it is worth it to put this into the kernel. Or let userspace just configure it. And if needed just change it.

Regards

Marcel


2013-10-07 21:28:20

by Andre Guedes

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: Make LE scan interval and window a controller option

Hi Marcel,

On 10/04/2013 11:39 PM, Marcel Holtmann wrote:
> Hi Andre,
>
>>> The scan interval and window for LE passive scanning and connection
>>> establishment should be configurable on a per controller basis. So
>>> introduce a setting that later on will allow modifying it.
>>
>> Each remote device has their particular set of parameters based on the profiles it support. So, these parameters should be per device, not per controller.
>>
>> IIRC, we discussed about this in New Orleans and the connection parameters will be informed to the kernel through the Mgmt command to load the connection list. This way, we'll have the parameters set per device.
>>
>> So I don't understand exactly what is the purpose of this command you are introducing. Am I missing something?
>
> I looked through the core specification and also the scan parameters profile. And actually the way I read it is that these two values are pretty much controller centric.
>
> So yes, depending on the profile you are running you can change them. Or if you are running on an active device or if your device is in sleep mode. However at the end of day, the kernel does not really care much what these two values are. It can not make any smart decision about it.

The way I see it, for connection (including background scan), the scan
window and interval are Peripheral centric. I'll explain.

Each profile specification recommends the set of parameters for
connection establishment (see the "Connection Establishment" section of
the profiles specification, for instance HoGP, PXP, FMP). At that
section we find the advertising parameters the profile recommends for
those who are implementing the Peripheral side and the connection
parameters (scan window, scan interval, connection maximum and minimum
interval) recommended for those who are implementing the Central side.
The profiles may have different connection parameters (e.g. HoGP and FMP).

So, based on the scanning parameters defined by the profiles the Central
supports, we should configure the background scan. For instance, let's
say we have three devices with the following scanning parameters:
- Device A (HoGP): interval 22.5ms window 11.25ms
- Device B (PXP): interval 60ms window 30ms
- Device C (FMP): interval 60ms window 30ms

For that list of devices, the background scan should be configured with
interval 22.5ms window 11.25ms. Now, let's say Device A connects. Then
the background scan should be configured with interval 60ms window 30ms.

> The way I read especially the scan parameters profile is that not the peripheral is telling us what would be good scan parameters. Instead the central is telling what scan parameters it is using and then the peripheral is suppose to adjust its advertising to it.

The Scan Parameters Profile seems to be useful in situation like the one
described above. The Central is not using the recommends scanning
parameters (since it has more than one set of parameters) so it informs
the Peripheral what parameters it is using. The Peripheral does its best
to configure its advertising interval according to the scanning
parameters the Central is using.

> All the information to pick good scan parameters are based on the remote profiles and whatever the system is currently doing. So my current take is that we let bluetoothd make that call and set the right parameters and the kernel just uses them. Of course buetoothd can adjust these at runtime any time it wants to.

The background scanning parameters can be configured by bluetoothd or
internaly by the kernel. At the moment, I'm not sure what option is the
best.

> Settings like the connection interval are different. They are learned from the advertising data and can be used by the connection process. The scan internal and window however make no difference. For background scanning and auto-connection handling these values should be used. In case of pairing and direct connections, we better set them to same value to get a continuous scan anyway. Same as we do for active scanning during discovery right now.

The maximum and minimum connection intervals are defined by the profiles
and/or in the advertising data.

The Central should use them to establish connection in order to optimize
the energy comsuption on the Peripheral side. If the Central doesn't use
the recommended parameters, the Peripheral may send a Connection
Parameter Update Request through the signaling channel to change the
connection parameters.

Regards,

Andre

2013-10-05 02:39:23

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: Make LE scan interval and window a controller option

Hi Andre,

>> The scan interval and window for LE passive scanning and connection
>> establishment should be configurable on a per controller basis. So
>> introduce a setting that later on will allow modifying it.
>
> Each remote device has their particular set of parameters based on the profiles it support. So, these parameters should be per device, not per controller.
>
> IIRC, we discussed about this in New Orleans and the connection parameters will be informed to the kernel through the Mgmt command to load the connection list. This way, we'll have the parameters set per device.
>
> So I don't understand exactly what is the purpose of this command you are introducing. Am I missing something?

I looked through the core specification and also the scan parameters profile. And actually the way I read it is that these two values are pretty much controller centric.

So yes, depending on the profile you are running you can change them. Or if you are running on an active device or if your device is in sleep mode. However at the end of day, the kernel does not really care much what these two values are. It can not make any smart decision about it.

The way I read especially the scan parameters profile is that not the peripheral is telling us what would be good scan parameters. Instead the central is telling what scan parameters it is using and then the peripheral is suppose to adjust its advertising to it.

All the information to pick good scan parameters are based on the remote profiles and whatever the system is currently doing. So my current take is that we let bluetoothd make that call and set the right parameters and the kernel just uses them. Of course buetoothd can adjust these at runtime any time it wants to.

Settings like the connection interval are different. They are learned from the advertising data and can be used by the connection process. The scan internal and window however make no difference. For background scanning and auto-connection handling these values should be used. In case of pairing and direct connections, we better set them to same value to get a continuous scan anyway. Same as we do for active scanning during discovery right now.

If anybody knows any better, I am happy to discuss this, but that is what I got from reading the actual specifications.

Regards

Marcel


2013-10-04 21:51:46

by Andre Guedes

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: Make LE scan interval and window a controller option

Hi Marcel,

On 10/04/2013 07:19 AM, Marcel Holtmann wrote:
> The scan interval and window for LE passive scanning and connection
> establishment should be configurable on a per controller basis. So
> introduce a setting that later on will allow modifying it.

Each remote device has their particular set of parameters based on the
profiles it support. So, these parameters should be per device, not per
controller.

IIRC, we discussed about this in New Orleans and the connection
parameters will be informed to the kernel through the Mgmt command to
load the connection list. This way, we'll have the parameters set per
device.

So I don't understand exactly what is the purpose of this command you
are introducing. Am I missing something?

Regards,

Andre