Bluetooth: Fix trying to disable scanning twice
Subsystems (2)
PATCH 1/2 Bluetooth: Fix trying to disable scanning twice
From: Johan Hedberg <[email protected]>
The discovery process has a timer for disabling scanning, however scanning might be disabled through other means too like the auto-connect process. We should therefore ensure that the timer is never active after sending a HCI command to disable scanning.
There was some existing code in stop_scan_complete trying to avoid the timer when a connect request interrupts a discovery procedure, but the other way around was not covered. This patch covers both scenarios by canceling the timer as soon as we get a successful command complete for the disabling HCI command.
--- net/bluetooth/hci_conn.c | 1 - net/bluetooth/hci_event.c | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-)
net/bluetooth/hci_conn.c +0 -1
@@ -628,7 +628,6 @@ static void stop_scan_complete(struct hci_dev *hdev, u8 status)/* Since we may have prematurely stopped discovery procedure, we should * update discovery state. */ -cancel_delayed_work (&hdev->le_scan_disable);hci_discovery_set_state (hdev,DISCOVERY_STOPPED );hci_req_init (&req, hdev);
net/bluetooth/hci_event.c +5 -0
@@ -1018,6 +1018,11 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,break ;case LE_SCAN_DISABLE : +/* Cancel this timer so that we don't try to disable scanning +* when it's already disabled. +*/ +cancel_delayed_work (&hdev->le_scan_disable); +clear_bit (HCI_LE_SCAN , &hdev->dev_flags);break ;
Signature · 1 line
1.8.5.3
PATCH 2/2 Bluetooth: Remove unnecessary stop_scan_complete function
From: Johan Hedberg <[email protected]>
The stop_scan_complete function was used as an intermediate step before doing the actual connection creation. Since we're using hci_request there's no reason to have this extra function around, i.e. we can simply put both HCI commands into the same request.
The single task that the intermediate function had, i.e. indicating discovery as stopped is now taken care of by a new HCI_LE_SCAN_INTERRUPTED flag which allows us to do the discovery state update when the stop scan command completes.
--- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_conn.c | 51 +++++++-------------------------------------- net/bluetooth/hci_event.c | 7 +++++++ 3 files changed, 16 insertions(+), 43 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -140,6 +140,7 @@ enum {HCI_FAST_CONNECTABLE ,HCI_BREDR_ENABLED ,HCI_6LOWPAN_ENABLED , + HCI_LE_SCAN_INTERRUPTED, };/* A mask for the flags that are supposed to remain when a reset happens
net/bluetooth/hci_conn.c +8 -43
68 lines not on this page · raw message
net/bluetooth/hci_event.c +7 -0
@@ -1024,6 +1024,13 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,cancel_delayed_work (&hdev->le_scan_disable);clear_bit (HCI_LE_SCAN , &hdev->dev_flags); +/* The HCI_LE_SCAN_INTERRUPTED flag indicates that we +* interrupted scanning due to a connect request. Mark +* therefore discovery as stopped. +*/ +if (test_and_clear_bit (HCI_LE_SCAN_INTERRUPTED , + &hdev->dev_flags)) +hci_discovery_set_state (hdev,DISCOVERY_STOPPED );break ;default :
Signature · 1 line
1.8.5.3
Marcel Holtmann
maintainerRe: [PATCH 2/2] Bluetooth: Remove unnecessary stop_scan_complete function
Hi Johan,
Quoted 10 lines
The
stop_scan_completefunction was used as an intermediate step before doing the actual connection creation. Since we're usinghci_requestthere's no reason to have this extra function around, i.e. we can simply put both HCI commands into the same request.The single task that the intermediate function had, i.e. indicating discovery as stopped is now taken care of by a new
HCI_LE_SCAN_INTERRUPTEDflag which allows us to do the discovery state update when the stop scan command completes.
Quoted 6 lines
Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_conn.c | 51 +++++++-------------------------------------- net/bluetooth/hci_event.c | 7 +++++++ 3 files changed, 16 insertions(+), 43 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerHi Johan,
Quoted 11 lines
The discovery process has a timer for disabling scanning, however scanning might be disabled through other means too like the auto-connect process. We should therefore ensure that the timer is never active after sending a HCI command to disable scanning.
There was some existing code in
stop_scan_completetrying to avoid the timer when a connect request interrupts a discovery procedure, but the other way around was not covered. This patch covers both scenarios by canceling the timer as soon as we get a successful command complete for the disabling HCI command.
Quoted 5 lines
Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/hci_conn.c| 1 -net/bluetooth/hci_event.c| 5 +++++2 files changed, 5 insertions(+), 1 deletion(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel