[PATCH 5/5] Bluetooth: Fix set advertising while scanning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We can check states supported by controller to determine whether it is
allowed to advertise while scanning or not.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@xxxxxxxxxxx>
---
 net/bluetooth/hci_request.c | 24 +++++++++++++++++++++---
 net/bluetooth/mgmt.c        |  4 +---
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 71c138c56321..5498afec03fb 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -1008,9 +1008,27 @@ static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags)
 
 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable)
 {
-	/* If there is no connection we are OK to advertise. */
-	if (hci_conn_num(hdev, LE_LINK) == 0)
-		return true;
+	/* Check le_states if there is active scanning ongoing */
+	if (hci_dev_test_flag(hdev, HCI_LE_SCAN) &&
+	    hdev->le_scan_type == LE_SCAN_ACTIVE) {
+		if (!connectable && !le_state_supported(hdev, 12))
+			return false;
+
+		if (connectable && (!le_state_supported(hdev, 13) ||
+				    !le_state_supported(hdev, 14)))
+			return false;
+	}
+
+	/* Check le_states if there is passive scanning ongoing */
+	if (hci_dev_test_flag(hdev, HCI_LE_SCAN) &&
+	    hdev->le_scan_type == LE_SCAN_PASSIVE) {
+		if (!connectable && !le_state_supported(hdev, 8))
+			return false;
+
+		if (connectable && (!le_state_supported(hdev, 9) ||
+				    !le_state_supported(hdev, 10)))
+			return false;
+	}
 
 	/* Check le_states if there is any connection in slave role. */
 	if (hdev->conn_hash.le_num_slave > 0) {
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d44681c99341..3072c104888e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4333,9 +4333,7 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
 	 */
 	if (!hdev_is_powered(hdev) ||
 	    (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) &&
-	     (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) ||
-	    (hci_dev_test_flag(hdev, HCI_LE_SCAN) &&
-	     hdev->le_scan_type == LE_SCAN_ACTIVE)) {
+	     (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE))) {
 		bool changed;
 
 		if (cp->val) {
-- 
2.20.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux