Bluetooth: fix service discovery behaviour for empty uuids filter
Subsystems (2)
PATCH v2 1/1 Bluetooth: fix service discovery behaviour for empty uuids filter
This patch fixes service discovery behaviour, when provided uuid filter is empty and HCI_QUIRK_STRICT_DUPLICATE_FILTER is set. Before this patch, empty uuid filter was unable to trigger scan restart, and that caused inconsistent behaviour in applications.
Example: two DBus clients call BlueZ, one to find all devices with service abcd, second to find all devices with rssi smaller than -90. Sum of those filters, that is passed to mgmt_service_scan is empty filter, with no rssi or uuids set.
That caused kernel not to restart scan when quirk was set. That was inconsistent with what happen when there's only one of those two filters set (scan is restarted and reports devices).
To fix that, new variable hdev->discovery.service_discovery was introduced. It can indicate that filtered scan is running, no matter what uuid or rssi filter is set.
This patch also closes all code responsible for filtered discovery in one if statement. That makes whole code shorter, much more readable, and easier to backport to older kernels, especially pre 3.10.
--- include/net/bluetooth/hci_core.h | 2 + net/bluetooth/mgmt.c | 140 +++++++++++++++------------------------ 2 files changed, 55 insertions(+), 87 deletions(-)
include/net/bluetooth/hci_core.h +2 -0
@@ -76,6 +76,7 @@ struct discovery_state {u8 last_adv_data[HCI_MAX_AD_LENGTH ];u8 last_adv_data_len;bool report_invalid_rssi; +bool service_discovery;s8 rssi;u16 uuid_count;u8 (*uuids)[16 ];
@@ -529,6 +530,7 @@ static inline void discovery_init(struct hci_dev *hdev)static inline void hci_discovery_filter_clear (struct hci_dev *hdev) { + hdev->discovery.service_discovery = false; hdev->discovery.report_invalid_rssi = true; hdev->discovery.rssi =HCI_RSSI_INVALID ; hdev->discovery.uuid_count =0 ;
net/bluetooth/mgmt.c +53 -87
174 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Hi Jakub,
net/bluetooth/mgmt.c static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, · line 4083
Quoted 5 lines · Jakub Pawlowski
net/bluetooth/mgmt.c +1
-0@@ -4081,6 +4080,7 @@ static int start_service_discovery(struct sock *sk, struct hci_dev *hdev,*/ hci_discovery_filter_clear (hdev); + hdev->discovery.service_scan = true;
How much have you actually tested this patch considering that it doesn't even compile? The above should be 'service_discovery' rather than 'service_scan'.
I think there's also some mismatch of {} somewhere since I also get the following compile errors:
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:net/bluetooth/mgmt.c:7391:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
^net/bluetooth/mgmt.c:7427:13: error: invalid storage class for function ‘adv_enable_complete’
static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
^
net/bluetooth/mgmt.c:7442:1: error: expected declaration or statement at end of input
}
^net/bluetooth/mgmt.c:7442:1: error: expected declaration or statement at end of input net/bluetooth/mgmt.c:7283:7: warning: unused variable ‘match’ [-Wunused-variable]
bool match;
^Johan
Quoted 11 lines · Johan Hedberg
Hi Jakub,
net/bluetooth/mgmt.c static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, · line 4083
Quoted 5 lines · Jakub Pawlowski
net/bluetooth/mgmt.c +1
-0@@ -4081,6 +4080,7 @@ static int start_service_discovery(struct sock *sk, struct hci_dev *hdev,*/ hci_discovery_filter_clear (hdev); + hdev->discovery.service_scan = true;How much have you actually tested this patch considering that it doesn't even compile? The above should be '
service_discovery' rather than 'service_scan'.
I'm working on 3.14 chromeos branch with lots of backports, then I have another machine with ubuntu with 3.19 where I test again, and then I apply my patches to bluetooth-next when it works on both, but sometimes some half-done version gets copied and emailed by mistake, sorry. I'm uploading fixed version.
Quoted 20 lines
I think there's also some mismatch of {} somewhere since I also get the following compile errors:
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:net/bluetooth/mgmt.c:7391:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
void mgmt_remote_name(structhci_dev*hdev,bdaddr_t*bdaddr, u8link_type,
^net/bluetooth/mgmt.c:7427:13: error: invalid storage class for function ‘adv_enable_complete’
static voidadv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)^
net/bluetooth/mgmt.c:7442:1: error: expected declaration or statement at end of input
}
^net/bluetooth/mgmt.c:7442:1: error: expected declaration or statement at end of inputnet/bluetooth/mgmt.c:7283:7: warning: unused variable ‘match’ [-Wunused-variable]bool match; ^Johan