[PATCH 2/5] Bluetooth: Add le_state_supported helper macro

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

 



This allows for quickly checking if given LE states combination is
supported by controller. Combination is identified by bit number, as
defined in Core 5.0, Vol 2, Part E, 7.8.27.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@xxxxxxxxxxx>
---
 include/net/bluetooth/hci_core.h |  4 ++++
 net/bluetooth/hci_request.c      | 14 +++++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 094e61e07030..cdbab10fc4a6 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1207,6 +1207,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 /* Extended advertising support */
 #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
 
+/* LE supportes states and states combinations */
+#define le_state_supported(dev, bit) ((dev)->le_states[(bit) / 8] & \
+				      (1 << ((bit) % 8)))
+
 /* ----- HCI protocols ----- */
 #define HCI_PROTO_DEFER             0x01
 
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index ca73d36cc149..71c138c56321 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -1015,28 +1015,28 @@ static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable)
 	/* Check le_states if there is any connection in slave role. */
 	if (hdev->conn_hash.le_num_slave > 0) {
 		/* Slave connection state and non connectable mode bit 20. */
-		if (!connectable && !(hdev->le_states[2] & 0x10))
+		if (!connectable && !le_state_supported(hdev, 20))
 			return false;
 
 		/* Slave connection state and connectable mode bit 38
 		 * and scannable bit 21.
 		 */
-		if (connectable && (!(hdev->le_states[4] & 0x40) ||
-				    !(hdev->le_states[2] & 0x20)))
+		if (connectable && (!le_state_supported(hdev, 21) ||
+				    !le_state_supported(hdev, 38)))
 			return false;
 	}
 
 	/* Check le_states if there is any connection in master role. */
 	if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_slave) {
-		/* Master connection state and non connectable mode bit 18. */
-		if (!connectable && !(hdev->le_states[2] & 0x02))
+		/* Master connection state and non connectable mode bit 17. */
+		if (!connectable && !le_state_supported(hdev, 17))
 			return false;
 
 		/* Master connection state and connectable mode bit 35 and
 		 * scannable 19.
 		 */
-		if (connectable && (!(hdev->le_states[4] & 0x08) ||
-				    !(hdev->le_states[2] & 0x08)))
+		if (connectable && (!le_state_supported(hdev, 19) ||
+				    !le_state_supported(hdev, 35)))
 			return false;
 	}
 
-- 
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