Skip to contentSkip to conversation

Bluetooth: Add le_scan_restart

PATCH Superseded Jakub Pawlowski 2 participants 3 messages Jan 16, 2015 – Jan 22, 2015

Subsystems (2)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v9 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         | 58 ++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/mgmt.c             |  7 ++++-
 3 files changed, 67 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +3 -0
index 7777124..de019eb 100644
@@ -79,6 +79,7 @@ struct discovery_state {
 	s8			rssi;
 	u16			uuid_count;
 	u8			(*uuids)[16];
+	unsigned long		scan_end;
 };
 
 struct hci_conn_hash {
@@ -351,6 +352,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];
@@ -527,6 +529,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 +58 -0

94 lines not on this page · raw message

net/bluetooth/mgmt.c +6 -1
index f5c4d2e..c2b5f8a 100644
@@ -3878,9 +3878,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 v9 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             | 48 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index de019eb..cbfc18e 100644
@@ -1328,6 +1328,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 +44 -4

82 lines not on this page · raw message

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

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

Hi Jakub,

Quoted 8 lines · Jakub Pawlowski

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.

Quoted 5 lines
---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/mgmt.c             | 48 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 4 deletions(-)

A couple of minor things with this one still:

include/net/bluetooth/hci_core.h void hci_sock_dev_event(struct hci_dev *hdev, int event); · line 1331

Quoted 9 lines
include/net/bluetooth/hci_core.h +1 -0
index de019eb..cbfc18e 100644
@@ -1328,6 +1328,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 */

Please put the msecs_to_jiffies() straight into the definition here (see our other similar defines in include/net/bluetooth/hci.h for examples). This makes the code using the define simpler (e.g. less need for line breaks).

include/net/bluetooth/hci_core.h void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 7243

Quoted 11 lines
include/net/bluetooth/hci_core.h +3 -1
 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 		       u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
 		       u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len)
@@ -7224,7 +7238,9 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 	 * the results are also dropped.
 	 */
 	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 correctly aligned: the !test_bit should start at the same place as the 'r' of the rssi on the line above.

Quoted 4 lines
include/net/bluetooth/hci_core.h +0 -0
@@ -7296,7 +7320,15 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 						     hdev->discovery.uuid_count,
 						     hdev->discovery.uuids))
 				return;

include/net/bluetooth/hci_core.h void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 7331

Quoted 10 lines
include/net/bluetooth/hci_core.h +9 -1
-		}
+
+			/* we have service match. If duplicate filtering doesn't
+			 * honour RSSI hanges, restart scan to make sure we'll
+			 * get RSSI updates
+			 */
+			if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER,
+				     &hdev->quirks))
+				restart_le_scan(hdev);
+			}

Something's not quite right here indentation-wise. The closing } seems to be on the same level as the 'if' which can't be right?

Johan