Bluetooth: Improve device found events in busy environments
Subsystems (2)
cover Bluetooth: Improve device found events in busy environments
Hi,
Here are two patches which I saw necessary for having decent behavior with CSR adapters in crowded environments (3 or more advertisers).
Johan
----------------------------------------------------------------
Johan Hedberg (2):
Bluetooth: Don't send device found events for duplicate reports
Bluetooth: Store also RSSI for pending advertising reports
include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_event.c | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-)
PATCH 1/2 Bluetooth: Don't send device found events for duplicate reports
From: Johan Hedberg <[email protected]>
Occasionally, during active scanning we will receive duplicate ADV_IND reports from the same device before receiving the SCAN_RSP from them. In order to not wake up user space unnecessarily it's better not to send these extra events as they do not contain any new information.
--- net/bluetooth/hci_event.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
net/bluetooth/hci_event.c +12 -7
@@ -4021,6 +4021,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, u8 bdaddr_type, s8 rssi, u8 *data, u8 len) { struct discovery_state *d = &hdev->discovery; +bool match;/* Passive scanning shouldn't trigger any device found events */ if (hdev->le_scan_type ==LE_SCAN_PASSIVE ) {
@@ -4048,17 +4049,21 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,return ; } +/* Check if the pending report is for the same device as the new one */ + match = (!bacmp (bdaddr, &d->last_adv_addr) && + bdaddr_type == d->last_adv_addr_type); +/* If the pending data doesn't match this report or this isn't a * scan response (e.g. we got a duplicate ADV_IND) then force * sending of the pending data. */ -if (type !=LE_ADV_SCAN_RSP ||bacmp (bdaddr, &d->last_adv_addr) || - bdaddr_type != d->last_adv_addr_type) { -/* Send out whatever is in the cache */ -mgmt_device_found (hdev, &d->last_adv_addr,LE_LINK , - d->last_adv_addr_type,NULL ,0 ,0 ,1 , - d->last_adv_data, d->last_adv_data_len, -NULL ,0 ); +if (type !=LE_ADV_SCAN_RSP || !match) { +/* Send out whatever is in the cache, but skip duplicates */ +if (!match) +mgmt_device_found (hdev, &d->last_adv_addr,LE_LINK , + d->last_adv_addr_type,NULL ,0 , +0 ,1 , d->last_adv_data, + d->last_adv_data_len,NULL ,0 );/* If the new report will trigger a SCAN_REQ store it for * later merging.
Signature · 1 line
1.8.5.3
PATCH 2/2 Bluetooth: Store also RSSI for pending advertising reports
In reply to [email protected]From: Johan Hedberg <[email protected]>
Especially in crowded environments it can become frequent that we have to send out whatever pending event there is stored. Since user space has its own filtering of small RSSI changes sending a 0 value will essentially force user space to wake up the higher layers (e.g. over D-Bus) even though the RSSI didn't actually change more than the threshold value.
This patch adds storing also of the RSSI for pending advertising reports so that we report an as accurate RSSI as possible when we have to send out the stored information to user space.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_event.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -70,6 +70,7 @@ struct discovery_state {__u32 timestamp;bdaddr_t last_adv_addr;u8 last_adv_addr_type; +s8 rssi;u8 last_adv_data[HCI_MAX_AD_LENGTH ];u8 last_adv_data_len; };
net/bluetooth/hci_event.c +5 -4
@@ -1049,12 +1049,13 @@ static void clear_pending_adv_report(struct hci_dev *hdev) }static void store_pending_adv_report (struct hci_dev *hdev,bdaddr_t *bdaddr, -u8 bdaddr_type,u8 *data,u8 len) +s8 rssi,u8 bdaddr_type,u8 *data,u8 len) {struct discovery_state *d = &hdev->discovery;bacpy (&d->last_adv_addr, bdaddr); d->last_adv_addr_type = bdaddr_type; + d->rssi = rssi;memcpy (d->last_adv_data, data, len); d->last_adv_data_len = len; }
@@ -4040,7 +4041,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,*/ if (type ==LE_ADV_IND || type ==LE_ADV_SCAN_IND ) {store_pending_adv_report (hdev, bdaddr, bdaddr_type, - data, len); + rssi, data, len);return ; }
@@ -4061,7 +4062,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,/* Send out whatever is in the cache, but skip duplicates */ if (!match)mgmt_device_found (hdev, &d->last_adv_addr,LE_LINK , - d->last_adv_addr_type,NULL ,0 , + d->last_adv_addr_type,NULL , d->rssi,0 ,1 , d->last_adv_data, d->last_adv_data_len,NULL ,0 );
@@ -4070,7 +4071,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,*/ if (type ==LE_ADV_IND || type ==LE_ADV_SCAN_IND ) {store_pending_adv_report (hdev, bdaddr, bdaddr_type, - data, len); + rssi, data, len);return ; }
Signature · 1 line
1.8.5.3
PATCH v2 2/2 Bluetooth: Store also RSSI for pending advertising reports
From: Johan Hedberg <[email protected]>
Especially in crowded environments it can become frequent that we have to send out whatever pending event there is stored. Since user space has its own filtering of small RSSI changes sending a 0 value will essentially force user space to wake up the higher layers (e.g. over D-Bus) even though the RSSI didn't actually change more than the threshold value.
This patch adds storing also of the RSSI for pending advertising reports so that we report an as accurate RSSI as possible when we have to send out the stored information to user space.
---
v2: Use consistent last_adv prefix for the rssi variable
include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_event.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -70,6 +70,7 @@ struct discovery_state {__u32 timestamp;bdaddr_t last_adv_addr;u8 last_adv_addr_type; +s8 last_adv_rssi;u8 last_adv_data[HCI_MAX_AD_LENGTH ];u8 last_adv_data_len; };
net/bluetooth/hci_event.c +7 -5
@@ -1049,12 +1049,13 @@ static void clear_pending_adv_report(struct hci_dev *hdev) }static void store_pending_adv_report (struct hci_dev *hdev,bdaddr_t *bdaddr, -u8 bdaddr_type,u8 *data,u8 len) +s8 rssi,u8 bdaddr_type,u8 *data,u8 len) {struct discovery_state *d = &hdev->discovery;bacpy (&d->last_adv_addr, bdaddr); d->last_adv_addr_type = bdaddr_type; + d->last_adv_rssi = rssi;memcpy (d->last_adv_data, data, len); d->last_adv_data_len = len; }
@@ -4040,7 +4041,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,*/ if (type ==LE_ADV_IND || type ==LE_ADV_SCAN_IND ) {store_pending_adv_report (hdev, bdaddr, bdaddr_type, - data, len); + rssi, data, len);return ; }
@@ -4061,8 +4062,9 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,/* Send out whatever is in the cache, but skip duplicates */ if (!match)mgmt_device_found (hdev, &d->last_adv_addr,LE_LINK , - d->last_adv_addr_type,NULL ,0 , -0 ,1 , d->last_adv_data, + d->last_adv_addr_type,NULL , + d->last_adv_rssi,0 ,1 , + d->last_adv_data, d->last_adv_data_len,NULL ,0 );/* If the new report will trigger a SCAN_REQ store it for
@@ -4070,7 +4072,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,*/ if (type ==LE_ADV_IND || type ==LE_ADV_SCAN_IND ) {store_pending_adv_report (hdev, bdaddr, bdaddr_type, - data, len); + rssi, data, len);return ; }
Signature · 1 line
1.8.5.3
Marcel Holtmann
maintainerHi Johan,
Quoted 5 lines
Here are two patches which I saw necessary for having decent behavior with CSR adapters in crowded environments (3 or more advertisers).
Johan
Quoted 8 lines
----------------------------------------------------------------
Johan Hedberg (2):
Bluetooth: Don't send device found events for duplicate reports
Bluetooth: Store also RSSI for pending advertising reports
include/net/bluetooth/hci_core.h| 1 +net/bluetooth/hci_event.c| 26 ++++++++++++++++----------2 files changed, 17 insertions(+), 10 deletions(-)
both patches (v2) have been applied to bluetooth-next tree.
Regards
Marcel