Skip to contentSkip to conversation

Bluetooth: Add le_scan_restart

PATCH Superseded Jakub Pawlowski 2 participants 4 messages Jan 9, 2015 – Jan 14, 2015

Subsystems (2)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/2 Bluetooth: Add le_scan_restart

Currently there is no way to restart le scan, and it's needed in service scan method. The way it work: it disable, and then enable le scan on controller.

---
 include/net/bluetooth/hci_core.h |  3 +++
 net/bluetooth/hci_core.c         | 54 ++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/mgmt.c             |  7 +++++-
 3 files changed, 63 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +3 -0
index 89f4e3c..add94f6 100644
@@ -79,6 +79,7 @@ struct discovery_state {
 	s8			rssi;
 	u16			uuid_count;
 	u8			(*uuids)[16];
+	long		scan_end;
 };
 
 struct hci_conn_hash {
@@ -349,6 +350,7 @@ struct hci_dev {
 	unsigned long		dev_flags;
 
 	struct delayed_work	le_scan_disable;
+	struct delayed_work	le_scan_restart;
 
 	__s8			adv_tx_power;
 	__u8			adv_data[HCI_MAX_AD_LENGTH];
@@ -525,6 +527,7 @@ static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
 	hdev->discovery.uuid_count = 0;
 	kfree(hdev->discovery.uuids);
 	hdev->discovery.uuids = NULL;
+	hdev->discovery.scan_end = 0;
 }
 
 bool hci_discovery_active(struct hci_dev *hdev);
net/bluetooth/hci_core.c +54 -0

90 lines not on this page · raw message

net/bluetooth/mgmt.c +6 -1
index 6b3f553..9f295cd 100644
@@ -3875,9 +3875,14 @@ static void start_discovery_complete(struct hci_dev *hdev, u8 status)
 		break;
 	}
 
-	if (timeout)
+	if (timeout) {
+		if (hdev->discovery.uuid_count > 0 &&
+		    test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks))
+			hdev->discovery.scan_end = jiffies + timeout;
+
 		queue_delayed_work(hdev->workqueue,
 				   &hdev->le_scan_disable, timeout);
+	}
 
 unlock:
 	hci_dev_unlock(hdev);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH v7 2/2 Bluetooth: Add restarting to service discovery

When using LE_SCAN_FILTER_DUP_ENABLE, some controllers would send advertising report from each LE device only once. That means that we don't get any updates on RSSI value, and makes Service Discovery very slow. This patch adds restarting scan when in Service Discovery, and device with filtered uuid is found, but it's not in RSSI range to send event yet. This way if device moves into range, we will quickly get RSSI update.

---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/mgmt.c             | 43 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index add94f6..86c1bd7 100644
@@ -1327,6 +1327,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event);
 #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
 #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
 #define DISCOV_BREDR_INQUIRY_LEN	0x08
+#define DISCOV_LE_RESTART_DELAY		200	/* msec */
 
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
 int mgmt_new_settings(struct hci_dev *hdev);
net/bluetooth/mgmt.c +39 -4

77 lines not on this page · raw message

Signature · 1 line
2.2.0.rc0.207.ga3a616c
#2 lore raw

Re: [PATCH v7 2/2] Bluetooth: Add restarting to service discovery

Hi Jakub,

net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 7208

Quoted 4 lines · Jakub Pawlowski
net/bluetooth/mgmt.c +2 -1
 	if (hdev->discovery.rssi != HCI_RSSI_INVALID &&
-	    (rssi < hdev->discovery.rssi || rssi == HCI_RSSI_INVALID))
+	    (rssi == HCI_RSSI_INVALID || (rssi < hdev->discovery.rssi &&
+	    !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks))))

This doesn't look like it's following the coding-style of split lines. You probably need to move the "(rssi < hdev->discovery.rssi &&" to start from a new line so that you can align the "!test_bit(..." properly.

Johan

#3 lore raw
In reply to Jakub Pawlowski

Hi Jakub,

Quoted 10 lines · Jakub Pawlowski

Currently there is no way to restart le scan, and it's needed in service scan method. The way it work: it disable, and then enable le scan on controller.

---
 include/net/bluetooth/hci_core.h |  3 +++
 net/bluetooth/hci_core.c         | 54 ++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/mgmt.c             |  7 +++++-
 3 files changed, 63 insertions(+), 1 deletion(-)

In general this approach looks definitely simper to me as well - I think we're getting closer to something that can go upstream :)

The main issues I've got concerns about anymore is the complexity coming from various if-conditions here and there (which might be simplifiable by refactoring some common tasks into smaller helper functions) as well as some minor coding style issues.

include/net/bluetooth/hci_core.h struct discovery_state { · line 82

Quoted 9 lines
include/net/bluetooth/hci_core.h +1 -0
index 89f4e3c..add94f6 100644
@@ -79,6 +79,7 @@ struct discovery_state {
 	s8			rssi;
 	u16			uuid_count;
 	u8			(*uuids)[16];
+	long		scan_end;

I hope this is properly aligned with the other variables? It could be the initial non-tab characters that mess this up when looking at the diff or what I just quoted, but there the variables don't line up.

Quoted 7 lines
include/net/bluetooth/hci_core.h +7 -0
+static void le_scan_restart_work_complete(struct hci_dev *hdev, u8 status)
+{
+	BT_DBG("%s", hdev->name);
+
+	if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) &&
+	    hdev->discovery.scan_end != 0) {
+		long timeout = hdev->discovery.scan_end - jiffies;

include/net/bluetooth/hci_core.h struct discovery_state {

Quoted 10 lines
include/net/bluetooth/hci_core.h +10 -0
+
+		if (timeout < 0)
+			timeout = 0;
+		queue_delayed_work(hdev->workqueue,
+				   &hdev->le_scan_disable, timeout);
+	}
+
+	if (status)
+		BT_ERR("Failed to restart LE scan: status %d", status);
+}

This doesn't look right. Shouldn't the status check be at the very beginning of the function? If restarting scanning failed, what's the point of queuing the delayed work to disable scanning?

include/net/bluetooth/hci_core.h

Quoted 4 lines
include/net/bluetooth/hci_core.h +4 -0
+	err = hci_req_run(&req, le_scan_restart_work_complete);
+
+	if (err)
+		BT_ERR("Restart LE scan request failed: err %d", err);

You can drop the empty line between assignment to err and the check for its value.

Johan