All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: Fix sending redundant "LE Set Scan Enable (disable)" commands
@ 2014-09-26 14:50 Alfonso Acosta
  0 siblings, 0 replies; only message in thread
From: Alfonso Acosta @ 2014-09-26 14:50 UTC (permalink / raw)
  To: linux-bluetooth

Checking the LE scanning state (HCI_LE_SCAN) before queuing a new "LE
Set Scan Enable (disable)" command is not enough to avoid sending
extra redundant commands. Since HCI_LE_SCAN is only updated upon
"Command Complete" confirmation, multiple "LE Set Scan Enable
(disable)" can get queued before the first one gets delivered.

I encountered this issue when unpairing (MGMT_OP_UNPAIR_DEVICE) and
immediately pairing (MGMT_OP_PAIR_DEVICE) the only auto-connected
device. MGMT_OP_UNPAIR_DEVICE stopped scanning since there were no
more auto-connected devices and MGMT_OP_PAIR_DEVICE also stopped
scanning because some controllers cannot scan while connecting.

I added a dedicated flag (le_scan_disable_queued) in hci_dev for this
purpose since dev_flags is already full.

Signed-off-by: Alfonso Acosta <fons@spotify.com>
---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_core.c         | 4 +++-
 net/bluetooth/hci_event.c        | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 37ff1ae..04c2f2f 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -292,6 +292,7 @@ struct hci_dev {
  struct sk_buff_head rx_q;
  struct sk_buff_head raw_q;
  struct sk_buff_head cmd_q;
+ int le_scan_disable_queued;

  struct sk_buff *recv_evt;
  struct sk_buff *sent_cmd;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index cb05d7f..d0d27e7 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -5441,10 +5441,12 @@ static void hci_cmd_work(struct work_struct *work)
 void hci_req_add_le_scan_disable(struct hci_request *req)
 {
  struct hci_cp_le_set_scan_enable cp;
-
+ if(req->hdev->le_scan_disable_queued)
+  return;
  memset(&cp, 0, sizeof(cp));
  cp.enable = LE_SCAN_DISABLE;
  hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
+ req->hdev->le_scan_disable_queued = 1;
 }

 static void add_to_white_list(struct hci_request *req,
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8b0a2a6..ad81335 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1122,7 +1122,7 @@ static void hci_cc_le_set_scan_enable(struct
hci_dev *hdev,
  __u8 status = *((__u8 *) skb->data);

  BT_DBG("%s status 0x%2.2x", hdev->name, status);
-
+ hdev->le_scan_disable_queued = 0;
  if (status)
  return;

-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-09-26 14:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26 14:50 [PATCH] Bluetooth: Fix sending redundant "LE Set Scan Enable (disable)" commands Alfonso Acosta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.