Skip to contentSkip to conversation

Bluetooth: Update discovery state earlier in hci_discovery_set_state

PATCH In review [email protected] 2 participants 4 messages Jul 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Bluetooth: Update discovery state earlier in hci_discovery_set_state

From: Johan Hedberg <[email protected]>

In a subsequent patch the hci_update_background_scan() function will depend on being able to know the current discovery state. For this to be possible we need to set the new state early in the function. Since we also need to check what the old state was this patch introduces an extra variable for tracking it.

---
 net/bluetooth/hci_core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/bluetooth/hci_core.c +6 -4
index 623ffe0da4a6..6a0e39f69e03 100644
@@ -1903,16 +1903,20 @@ bool hci_discovery_active(struct hci_dev *hdev)
 
 void hci_discovery_set_state(struct hci_dev *hdev, int state)
 {
+	int old_state = hdev->discovery.state;
+
 	BT_DBG("%s state %u -> %u", hdev->name, hdev->discovery.state, state);
 
-	if (hdev->discovery.state == state)
+	if (old_state == state)
 		return;
 
+	hdev->discovery.state = state;
+
 	switch (state) {
 	case DISCOVERY_STOPPED:
 		hci_update_background_scan(hdev);
 
-		if (hdev->discovery.state != DISCOVERY_STARTING)
+		if (old_state != DISCOVERY_STARTING)
 			mgmt_discovering(hdev, 0);
 		break;
 	case DISCOVERY_STARTING:
@@ -1925,8 +1929,6 @@ void hci_discovery_set_state(struct hci_dev *hdev, int state)
 	case DISCOVERY_STOPPING:
 		break;
 	}
-
-	hdev->discovery.state = state;
 }
 
 void hci_inquiry_cache_flush(struct hci_dev *hdev)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 2/2 Bluetooth: Don't let background scanning interfering with discovery

From: Johan Hedberg <[email protected]>

If we have an active discovery going on we shouldn't do any changes to LE scanning when hci_update_background_scan() is called (a call which can happen for many different reasons). This patch fixes the issue by returning from the function if the discovery state is anything else except DISCOVERY_STOPPED.

---
 net/bluetooth/hci_core.c | 4 ++++
 1 file changed, 4 insertions(+)
net/bluetooth/hci_core.c +4 -0
index 6a0e39f69e03..4f8ba49ac49d 100644
@@ -5403,6 +5403,10 @@ void hci_update_background_scan(struct hci_dev *hdev)
 	    test_bit(HCI_UNREGISTER, &hdev->dev_flags))
 		return;
 
+	/* If discovery is active don't interfere with it */
+	if (hdev->discovery.state != DISCOVERY_STOPPED)
+		return;
+
 	hci_req_init(&req, hdev);
 
 	if (list_empty(&hdev->pend_le_conns) &&
Signature · 1 line
1.9.3
maintainer
#2 lore raw

Re: [PATCH 2/2] Bluetooth: Don't let background scanning interfering with discovery

Hi Johan,

Quoted 10 lines

If we have an active discovery going on we shouldn't do any changes to LE scanning when hci_update_background_scan() is called (a call which can happen for many different reasons). This patch fixes the issue by returning from the function if the discovery state is anything else except DISCOVERY_STOPPED.

---
net/bluetooth/hci_core.c | 4 ++++

1 file changed, 4 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

maintainer
#3 lore raw
In reply to [email protected]

Hi Johan,

Quoted 10 lines

In a subsequent patch the hci_update_background_scan() function will depend on being able to know the current discovery state. For this to be possible we need to set the new state early in the function. Since we also need to check what the old state was this patch introduces an extra variable for tracking it.

---
net/bluetooth/hci_core.c | 10 ++++++----

1 file changed, 6 insertions(+), 4 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel