Skip to contentSkip to conversation

LE LL Priavcy support enabled

PATCH In review Sathish Narsimman 5 participants 21 messages Mar 12, 2020 – Apr 6, 2020

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

cover LE LL Priavcy support enabled

With this LE LL Priavcy feature available if BT controller supports LL Privacy when privacy is enabled.

The patches are verified in below case.
Pairing - where the IRK is added to device Resolving List after identity info & IRK is shared in SMP.
Unpair - Delete the resolving entry from the Device resolving list Local IRK change - Whenever there is change in local IRK (privacy) the resolving list entries in the device is updated.
Whitelist - filter policies for whitelist is updated based on LL_adress resolution support.
Reload Resolving list - device reset/sysmte reboot the Resolving list reloaded in to the device.

Sathish Narsimman (7):
Bluetooth: LL Privacy Delete Store Resolving list
Bluetooth: Add device to Resolving List
Bluetooth: Update the Resolving list when Local IRK changed
Bluetooth: LL_PRIVACY re-load resolving list
Bluetooth: LL Privacy Check and Update the Resolving List
Bluetooth: Enable LL Privacy
Bluetooth LL Privacy update White list

 include/net/bluetooth/hci.h      |   3 +
 include/net/bluetooth/hci_core.h |   7 +
 net/bluetooth/hci_conn.c         |  32 ++++
 net/bluetooth/hci_core.c         |  20 ++-
 net/bluetooth/hci_event.c        |  32 +++-
 net/bluetooth/hci_request.c      | 251 ++++++++++++++++++++++++++++++-
 net/bluetooth/hci_request.h      |   2 +
 net/bluetooth/mgmt.c             |  10 +-
 net/bluetooth/smp.c              |  11 ++
 9 files changed, 354 insertions(+), 14 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/7 Bluetooth: LL Privacy Delete Store Resolving list

This patch help to delte the resolving list stored in the BT Controller w.r.t BD_ADDR.

---
 include/net/bluetooth/hci.h      |  1 +
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_request.c      | 33 ++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)
include/net/bluetooth/hci.h +1 -0
index 5f60e135aeb6..352bc43940ff 100644
@@ -457,6 +457,7 @@ enum {
 #define HCI_LE_DATA_LEN_EXT		0x20
 #define HCI_LE_PHY_2M			0x01
 #define HCI_LE_PHY_CODED		0x08
+#define HCI_LE_LL_PRIVACY		0x40
 #define HCI_LE_EXT_ADV			0x10
 #define HCI_LE_EXT_SCAN_POLICY		0x80
 #define HCI_LE_PHY_2M			0x01
include/net/bluetooth/hci_core.h +2 -0
index d4e28773d378..5f04ef88da35 100644
@@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
+void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
+				     bdaddr_t *bdaddr);
 
 #define SCO_AIRMODE_MASK       0x0003
 #define SCO_AIRMODE_CVSD       0x0000
net/bluetooth/hci_request.c +33 -0
index bf83179ab9d1..f4bbd3b79210 100644
@@ -885,6 +885,39 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 	}
 }
 
+void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr)
+{
+	struct hci_cp_le_del_from_resolv_list cp;
+	struct hci_request req;
+	struct bdaddr_list_with_irk *irk;
+
+	BT_DBG("");
+
+	/* Nothing to be done if LL privacy is not supported */
+	if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+		return;
+
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+	      hci_lookup_le_connect(hdev) ) )
+		return;
+
+	/* If the device is not present in resolving list
+	 * no need to send HCI command.
+	 */
+	irk = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, addr_type);
+	if (!irk)
+		return;
+
+	hci_req_init(&req, hdev);
+	cp.bdaddr_type = addr_type;
+	bacpy(&cp.bdaddr, bdaddr);
+
+	hci_req_add(&req, HCI_OP_LE_DEL_FROM_RESOLV_LIST, sizeof(cp), &cp);
+	hci_req_run(&req, NULL);
+}
+
 void hci_req_add_le_passive_scan(struct hci_request *req)
 {
 	struct hci_dev *hdev = req->hdev;
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list

Hi Sathish,

Quoted 50 lines

This patch help to delte the resolving list stored in the BT Controller w.r.t BD_ADDR.

---

include/net/bluetooth/hci.h      |  1 +
include/net/bluetooth/hci_core.h |  2 ++
net/bluetooth/hci_request.c      | 33 ++++++++++++++++++++++++++++++++
3 files changed, 36 insertions(+)
include/net/bluetooth/hci.h +1 -0
index 5f60e135aeb6..352bc43940ff 100644
@@ -457,6 +457,7 @@ enum {
 #define HCI_LE_DATA_LEN_EXT		0x20
 #define HCI_LE_PHY_2M			0x01
 #define HCI_LE_PHY_CODED		0x08
+#define HCI_LE_LL_PRIVACY		0x40
 #define HCI_LE_EXT_ADV			0x10
 #define HCI_LE_EXT_SCAN_POLICY		0x80
 #define HCI_LE_PHY_2M			0x01
include/net/bluetooth/hci_core.h +2 -0
index d4e28773d378..5f04ef88da35 100644
@@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
+void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
+				     bdaddr_t *bdaddr);
 
 #define SCO_AIRMODE_MASK       0x0003
 #define SCO_AIRMODE_CVSD       0x0000
net/bluetooth/hci_request.c +7 -0
index bf83179ab9d1..f4bbd3b79210 100644
@@ -885,6 +885,39 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 	}
 }
 
+void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr)
+{
+	struct hci_cp_le_del_from_resolv_list cp;
+	struct hci_request req;
+	struct bdaddr_list_with_irk *irk;
+
+	BT_DBG("");

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, · line 904

Quoted 10 lines
net/bluetooth/hci_request.c +10 -0
+
+	/* Nothing to be done if LL privacy is not supported */
+	if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+		return;
+
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+	      hci_lookup_le_connect(hdev) ) )
+		return;

please don’t invent your own coding style. Follow the netdev convention.

Regards

Marcel

#3 lore raw

Re: [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list

Hi Marcel

Quoted 57 lines · Marcel Holtmann

Hi Sathish,

Quoted 54 lines

This patch help to delte the resolving list stored in the BT Controller w.r.t BD_ADDR.

---

include/net/bluetooth/hci.h      |  1 +
include/net/bluetooth/hci_core.h |  2 ++
net/bluetooth/hci_request.c      | 33 ++++++++++++++++++++++++++++++++
3 files changed, 36 insertions(+)
include/net/bluetooth/hci.h +1 -0
index 5f60e135aeb6..352bc43940ff 100644
@@ -457,6 +457,7 @@ enum {
 #define HCI_LE_DATA_LEN_EXT           0x20
 #define HCI_LE_PHY_2M                 0x01
 #define HCI_LE_PHY_CODED              0x08
+#define HCI_LE_LL_PRIVACY            0x40
 #define HCI_LE_EXT_ADV                        0x10
 #define HCI_LE_EXT_SCAN_POLICY                0x80
 #define HCI_LE_PHY_2M                 0x01
include/net/bluetooth/hci_core.h +2 -0
index d4e28773d378..5f04ef88da35 100644
@@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
                             u8 *bdaddr_type);
+void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
+                                  bdaddr_t *bdaddr);
 
 #define SCO_AIRMODE_MASK       0x0003
 #define SCO_AIRMODE_CVSD       0x0000
net/bluetooth/hci_request.c +11 -0
index bf83179ab9d1..f4bbd3b79210 100644
@@ -885,6 +885,39 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
      }
 }
 
+void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr)
+{
+     struct hci_cp_le_del_from_resolv_list cp;
+     struct hci_request req;
+     struct bdaddr_list_with_irk *irk;
+
+     BT_DBG("");
+
+     /* Nothing to be done if LL privacy is not supported */
+     if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+             return;
Quoted 8 lines

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, · line 904

Quoted 6 lines
net/bluetooth/hci_request.c +6 -0
+
+     if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+         ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+           hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+           hci_lookup_le_connect(hdev) ) )
+             return;

please don’t invent your own coding style. Follow the netdev convention.

Sure will correct the coding style in next version of the patch

Quoted 5 lines

Regards

Marcel

#4 lore raw

PATCH 2/7 Bluetooth: Add device to Resolving List

In reply to Sathish Narsimman

The Patch is used to add the device to resolving list. The patch will look for the local IRK list and if the device is present in the local resolving list it will be updated and the same updated w.r.t to BT controller by first deleting the existing and adding the new IRK w.r.t bd_addr.

---
 include/net/bluetooth/hci_core.h |  2 +
 net/bluetooth/hci_request.c      | 80 ++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
include/net/bluetooth/hci_core.h +2 -0
index 5f04ef88da35..e5e09d530ce7 100644
@@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
+int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
+				  bdaddr_t *bdaddr, u8 irk[16]);
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
 				     bdaddr_t *bdaddr);
 
net/bluetooth/hci_request.c +80 -0

86 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 2/7] Bluetooth: Add device to Resolving List

Hi,

Quoted 56 lines · On Thursday, 12 March 2020 11:07:49 CET Sathish Narsimman wrote:

The Patch is used to add the device to resolving list. The patch will look for the local IRK list and if the device is present in the local resolving list it will be updated and the same updated w.r.t to BT controller by first deleting the existing and adding the new IRK w.r.t bd_addr.

---
 include/net/bluetooth/hci_core.h |  2 +
 net/bluetooth/hci_request.c      | 80 ++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
(quoted diff) +0 -0

b/include/net/bluetooth/hci_core.h index 5f04ef88da35..e5e09d530ce7 100644

include/net/bluetooth/hci_core.h +2 -0
@@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16
 ediv, __le64 rand,
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
+int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
+				  bdaddr_t *bdaddr, u8 irk[16]);
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
 				     bdaddr_t *bdaddr);
net/bluetooth/hci_request.c +20 -0
index f4bbd3b79210..88225a9ca1f8 100644
@@ -885,6 +885,86 @@ static void hci_req_start_scan(struct hci_request *req,
 u8 type, u16 interval, }
 }
 
+int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t
 *bdaddr, +				  u8 irk_val[16])
+{
+	struct hci_request req;
+	struct hci_cp_le_add_to_resolv_list cp;
+	struct bdaddr_list_with_irk *irk;
+	u8 entries;
+
+	BT_DBG("");
+
+	/* Nothing to be done if LL privacy is not supported */
+	if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+		return -EPROTONOSUPPORT;
+
+	/* Resolving List cannot be updated if address resolution
+	 * in the controller is enabled and advertisement or scanning
+	 * or create connection command is ongoing.
+	 */
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, · line 918

Quoted 10 lines
net/bluetooth/hci_request.c +9 -0
+	      hci_lookup_le_connect(hdev) ) )
+		return -EINVAL;
+
+	hci_req_init(&req, hdev);
+
+	irk = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr,
 type); +	if (irk) {
+		/* Device is present in resolving list.*/
+		if (memcmp(irk->peer_irk, irk_val, 16) == 0) {
+			/* Device present in resolving list with same 

IRK.

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,

Quoted 4 lines
net/bluetooth/hci_request.c +4 -0
+			 * No HCI communication is required.Sort the
+			 * Kernel list.
+			 */
+			hci_bdaddr_list_add_with_irk(&irk->list, bdaddr, 

type, irk_val, NULL);

Quoted 28 lines
net/bluetooth/hci_request.c +27 -0
+			return 0;
+
+		}
+		/* IRK has changed for the device in resolving list
+		 * Queue up commands to delete the existing entry and
+		 * add new one. Sorting will be done when command complete
+		 * for add command is receieved.
+		 */
+		goto remote;
+	}
+	/* Device is not present in resolving list.If resolving list
+	 * is not full add the device to resolving list.
+	 */
+	entries = 0;
+	list_for_each_entry(irk, &hdev->le_resolv_list, list) {
+		entries++;
+	}
+
+	if (entries < hdev->le_resolv_list_size)
+		goto add;
+
+	/* If the resolving list is full, queue up HCI command to delete
+	 * the entry that was used least recently to make space for the
+	 * new device. Kernel list will be updated when command complete
+	 * is received.
+	 */
+	irk = list_first_entry_or_null(&hdev->le_resolv_list, struct

bdaddr_list_with_irk, list); +

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, · line 952

Quoted 2 lines
net/bluetooth/hci_request.c +2 -0
+	if (!irk)
+		return -1;

I'm not sure about this... we should have some fallback mechanism when HW RL is full. Maybe some rotation of devies on list or simply disable address resolution in controller? Otherwise we won't be able to connect to some of paired devices.

Quoted 19 lines
net/bluetooth/hci_request.c +3 -0
+
+remote:
+	hci_req_del_from_resolving_list(hdev, irk->bdaddr_type, &irk-

bdaddr);

net/bluetooth/hci_request.c +12 -0
+
+add:
+	cp.bdaddr_type = type;
+	bacpy(&cp.bdaddr, bdaddr);
+	memcpy(cp.peer_irk, irk_val, 16);
+	memcpy(cp.local_irk, hdev->irk, 16);
+
+	hci_req_add(&req, HCI_OP_LE_ADD_TO_RESOLV_LIST, sizeof(cp), &cp);
+	hci_req_run(&req, NULL);
+	return 0;
+}
+
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,

bdaddr_t *bdaddr) {
struct hci_cp_le_del_from_resolv_list cp;

Signature · 2 lines
pozdrawiam
Szymon Janc
#6 lore raw

Re: [PATCH 2/7] Bluetooth: Add device to Resolving List

Hi Szymon,

Quoted 103 lines · Szymon Janc

Hi,

Quoted 56 lines · On Thursday, 12 March 2020 11:07:49 CET Sathish Narsimman wrote:

The Patch is used to add the device to resolving list. The patch will look for the local IRK list and if the device is present in the local resolving list it will be updated and the same updated w.r.t to BT controller by first deleting the existing and adding the new IRK w.r.t bd_addr.

---
 include/net/bluetooth/hci_core.h |  2 +
 net/bluetooth/hci_request.c      | 80 ++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
(quoted diff) +0 -0

b/include/net/bluetooth/hci_core.h index 5f04ef88da35..e5e09d530ce7 100644

include/net/bluetooth/hci_core.h +2 -0
@@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16
 ediv, __le64 rand,
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
                             u8 *bdaddr_type);
+int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
+                               bdaddr_t *bdaddr, u8 irk[16]);
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
                                   bdaddr_t *bdaddr);
net/bluetooth/hci_request.c +20 -0
index f4bbd3b79210..88225a9ca1f8 100644
@@ -885,6 +885,86 @@ static void hci_req_start_scan(struct hci_request *req,
 u8 type, u16 interval, }
 }
 
+int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t
 *bdaddr, +                              u8 irk_val[16])
+{
+     struct hci_request req;
+     struct hci_cp_le_add_to_resolv_list cp;
+     struct bdaddr_list_with_irk *irk;
+     u8 entries;
+
+     BT_DBG("");
+
+     /* Nothing to be done if LL privacy is not supported */
+     if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+             return -EPROTONOSUPPORT;
+
+     /* Resolving List cannot be updated if address resolution
+      * in the controller is enabled and advertisement or scanning
+      * or create connection command is ongoing.
+      */
+     if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+         ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+           hci_dev_test_flag(hdev, HCI_LE_SCAN) ||

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, · line 918

Quoted 10 lines
net/bluetooth/hci_request.c +9 -0
+           hci_lookup_le_connect(hdev) ) )
+             return -EINVAL;
+
+     hci_req_init(&req, hdev);
+
+     irk = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr,
 type); +      if (irk) {
+             /* Device is present in resolving list.*/
+             if (memcmp(irk->peer_irk, irk_val, 16) == 0) {
+                     /* Device present in resolving list with same

IRK.

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,

Quoted 4 lines
net/bluetooth/hci_request.c +4 -0
+                      * No HCI communication is required.Sort the
+                      * Kernel list.
+                      */
+                     hci_bdaddr_list_add_with_irk(&irk->list, bdaddr,

type, irk_val, NULL);

Quoted 27 lines
net/bluetooth/hci_request.c +27 -0
+                     return 0;
+
+             }
+             /* IRK has changed for the device in resolving list
+              * Queue up commands to delete the existing entry and
+              * add new one. Sorting will be done when command complete
+              * for add command is receieved.
+              */
+             goto remote;
+     }
+     /* Device is not present in resolving list.If resolving list
+      * is not full add the device to resolving list.
+      */
+     entries = 0;
+     list_for_each_entry(irk, &hdev->le_resolv_list, list) {
+             entries++;
+     }
+
+     if (entries < hdev->le_resolv_list_size)
+             goto add;
+
+     /* If the resolving list is full, queue up HCI command to delete
+      * the entry that was used least recently to make space for the
+      * new device. Kernel list will be updated when command complete
+      * is received.
+      */
+     irk = list_first_entry_or_null(&hdev->le_resolv_list, struct
Quoted 8 lines

net/bluetooth/hci_request.c static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, · line 952

Quoted 3 lines

bdaddr_list_with_irk, list); +

net/bluetooth/hci_request.c +2 -0
+     if (!irk)
+             return -1;

I'm not sure about this... we should have some fallback mechanism when HW RL is full. Maybe some rotation of devies on list or simply disable address resolution in controller? Otherwise we won't be able to connect to some of paired devices.

What I understood was
if (HW RL is full) {
don't delete the device from the kernel resolving list. delete the device from HW RL list(least used)
but we have to use a method to denote that it is deleted from HW RL list. }
from the above method at what scenario we need to add the deleted device back to the HW RL list?

And yes disabling HW RL list much simpler.

Quoted 17 lines
Quoted 17 lines
net/bluetooth/hci_request.c +3 -0
+
+remote:
+     hci_req_del_from_resolving_list(hdev, irk->bdaddr_type, &irk-

bdaddr);

net/bluetooth/hci_request.c +12 -0
+
+add:
+     cp.bdaddr_type = type;
+     bacpy(&cp.bdaddr, bdaddr);
+     memcpy(cp.peer_irk, irk_val, 16);
+     memcpy(cp.local_irk, hdev->irk, 16);
+
+     hci_req_add(&req, HCI_OP_LE_ADD_TO_RESOLV_LIST, sizeof(cp), &cp);
+     hci_req_run(&req, NULL);
+     return 0;
+}
+
Quoted 10 lines
Quoted 3 lines

void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,

bdaddr_t *bdaddr) {
      struct hci_cp_le_del_from_resolv_list cp;

--
pozdrawiam
Szymon Janc

Regards
Sathish N

#7 lore raw

PATCH 3/7 Bluetooth: Update the Resolving list when Local IRK changed

In reply to Sathish Narsimman

Whenever the Local IRK changes. i.e privacy mode is toggled this patch helps to change the IRK list in the bluetooth controller

---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_request.c      | 50 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
include/net/bluetooth/hci_core.h +2 -0
index e5e09d530ce7..43d31a9339a6 100644
@@ -1659,6 +1659,8 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
 int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
 				  bdaddr_t *bdaddr, u8 irk[16]);
+void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev);
+
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
 				     bdaddr_t *bdaddr);
 
net/bluetooth/hci_request.c +50 -0

56 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#8 lore raw

Re: [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed

Hi Sathish,

Quoted 36 lines

Whenever the Local IRK changes. i.e privacy mode is toggled this patch helps to change the IRK list in the bluetooth controller

---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_request.c | 50 ++++++++++++++++++++++++++++++++

2 files changed, 52 insertions(+)
include/net/bluetooth/hci_core.h +2 -0
index e5e09d530ce7..43d31a9339a6 100644
@@ -1659,6 +1659,8 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
 int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
 				  bdaddr_t *bdaddr, u8 irk[16]);
+void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev);
+
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
 				     bdaddr_t *bdaddr);
 
net/bluetooth/hci_request.c +4 -0
index 88225a9ca1f8..9ffb62178d24 100644
@@ -965,6 +965,56 @@ int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdadd
 	return 0;
 }
 
+void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev)
+{
+	struct bdaddr_list_with_irk *irk;
+	struct hci_request req;

net/bluetooth/hci_request.c int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdadd · line 981

Quoted 10 lines
net/bluetooth/hci_request.c +10 -0
+
+	BT_DBG("");
+
+	/* Nothing to be done if LL privacy is not supported. */
+	if (!(hdev->le_features[0] & HCI_LE_LL_PRIVACY))
+		return;
+
+	/* If resolving list is empty, nothing is to be done.*/
+	if (list_empty(&hdev->le_resolv_list))
+		return;

actually the le_resolv_list represents the current list programmed into the controller.

net/bluetooth/hci_request.c int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdadd · line 991

Quoted 10 lines
net/bluetooth/hci_request.c +10 -0
+
+	/* Resolving List cannot be updated if address resolution
+	 * in the controller is enabled and advertisement or scanning
+	 * or create connection command is ongoing.
+	 */
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+	      hci_lookup_le_connect(hdev) ) )
+		return;

Coding style needs to be correct.

Quoted 12 lines
net/bluetooth/hci_request.c +12 -0
+
+	/* If resolving list is not empty, then clear the resolving list
+	 * and add back each entry with updated local IRK.
+	 */
+	hci_req_init(&req, hdev);
+
+	list_for_each_entry(irk, &hdev->le_resolv_list, list) {
+		struct hci_cp_le_add_to_resolv_list cp;
+		struct hci_cp_le_del_from_resolv_list cp1;
+
+		cp1.bdaddr_type = irk->bdaddr_type;
+		bacpy(&cp1.bdaddr, &irk->bdaddr);

net/bluetooth/hci_request.c int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdadd · line 1013

Quoted 10 lines
net/bluetooth/hci_request.c +10 -0
+		hci_req_add(&req, HCI_OP_LE_DEL_FROM_RESOLV_LIST,
+			    sizeof(cp1), &cp1);
+
+		cp.bdaddr_type = irk->bdaddr_type;
+		bacpy(&cp.bdaddr, &irk->bdaddr);
+		memcpy(cp.peer_irk, irk->peer_irk, 16);
+		memcpy(cp.local_irk, hdev->irk, 16);
+		hci_req_add(&req, HCI_OP_LE_ADD_TO_RESOLV_LIST,
+			    sizeof(cp), &cp);
+	}

Can we please do this the smart way, no need to remove and entry to just add it back later.

Regards

Marcel

#9 lore raw

PATCH 4/7 Bluetooth: LL_PRIVACY re-load resolving list

In reply to Sathish Narsimman

The patch is used to load the entries in the local IRK to the Bluetooth LE controller resolving list.

---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_request.c      | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
index 43d31a9339a6..46d2d3e10c97 100644
@@ -1659,6 +1659,7 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
 int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
 				  bdaddr_t *bdaddr, u8 irk[16]);
+void hci_load_resolving_list(struct hci_dev *hdev);
 void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev);
 
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
net/bluetooth/hci_request.c +29 -0
index 9ffb62178d24..e17db3103a3d 100644
@@ -1015,6 +1015,35 @@ void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev)
 	hci_req_run(&req, NULL);
 }
 
+void hci_load_resolving_list (struct hci_dev *hdev)
+{
+	struct smp_irk *irk;
+	u8 num = 0;
+
+	/* Nothing to be done if LL privacy is not supported */
+	if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+		return;
+
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+	      hci_lookup_le_connect(hdev) ) )
+		return;
+
+	/* Load the first le_resolving_list_size entries from IRK
+	 * list in to resolving list.
+	 */
+	rcu_read_lock();
+	list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
+		if (num++ >= hdev->le_resolv_list_size)
+			return;
+
+		hci_req_update_resolving_list(hdev, irk->addr_type, &irk->bdaddr, irk->val);
+	}
+
+	rcu_read_unlock();
+}
+
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr)
 {
 	struct hci_cp_le_del_from_resolv_list cp;
Signature · 1 line
2.17.1
maintainer
#10 lore raw

Re: [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list

Hi Sathish,

Quoted 45 lines

The patch is used to load the entries in the local IRK to the Bluetooth LE controller resolving list.

---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_request.c | 29 +++++++++++++++++++++++++++++

2 files changed, 30 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
index 43d31a9339a6..46d2d3e10c97 100644
@@ -1659,6 +1659,7 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
 int hci_req_update_resolving_list(struct hci_dev *hdev,  u8 addr_type,
 				  bdaddr_t *bdaddr, u8 irk[16]);
+void hci_load_resolving_list(struct hci_dev *hdev);
 void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev);
 
 void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type,
net/bluetooth/hci_request.c +15 -0
index 9ffb62178d24..e17db3103a3d 100644
@@ -1015,6 +1015,35 @@ void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev)
 	hci_req_run(&req, NULL);
 }
 
+void hci_load_resolving_list (struct hci_dev *hdev)
+{
+	struct smp_irk *irk;
+	u8 num = 0;
+
+	/* Nothing to be done if LL privacy is not supported */
+	if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+		return;
+
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+	      hci_lookup_le_connect(hdev) ) )
+		return;
+

net/bluetooth/hci_request.c void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev) · line 1042

Quoted 10 lines
net/bluetooth/hci_request.c +10 -0
+	/* Load the first le_resolving_list_size entries from IRK
+	 * list in to resolving list.
+	 */
+	rcu_read_lock();
+	list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
+		if (num++ >= hdev->le_resolv_list_size)
+			return;
+
+		hci_req_update_resolving_list(hdev, irk->addr_type, &irk->bdaddr, irk->val);
+	}

I comparison to the le_whitelist, the le_resolv_list_size does not have to match the actual available memory of the controller. It is just some guesstimate. I think we have to design this in a way that we add the IRK anyway and handle the error case gracefully.

I am also confused why we are not actually checking here if an entry is already present and just loading the whole list. I have seen code being duplicated in at least 3 places now.

Regards

Marcel

#11 lore raw

PATCH 5/7 Bluetooth: LL Privacy Check and Update the Resolving List

In reply to Sathish Narsimman

This patch is an helper function which will be usefull to check the Local Resolving list and update the controller Resolving list during le_create_conn , le_directed_adv.

---
 net/bluetooth/hci_request.c | 21 +++++++++++++++++++++
 net/bluetooth/hci_request.h |  2 ++
 2 files changed, 23 insertions(+)
net/bluetooth/hci_request.c +21 -0
index e17db3103a3d..6b685cdc7de5 100644
@@ -1015,6 +1015,27 @@ void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev)
 	hci_req_run(&req, NULL);
 }
 
+void hci_req_check_and_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr)
+{
+	struct smp_irk *irk;
+
+	BT_DBG("");
+
+	/* Nothing to be done if LL privacy is not supported */
+	if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) )
+		return;
+
+	if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) &&
+	    ( hci_dev_test_flag(hdev, HCI_LE_ADV) ||
+	      hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
+	      hci_lookup_le_connect(hdev) ) )
+		return;
+
+	irk = hci_find_irk_by_addr(hdev, bdaddr, type);
+	if (irk)
+		hci_req_update_resolving_list(hdev, irk->addr_type, &irk->bdaddr, irk->val);
+}
+
 void hci_load_resolving_list (struct hci_dev *hdev)
 {
 	struct smp_irk *irk;
net/bluetooth/hci_request.h +2 -0
index 0e81614d235e..92a71f35543b 100644
@@ -90,6 +90,8 @@ void __hci_req_clear_ext_adv_sets(struct hci_request *req);
 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
 			   bool use_rpa, struct adv_info *adv_instance,
 			   u8 *own_addr_type, bdaddr_t *rand_addr);
+void hci_req_check_and_update_resolving_list(struct hci_dev *hdev, u8 addr_type,
+					     bdaddr_t *bdaddr);
 
 void __hci_req_update_class(struct hci_request *req);
 
Signature · 1 line
2.17.1
#12 lore raw

PATCH 6/7 Bluetooth: Enable LL Privacy

In reply to Sathish Narsimman

This enables Link Layer Privacy and sets RPA timeout to 900sec

< HCI Command: LE Set Address Resolution Enable (0x08|0x002d) plen 1

        Address resolution: Enabled (0x01)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

      LE Set Address Resolution Enable (0x08|0x002d) ncmd 1d
        Status: Success (0x00)

< HCI Command: LE Set Resolvable Private Address Timeout (0x08|0x002e) plen 2
Timeout: 900 seconds

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

      LE Set Resolvable Private Address Timeout (0x08|0x002e) ncmd 1
        Status: Success (0x00)

During Successfull pairing adding the information to device Resolving list

< HCI Command: LE Add Device To Resolving List (0x08|0x0027) plen 39

        Address type: Random (0x01)
        Address: D1:79:92:B1:83:DF (Static)
        Peer identity resolving key: ecc317056e5b385cda281b9c24a453e9
        Local identity resolving key: 00000000000000000000000000000000

< ACL Data TX: Handle 3585 flags 0x00 dlen 21

      SMP: Signing Information (0x0a) len 16
        Signature key: 37b6c45656c7e8b3ec8db062c3e0c2b2
Quoted 1 line

ACL Data RX: Handle 3585 flags 0x02 dlen 9

      ATT: Error Response (0x01) len 4
        Read By Group Type Request (0x10)
        Handle: 0x0001
        Error: Attribute Not Found (0x0a)
Quoted 1 line

ACL Data RX: Handle 3585 flags 0x02 dlen 11

      ATT: Read By Group Type Request (0x10) len 6
        Handle range: 0x000a-0xffff
        Attribute group type: Primary Service (0x2800)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

      LE Add Device To Resolving List (0x08|0x0027) ncmd 1
        Status: Success (0x00)
---
 include/net/bluetooth/hci.h |  2 ++
 net/bluetooth/hci_conn.c    | 32 ++++++++++++++++++++++++++++++++
 net/bluetooth/hci_core.c    | 20 +++++++++++++++++++-
 net/bluetooth/hci_event.c   | 32 +++++++++++++++++++++++++-------
 net/bluetooth/hci_request.c | 16 +++++++++++++---
 net/bluetooth/mgmt.c        | 10 +++++++++-
 net/bluetooth/smp.c         | 11 +++++++++++
 7 files changed, 111 insertions(+), 12 deletions(-)
include/net/bluetooth/hci.h +2 -0
index 352bc43940ff..d8431ebb8baa 100644
@@ -1617,6 +1617,8 @@ struct hci_rp_le_read_resolv_list_size {
 
 #define HCI_OP_LE_SET_ADDR_RESOLV_ENABLE 0x202d
 
+#define HCI_OP_LE_SET_RPA_TIMEOUT 	 0x202e
+
 #define HCI_OP_LE_READ_MAX_DATA_LEN	0x202f
 struct hci_rp_le_read_max_data_len {
 	__u8	status;
net/bluetooth/hci_conn.c +32 -0
index e245bc155cc2..06067c0852a6 100644
@@ -830,6 +830,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
 
 		plen = sizeof(*cp);
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x02)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+
 		if (scan_1m(hdev)) {
 			cp->phys |= LE_SCAN_PHY_1M;
 			set_ext_conn_params(conn, p);
@@ -866,6 +874,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
 		cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
 		cp.scan_window = cp.scan_interval;
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x02)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+
 		bacpy(&cp.peer_addr, &conn->dst);
 		cp.peer_addr_type = conn->dst_type;
 		cp.own_address_type = own_addr_type;
@@ -901,6 +917,14 @@ static void hci_req_directed_advertising(struct hci_request *req,
 					   &own_addr_type, &random_addr) < 0)
 			return;
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x03)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+
 		memset(&cp, 0, sizeof(cp));
 
 		cp.evt_properties = cpu_to_le16(LE_LEGACY_ADV_DIRECT_IND);
@@ -959,6 +983,14 @@ static void hci_req_directed_advertising(struct hci_request *req,
 					      &own_addr_type) < 0)
 			return;
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x02)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+
 		memset(&cp, 0, sizeof(cp));
 
 		/* Some controllers might reject command if intervals are not
net/bluetooth/hci_core.c +19 -1
index dbd2ad3a26ed..7727be922084 100644
@@ -713,7 +713,7 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 		/* If the controller supports the LE Extended Create Connection
 		 * command, enable the corresponding event.
 		 */
-		if (use_ext_conn(hdev))
+		if (use_ext_conn(hdev) || hdev->le_features[0] & HCI_LE_LL_PRIVACY)
 			events[1] |= 0x02;      /* LE Enhanced Connection
 						 * Complete
 						 */
@@ -762,6 +762,24 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 			hci_req_add(req, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL);
 		}
 
+		if (hdev->commands[35] & 0x02) {
+			u8 addr_resoln_enable = 0x01;
+
+			/* Enable Address Resolution in controller */
+			hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE,
+				    sizeof(addr_resoln_enable),
+				    &addr_resoln_enable);
+		}
+
+		if (hdev->commands[35] & 0x40) {
+			__le16 rpa_timeout = cpu_to_le16(hdev->rpa_timeout);
+
+			/* Set RPA timeout */
+			hci_req_add(req, HCI_OP_LE_SET_RPA_TIMEOUT, 2,
+				    &rpa_timeout);
+
+		}
+
 		if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) {
 			/* Read LE Maximum Data Length */
 			hci_req_add(req, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL);
net/bluetooth/hci_event.c +25 -7
index 20408d386268..d5ce1921fadd 100644
@@ -1684,7 +1684,11 @@ static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
 		return;
 
 	hci_dev_lock(hdev);
-	hdev->adv_addr_type = cp->own_address_type;
+
+	if (cp->own_address_type == ADDR_LE_DEV_PUBLIC)
+		hdev->adv_addr_type = ADDR_LE_DEV_PUBLIC;
+	else
+		hdev->adv_addr_type = ADDR_LE_DEV_RANDOM;
 	hci_dev_unlock(hdev);
 }
 
@@ -1704,7 +1708,12 @@ static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
 		return;
 
 	hci_dev_lock(hdev);
-	hdev->adv_addr_type = cp->own_addr_type;
+
+	if (cp->own_addr_type == ADDR_LE_DEV_PUBLIC)
+		hdev->adv_addr_type = ADDR_LE_DEV_PUBLIC;
+	else
+		hdev->adv_addr_type = ADDR_LE_DEV_RANDOM;
+
 	if (!hdev->cur_adv_instance) {
 		/* Store in hdev for instance 0 */
 		hdev->adv_tx_power = rp->tx_power;
@@ -2267,11 +2276,13 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
 	 * is needed for SMP. These values will not change during the
 	 * lifetime of the connection.
 	 */
-	conn->init_addr_type = own_address_type;
-	if (own_address_type == ADDR_LE_DEV_RANDOM)
+	if (own_address_type == 0x03 || own_address_type == 0x01) {
+		conn->init_addr_type = ADDR_LE_DEV_RANDOM;
 		bacpy(&conn->init_addr, &hdev->random_addr);
-	else
+	} else {
+		conn->init_addr_type = ADDR_LE_DEV_PUBLIC;
 		bacpy(&conn->init_addr, &hdev->bdaddr);
+	}
 
 	conn->resp_addr_type = peer_addr_type;
 	bacpy(&conn->resp_addr, peer_addr);
@@ -5141,6 +5152,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
 		}
 	}
 
+	hci_req_check_and_update_resolving_list(hdev, (conn->dst_type), &conn->dst);
+
 unlock:
 	hci_update_background_scan(hdev);
 	hci_dev_unlock(hdev);
@@ -5365,8 +5378,13 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
 		/* Only resolvable random addresses are valid for these
 		 * kind of reports and others can be ignored.
 		 */
-		if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type))
-			return;
+		if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) {
+			/* Controller with LL Privacy Supported tend to resolve
+			 * the RPA. In that case we should ignore this condition
+			 */
+			if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY))
+				return;
+		}
 
 		/* If the controller is not using resolvable random
 		 * addresses, then this report can be ignored.
net/bluetooth/hci_request.c +13 -3
index 6b685cdc7de5..12868caf50ea 100644
@@ -1916,7 +1916,12 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
 	if (use_rpa) {
 		int to;
 
-		*own_addr_type = ADDR_LE_DEV_RANDOM;
+		if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) {
+			/*if there is no resolving list used in the controller
+			 * use the bd_addr from latest Le_set_random_address*/
+			*own_addr_type = 0x03;
+		} else
+			*own_addr_type = ADDR_LE_DEV_RANDOM;
 
 		if (adv_instance) {
 			if (!adv_instance->rpa_expired &&
@@ -2074,7 +2079,7 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
 
 	hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
 
-	if (own_addr_type == ADDR_LE_DEV_RANDOM &&
+	if (((own_addr_type == ADDR_LE_DEV_RANDOM) || (own_addr_type == 0x03)) &&
 	    bacmp(&random_addr, BDADDR_ANY)) {
 		struct hci_cp_le_set_adv_set_rand_addr cp;
 
@@ -2341,7 +2346,12 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
 	if (use_rpa) {
 		int to;
 
-		*own_addr_type = ADDR_LE_DEV_RANDOM;
+		if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) {
+			/*if there is no resolving list used in the controller
+			 * use the bd_addr from latest Le_set_random_address*/
+			*own_addr_type = 0x03;
+		} else
+			*own_addr_type = ADDR_LE_DEV_RANDOM;
 
 		if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) &&
 		    !bacmp(&hdev->random_addr, &hdev->rpa))
net/bluetooth/mgmt.c +9 -1
index 6552003a170e..2b2bc011a130 100644
@@ -5084,8 +5084,10 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev,
 	if (err < 0)
 		goto unlock;
 
-	if (changed)
+	if (changed) {
 		err = new_settings(hdev, sk);
+		hci_req_update_resolving_list_local_irk(hdev);
+	}
 
 unlock:
 	hci_dev_unlock(hdev);
@@ -5227,6 +5229,8 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data,
 			    BDADDR_ANY);
 	}
 
+	/* Load the resolving list with entries from IRK list.*/
+	hci_load_resolving_list(hdev);
 	hci_dev_set_flag(hdev, HCI_RPA_RESOLVING);
 
 	err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0);
@@ -7213,6 +7217,10 @@ void mgmt_power_on(struct hci_dev *hdev, int err)
 	if (match.sk)
 		sock_put(match.sk);
 
+	/* If load _irk was called when controller was powered down,
+	 * then the resolving list has to be updated now.
+	 */
+	hci_load_resolving_list(hdev);
 	hci_dev_unlock(hdev);
 }
 
net/bluetooth/smp.c +11 -0
index 1476a91ce935..85be3f5d869a 100644
@@ -2425,6 +2425,8 @@ int smp_cancel_and_remove_pairing(struct hci_dev *hdev, bdaddr_t *bdaddr,
 	struct smp_chan *smp;
 	int err;
 
+	hci_req_del_from_resolving_list(hdev, addr_type, bdaddr);
+
 	err = hci_remove_ltk(hdev, bdaddr, addr_type);
 	hci_remove_irk(hdev, bdaddr, addr_type);
 
@@ -2619,6 +2621,15 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn,
 	smp->remote_irk = hci_add_irk(conn->hcon->hdev, &smp->id_addr,
 				      smp->id_addr_type, smp->irk, &rpa);
 
+	/* Add the device to the resolving list.*/
+	hci_req_update_resolving_list(conn->hcon->hdev,
+					      smp->remote_irk->addr_type,
+					      &smp->remote_irk->bdaddr,
+					      smp->remote_irk->val);
+
+
+	/*TODO:  Check remote device Supports LL Privacy. If not set the device
+	 * with IRK to Device-privacy Mode - Should be discussed - Based on */
 distribute:
 	if (!(smp->remote_key_dist & KEY_DIST_MASK))
 		smp_distribute_keys(smp);
Signature · 1 line
2.17.1
maintainer
#13 lore raw

Re: [PATCH 6/7] Bluetooth: Enable LL Privacy

Hi Sathish,

Quoted 69 lines

This enables Link Layer Privacy and sets RPA timeout to 900sec

< HCI Command: LE Set Address Resolution Enable (0x08|0x002d) plen 1

       Address resolution: Enabled (0x01)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

     LE Set Address Resolution Enable (0x08|0x002d) ncmd 1d
       Status: Success (0x00)

< HCI Command: LE Set Resolvable Private Address Timeout (0x08|0x002e) plen 2
Timeout: 900 seconds

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

     LE Set Resolvable Private Address Timeout (0x08|0x002e) ncmd 1
       Status: Success (0x00)

During Successfull pairing adding the information to device Resolving list

< HCI Command: LE Add Device To Resolving List (0x08|0x0027) plen 39

       Address type: Random (0x01)
       Address: D1:79:92:B1:83:DF (Static)
       Peer identity resolving key: ecc317056e5b385cda281b9c24a453e9
       Local identity resolving key: 00000000000000000000000000000000

< ACL Data TX: Handle 3585 flags 0x00 dlen 21

     SMP: Signing Information (0x0a) len 16
       Signature key: 37b6c45656c7e8b3ec8db062c3e0c2b2
Quoted 1 line

ACL Data RX: Handle 3585 flags 0x02 dlen 9

     ATT: Error Response (0x01) len 4
       Read By Group Type Request (0x10)
       Handle: 0x0001
       Error: Attribute Not Found (0x0a)
Quoted 1 line

ACL Data RX: Handle 3585 flags 0x02 dlen 11

     ATT: Read By Group Type Request (0x10) len 6
       Handle range: 0x000a-0xffff
       Attribute group type: Primary Service (0x2800)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

     LE Add Device To Resolving List (0x08|0x0027) ncmd 1
       Status: Success (0x00)

---

include/net/bluetooth/hci.h |  2 ++
net/bluetooth/hci_conn.c    | 32 ++++++++++++++++++++++++++++++++
net/bluetooth/hci_core.c    | 20 +++++++++++++++++++-
net/bluetooth/hci_event.c   | 32 +++++++++++++++++++++++++-------
net/bluetooth/hci_request.c | 16 +++++++++++++---
net/bluetooth/mgmt.c        | 10 +++++++++-
net/bluetooth/smp.c         | 11 +++++++++++
7 files changed, 111 insertions(+), 12 deletions(-)
include/net/bluetooth/hci.h +2 -0
index 352bc43940ff..d8431ebb8baa 100644
@@ -1617,6 +1617,8 @@ struct hci_rp_le_read_resolv_list_size {
 
 #define HCI_OP_LE_SET_ADDR_RESOLV_ENABLE 0x202d
 
+#define HCI_OP_LE_SET_RPA_TIMEOUT 	 0x202e
+
 #define HCI_OP_LE_READ_MAX_DATA_LEN	0x202f
 struct hci_rp_le_read_max_data_len {
 	__u8	status;
net/bluetooth/hci_conn.c +0 -0
index e245bc155cc2..06067c0852a6 100644
@@ -830,6 +830,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
 

net/bluetooth/hci_conn.c static void hci_req_add_le_create_conn(struct hci_request *req, · line 840

Quoted 10 lines
net/bluetooth/hci_conn.c +8 -0
 		plen = sizeof(*cp);
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x02)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+

I am failing to understand this part. The address should have been in the resolving list already. Either via Load Identify Resolving Keys mgmt command or from the SMP pairing. Doing that at time when calling Create Connection seems wrong. It should be independent from that.

Quoted 35 lines
net/bluetooth/hci_conn.c +16 -0
 		if (scan_1m(hdev)) {
 			cp->phys |= LE_SCAN_PHY_1M;
 			set_ext_conn_params(conn, p);
@@ -866,6 +874,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
 		cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
 		cp.scan_window = cp.scan_interval;
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x02)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+
 		bacpy(&cp.peer_addr, &conn->dst);
 		cp.peer_addr_type = conn->dst_type;
 		cp.own_address_type = own_addr_type;
@@ -901,6 +917,14 @@ static void hci_req_directed_advertising(struct hci_request *req,
 					   &own_addr_type, &random_addr) < 0)
 			return;
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x03)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+
 		memset(&cp, 0, sizeof(cp));
 
 		cp.evt_properties = cpu_to_le16(LE_LEGACY_ADV_DIRECT_IND);
@@ -959,6 +983,14 @@ static void hci_req_directed_advertising(struct hci_request *req,
 					      &own_addr_type) < 0)

net/bluetooth/hci_conn.c static void hci_req_directed_advertising(struct hci_request *req, · line 993

Quoted 10 lines
net/bluetooth/hci_conn.c +8 -0
 			return;
 
+		/* If the own_addr_type is 0x03 or 0x02 and peer is present
+		 * in Kernel IRK list, but not in resolving add the peer to
+		 * the resolving list.
+		 */
+		if (own_addr_type == 0x03 || own_addr_type == 0x02)
+			hci_req_check_and_update_resolving_list(hdev, conn->dst_type,
+								&conn->dst);
+

We just keep repeating this code. It doesn’t look right.

Quoted 8 lines
net/bluetooth/hci_conn.c +0 -0
 		memset(&cp, 0, sizeof(cp));
 
 		/* Some controllers might reject command if intervals are not
net/bluetooth/hci_core.c +0 -0
index dbd2ad3a26ed..7727be922084 100644

net/bluetooth/hci_core.c static int hci_init3_req(struct hci_request *req, unsigned long opt) · line 719

Quoted 8 lines
net/bluetooth/hci_core.c +1 -1
@@ -713,7 +713,7 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 		/* If the controller supports the LE Extended Create Connection
 		 * command, enable the corresponding event.
 		 */
-		if (use_ext_conn(hdev))
+		if (use_ext_conn(hdev) || hdev->le_features[0] & HCI_LE_LL_PRIVACY)
 			events[1] |= 0x02;      /* LE Enhanced Connection
 						 * Complete
 						 */

I do not get this change.

net/bluetooth/hci_core.c static int hci_init3_req(struct hci_request *req, unsigned long opt) · line 766

Quoted 6 lines
net/bluetooth/hci_core.c +2 -0
@@ -762,6 +762,24 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 			hci_req_add(req, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL);
 		}
 
+		if (hdev->commands[35] & 0x02) {
+			u8 addr_resoln_enable = 0x01;

I don’t know what resoln is suppose to stand for.

Quoted 6 lines
net/bluetooth/hci_core.c +6 -0
+
+			/* Enable Address Resolution in controller */
+			hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE,
+				    sizeof(addr_resoln_enable),
+				    &addr_resoln_enable);
+		}

net/bluetooth/hci_core.c static int hci_init3_req(struct hci_request *req, unsigned long opt) · line 782

Quoted 10 lines
net/bluetooth/hci_core.c +10 -0
+
+		if (hdev->commands[35] & 0x40) {
+			__le16 rpa_timeout = cpu_to_le16(hdev->rpa_timeout);
+
+			/* Set RPA timeout */
+			hci_req_add(req, HCI_OP_LE_SET_RPA_TIMEOUT, 2,
+				    &rpa_timeout);
+
+		}
+

I think you should be adding RPA timeout handling in a separate patch. It is also important to note that there is a debugfs setting that should be capable of changing this value at runtime.

Quoted 8 lines
net/bluetooth/hci_core.c +0 -0
 		if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) {
 			/* Read LE Maximum Data Length */
 			hci_req_add(req, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL);
net/bluetooth/hci_event.c +0 -0
index 20408d386268..d5ce1921fadd 100644

net/bluetooth/hci_event.c static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) · line 1691

Quoted 9 lines
net/bluetooth/hci_event.c +5 -1
@@ -1684,7 +1684,11 @@ static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
 		return;
 
 	hci_dev_lock(hdev);
-	hdev->adv_addr_type = cp->own_address_type;
+
+	if (cp->own_address_type == ADDR_LE_DEV_PUBLIC)
+		hdev->adv_addr_type = ADDR_LE_DEV_PUBLIC;
+	else
+		hdev->adv_addr_type = ADDR_LE_DEV_RANDOM;

I don’t get this change.

Quoted 4 lines
net/bluetooth/hci_event.c +0 -0
 	hci_dev_unlock(hdev);
 }
 

net/bluetooth/hci_event.c static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb) · line 1716

Quoted 10 lines
net/bluetooth/hci_event.c +6 -1
@@ -1704,7 +1708,12 @@ static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
 		return;
 
 	hci_dev_lock(hdev);
-	hdev->adv_addr_type = cp->own_addr_type;
+
+	if (cp->own_addr_type == ADDR_LE_DEV_PUBLIC)
+		hdev->adv_addr_type = ADDR_LE_DEV_PUBLIC;
+	else
+		hdev->adv_addr_type = ADDR_LE_DEV_RANDOM;
+

Same as above. I fail to see why this is important.

Quoted 7 lines
net/bluetooth/hci_event.c +0 -0
 	if (!hdev->cur_adv_instance) {
 		/* Store in hdev for instance 0 */
 		hdev->adv_tx_power = rp->tx_power;
@@ -2267,11 +2276,13 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
 	 * is needed for SMP. These values will not change during the
 	 * lifetime of the connection.
 	 */

net/bluetooth/hci_event.c static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, · line 2285

Quoted 10 lines
net/bluetooth/hci_event.c +5 -3
-	conn->init_addr_type = own_address_type;
-	if (own_address_type == ADDR_LE_DEV_RANDOM)
+	if (own_address_type == 0x03 || own_address_type == 0x01) {
+		conn->init_addr_type = ADDR_LE_DEV_RANDOM;
 		bacpy(&conn->init_addr, &hdev->random_addr);
-	else
+	} else {
+		conn->init_addr_type = ADDR_LE_DEV_PUBLIC;
 		bacpy(&conn->init_addr, &hdev->bdaddr);
+	}

This requires an appropriate comment change as well.

Quoted 14 lines
net/bluetooth/hci_event.c +2 -0
 	conn->resp_addr_type = peer_addr_type;
 	bacpy(&conn->resp_addr, peer_addr);
@@ -5141,6 +5152,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
 		}
 	}
 
+	hci_req_check_and_update_resolving_list(hdev, (conn->dst_type), &conn->dst);
+

unlock:

	hci_update_background_scan(hdev);
	hci_dev_unlock(hdev);
net/bluetooth/hci_event.c +0 -0
@@ -5365,8 +5378,13 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
 		/* Only resolvable random addresses are valid for these

net/bluetooth/hci_event.c static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, · line 5386

Quoted 10 lines
net/bluetooth/hci_event.c +6 -2
 		 * kind of reports and others can be ignored.
 		 */
-		if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type))
-			return;
+		if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) {
+			/* Controller with LL Privacy Supported tend to resolve
+			 * the RPA. In that case we should ignore this condition
+			 */
+			if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY))
+				return;

Please obey the coding style.

And just checking the existence of feature bit is not enough. We also need to check that the feature is active and actually used in this case.

Quoted 9 lines
net/bluetooth/hci_event.c +1 -0
+		}
 
 		/* If the controller is not using resolvable random
 		 * addresses, then this report can be ignored.
net/bluetooth/hci_request.c +0 -0
index 6b685cdc7de5..12868caf50ea 100644

net/bluetooth/hci_request.c int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, · line 1924

Quoted 10 lines
net/bluetooth/hci_request.c +6 -1
@@ -1916,7 +1916,12 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
 	if (use_rpa) {
 		int to;
 
-		*own_addr_type = ADDR_LE_DEV_RANDOM;
+		if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) {
+			/*if there is no resolving list used in the controller
+			 * use the bd_addr from latest Le_set_random_address*/
+			*own_addr_type = 0x03;
+		} else
+			*own_addr_type = ADDR_LE_DEV_RANDOM;

I really don’t see how this is going to work. Local privacy can off and maybe remote device don’t use privacy. As noted above the le_features bit is not an indicate if LL Privacy is in use.

In addition, please get the coding style right.

net/bluetooth/hci_request.c int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) · line 2082

Quoted 9 lines
net/bluetooth/hci_request.c +1 -1
 		if (adv_instance) {
 			if (!adv_instance->rpa_expired &&
@@ -2074,7 +2079,7 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
 
 	hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
 
-	if (own_addr_type == ADDR_LE_DEV_RANDOM &&
+	if (((own_addr_type == ADDR_LE_DEV_RANDOM) || (own_addr_type == 0x03)) &&

The extra (x == y) are not needed and it might be a good idea to introduce constants for 0x02 and 0x03 early on.

Quoted 4 lines
net/bluetooth/hci_request.c +0 -0
 	    bacmp(&random_addr, BDADDR_ANY)) {
 		struct hci_cp_le_set_adv_set_rand_addr cp;
 

net/bluetooth/hci_request.c int hci_update_random_address(struct hci_request *req, bool require_privacy, · line 2354

Quoted 10 lines
net/bluetooth/hci_request.c +6 -1
@@ -2341,7 +2346,12 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
 	if (use_rpa) {
 		int to;
 
-		*own_addr_type = ADDR_LE_DEV_RANDOM;
+		if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) {
+			/*if there is no resolving list used in the controller
+			 * use the bd_addr from latest Le_set_random_address*/
+			*own_addr_type = 0x03;
+		} else
+			*own_addr_type = ADDR_LE_DEV_RANDOM;

I really need to stop reviewing patches where the coding style mistakes are this many.

Quoted 55 lines
net/bluetooth/hci_request.c +0 -0
 		if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) &&
 		    !bacmp(&hdev->random_addr, &hdev->rpa))
net/bluetooth/mgmt.c +3 -1
index 6552003a170e..2b2bc011a130 100644
@@ -5084,8 +5084,10 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev,
 	if (err < 0)
 		goto unlock;
 
-	if (changed)
+	if (changed) {
 		err = new_settings(hdev, sk);
+		hci_req_update_resolving_list_local_irk(hdev);
+	}
 

unlock:

	hci_dev_unlock(hdev);
net/bluetooth/mgmt.c +6 -0
@@ -5227,6 +5229,8 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data,
 			    BDADDR_ANY);
 	}
 
+	/* Load the resolving list with entries from IRK list.*/
+	hci_load_resolving_list(hdev);
 	hci_dev_set_flag(hdev, HCI_RPA_RESOLVING);
 
 	err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0);
@@ -7213,6 +7217,10 @@ void mgmt_power_on(struct hci_dev *hdev, int err)
 	if (match.sk)
 		sock_put(match.sk);
 
+	/* If load _irk was called when controller was powered down,
+	 * then the resolving list has to be updated now.
+	 */
+	hci_load_resolving_list(hdev);
 	hci_dev_unlock(hdev);
 }
 
net/bluetooth/smp.c +2 -0
index 1476a91ce935..85be3f5d869a 100644
@@ -2425,6 +2425,8 @@ int smp_cancel_and_remove_pairing(struct hci_dev *hdev, bdaddr_t *bdaddr,
 	struct smp_chan *smp;
 	int err;
 
+	hci_req_del_from_resolving_list(hdev, addr_type, bdaddr);
+
 	err = hci_remove_ltk(hdev, bdaddr, addr_type);
 	hci_remove_irk(hdev, bdaddr, addr_type);
 
@@ -2619,6 +2621,15 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn,
 	smp->remote_irk = hci_add_irk(conn->hcon->hdev, &smp->id_addr,
 				      smp->id_addr_type, smp->irk, &rpa);

net/bluetooth/smp.c static int smp_cmd_ident_addr_info(struct l2cap_conn *conn, · line 2632

Quoted 10 lines
net/bluetooth/smp.c +9 -0
 
+	/* Add the device to the resolving list.*/
+	hci_req_update_resolving_list(conn->hcon->hdev,
+					      smp->remote_irk->addr_type,
+					      &smp->remote_irk->bdaddr,
+					      smp->remote_irk->val);
+
+
+	/*TODO:  Check remote device Supports LL Privacy. If not set the device
+	 * with IRK to Device-privacy Mode - Should be discussed - Based on */

I rather have this fixed instead of keeping a TODO in here.

Quoted 3 lines

distribute:

	if (!(smp->remote_key_dist & KEY_DIST_MASK))
		smp_distribute_keys(smp);

Regards

Marcel

#14 lore raw

PATCH 7/7 Bluetooth LL Privacy update White list

In reply to Sathish Narsimman

Update white list filter policy of if LL Privacy is enabled When Address Resolution is enabled and device is already in the white list then follow the filter policy

---
 net/bluetooth/hci_request.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
net/bluetooth/hci_request.c +20 -2
index 12868caf50ea..47cb2602713a 100644
@@ -711,7 +711,16 @@ static int add_to_white_list(struct hci_request *req,
 	/* White list can not be used with RPAs */
 	if (!allow_rpa &&
 	    hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
-		return -1;
+		/* White list can not be used with RPAs if address
+		 * resolution is disabled in the controller
+		 */
+		if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
+			return -1;
+
+		/* if  the peer device is not present in the resolving list */
+		if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
+						     b->bdaddr_type))
+			return -1;
 	}
 
 	/* During suspend, only wakeable devices can be in whitelist */
@@ -768,7 +777,16 @@ static u8 update_white_list(struct hci_request *req)
 		/* White list can not be used with RPAs */
 		if (!allow_rpa &&
 		    hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) {
-			return 0x00;
+			/* White list can not be used with RPAs if address
+			 * resolution is disabled in the controller
+			 */
+			if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
+				return 0x00;
+
+			/* if  the peer device is not present in the resolving list */
+			if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
+							     b->bdaddr_type))
+				return 0x00;
 		}
 
 		num_entries++;
Signature · 1 line
2.17.1
#15 lore raw

Re: [PATCH 7/7] Bluetooth LL Privacy update White list

Thank you for the patch! Yet something to improve:

Hi Sathish,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on next-20200312]
[cannot apply to v5.6-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Sathish-Narsimman/LE-LL-Priavcy-support-enabled/20200313-033706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: parisc-allyesconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=parisc

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

net//bluetooth/hci_request.c: In function 'add_to_white_list':

>> net//bluetooth/hci_request.c:721:64: error: 'b' undeclared (first use in this function); did you mean 'mb'?
     721 |   if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
         |                                                                ^
         |                                                                mb

net//bluetooth/hci_request.c:721:64: note: each undeclared identifier is reported only once for each function it appears in

vim +721 net//bluetooth/hci_request.c

693
694 /* Adds connection to white list if needed. On error, returns -1. */
695 static int add_to_white_list(struct hci_request *req,
696 struct hci_conn_params *params, u8 *num_entries,
697 bool allow_rpa)
698 {
699 struct hci_cp_le_add_to_white_list cp;
700 struct hci_dev *hdev = req->hdev;
701
702 /* Already in white list */
703 if (hci_bdaddr_list_lookup(&hdev->le_white_list, &params->addr,
704 params->addr_type))
705 return 0;
706
707 /* Select filter policy to accept all advertising */
708 if (*num_entries >= hdev->le_white_list_size)
709 return -1;
710
711 /* White list can not be used with RPAs */
712 if (!allow_rpa &&
713 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
714 /* White list can not be used with RPAs if address
715 * resolution is disabled in the controller
716 */
717 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
718 return -1;
719
720 /* if the peer device is not present in the resolving list */

 > 721			if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,

722 b->bdaddr_type))
723 return -1;
724 }
725
726 /* During suspend, only wakeable devices can be in whitelist */
727 if (hdev->suspended && !params->wakeable)
728 return 0;
729
730 *num_entries += 1;
731 cp.bdaddr_type = params->addr_type;
732 bacpy(&cp.bdaddr, &params->addr);
733
734 bt_dev_dbg(hdev, "Add %pMR (0x%x) to whitelist", &cp.bdaddr,
735 cp.bdaddr_type);
736 hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);
737
738 return 0;
739 }
740

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#16 lore raw

Re: [PATCH 7/7] Bluetooth LL Privacy update White list

In reply to Sathish Narsimman
Thank you for the patch! Yet something to improve:

Hi Sathish,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on next-20200312]
[cannot apply to bluetooth/master v5.6-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Sathish-Narsimman/LE-LL-Priavcy-support-enabled/20200313-033706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: x86_64-randconfig-s0-20200313 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

net//bluetooth/hci_request.c: In function 'add_to_white_list':

>> net//bluetooth/hci_request.c:721:64: error: 'b' undeclared (first use in this function)
      if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
                                                                   ^

net//bluetooth/hci_request.c:721:64: note: each undeclared identifier is reported only once for each function it appears in

vim +/b +721 net//bluetooth/hci_request.c

693
694 /* Adds connection to white list if needed. On error, returns -1. */
695 static int add_to_white_list(struct hci_request *req,
696 struct hci_conn_params *params, u8 *num_entries,
697 bool allow_rpa)
698 {
699 struct hci_cp_le_add_to_white_list cp;
700 struct hci_dev *hdev = req->hdev;
701
702 /* Already in white list */
703 if (hci_bdaddr_list_lookup(&hdev->le_white_list, &params->addr,
704 params->addr_type))
705 return 0;
706
707 /* Select filter policy to accept all advertising */
708 if (*num_entries >= hdev->le_white_list_size)
709 return -1;
710
711 /* White list can not be used with RPAs */
712 if (!allow_rpa &&
713 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
714 /* White list can not be used with RPAs if address
715 * resolution is disabled in the controller
716 */
717 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
718 return -1;
719
720 /* if the peer device is not present in the resolving list */

 > 721			if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,

722 b->bdaddr_type))
723 return -1;
724 }
725
726 /* During suspend, only wakeable devices can be in whitelist */
727 if (hdev->suspended && !params->wakeable)
728 return 0;
729
730 *num_entries += 1;
731 cp.bdaddr_type = params->addr_type;
732 bacpy(&cp.bdaddr, &params->addr);
733
734 bt_dev_dbg(hdev, "Add %pMR (0x%x) to whitelist", &cp.bdaddr,
735 cp.bdaddr_type);
736 hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);
737
738 return 0;
739 }
740

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#17 lore raw

Re: [PATCH 7/7] Bluetooth LL Privacy update White list

In reply to Sathish Narsimman
Thank you for the patch! Perhaps something to improve:

Hi Sathish,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on next-20200312]
[cannot apply to bluetooth/master v5.6-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Sathish-Narsimman/LE-LL-Priavcy-support-enabled/20200313-033706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: i386-randconfig-d001-20200312 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-5) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from include/linux/export.h:43:0,
from include/linux/linkage.h:7,
from include/linux/kernel.h:8,
from include/linux/list.h:9,
from include/linux/rculist.h:10,
from include/linux/sched/signal.h:5,
from net/bluetooth/hci_request.c:24:
net/bluetooth/hci_request.c: In function 'add_to_white_list':
net/bluetooth/hci_request.c:721:64: error: 'b' undeclared (first use in this function); did you mean 'mb'?

      if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
                                                                   ^
   include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                       ^~~~
>> net/bluetooth/hci_request.c:721:3: note: in expansion of macro 'if'
      if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
      ^~
   net/bluetooth/hci_request.c:721:64: note: each undeclared identifier is reported only once for each function it appears in
      if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
                                                                   ^
   include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                       ^~~~
>> net/bluetooth/hci_request.c:721:3: note: in expansion of macro 'if'
      if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,
      ^~

vim +/if +721 net/bluetooth/hci_request.c

693
694 /* Adds connection to white list if needed. On error, returns -1. */
695 static int add_to_white_list(struct hci_request *req,
696 struct hci_conn_params *params, u8 *num_entries,
697 bool allow_rpa)
698 {
699 struct hci_cp_le_add_to_white_list cp;
700 struct hci_dev *hdev = req->hdev;
701
702 /* Already in white list */
703 if (hci_bdaddr_list_lookup(&hdev->le_white_list, &params->addr,
704 params->addr_type))
705 return 0;
706
707 /* Select filter policy to accept all advertising */
708 if (*num_entries >= hdev->le_white_list_size)
709 return -1;
710
711 /* White list can not be used with RPAs */
712 if (!allow_rpa &&
713 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
714 /* White list can not be used with RPAs if address
715 * resolution is disabled in the controller
716 */
717 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
718 return -1;
719
720 /* if the peer device is not present in the resolving list */

 > 721			if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr,

722 b->bdaddr_type))
723 return -1;
724 }
725
726 /* During suspend, only wakeable devices can be in whitelist */
727 if (hdev->suspended && !params->wakeable)
728 return 0;
729
730 *num_entries += 1;
731 cp.bdaddr_type = params->addr_type;
732 bacpy(&cp.bdaddr, &params->addr);
733
734 bt_dev_dbg(hdev, "Add %pMR (0x%x) to whitelist", &cp.bdaddr,
735 cp.bdaddr_type);
736 hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);
737
738 return 0;
739 }
740

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#18 lore raw
In reply to Sathish Narsimman

Hi

A gentle reminder to review the patches

Quoted 38 lines · Sathish Narsimman

With this LE LL Priavcy feature available if BT controller supports LL Privacy when privacy is enabled.

The patches are verified in below case.
Pairing - where the IRK is added to device Resolving List after identity info & IRK is shared in SMP.
Unpair - Delete the resolving entry from the Device resolving list Local IRK change - Whenever there is change in local IRK (privacy) the resolving list entries in the device is updated.
Whitelist - filter policies for whitelist is updated based on LL_adress resolution support.
Reload Resolving list - device reset/sysmte reboot the Resolving list reloaded in to the device.

Sathish Narsimman (7):
Bluetooth: LL Privacy Delete Store Resolving list
Bluetooth: Add device to Resolving List
Bluetooth: Update the Resolving list when Local IRK changed
Bluetooth: LL_PRIVACY re-load resolving list
Bluetooth: LL Privacy Check and Update the Resolving List
Bluetooth: Enable LL Privacy
Bluetooth LL Privacy update White list

 include/net/bluetooth/hci.h      |   3 +
 include/net/bluetooth/hci_core.h |   7 +
 net/bluetooth/hci_conn.c         |  32 ++++
 net/bluetooth/hci_core.c         |  20 ++-
 net/bluetooth/hci_event.c        |  32 +++-
 net/bluetooth/hci_request.c      | 251 ++++++++++++++++++++++++++++++-
 net/bluetooth/hci_request.h      |   2 +
 net/bluetooth/mgmt.c             |  10 +-
 net/bluetooth/smp.c              |  11 ++
 9 files changed, 354 insertions(+), 14 deletions(-)

--
2.17.1

#19 lore raw

Hi Satish,

Looking through the patches in this series, it looks like you are adding the IRK for all connected devices and I'm not sure that's the best method.
The resolv list seems to be useful in the same way as the le
whitelist: to filter incoming advertisements for devices we care about.

Thus, to simplify your design, could we not do the same thing as the le whitelist:
* Update the resolv list anytime passive/background scan is being enabled
* Only keep entries in the resolv list that are part of the pend_le_conn or pend_le_report lists

Then, you would only need to update the resolv list in hci_req_add_le_passive_scan and any IRK changes would just disable passive scan, remove IRKs if existing and re-enable passive scan (which would add it back with the new one).

Thanks,
Abhishek

Quoted 44 lines · Sathish Narasimman

Hi

A gentle reminder to review the patches

Quoted 38 lines · Sathish Narsimman

With this LE LL Priavcy feature available if BT controller supports LL Privacy when privacy is enabled.

The patches are verified in below case.
Pairing - where the IRK is added to device Resolving List after identity info & IRK is shared in SMP.
Unpair - Delete the resolving entry from the Device resolving list Local IRK change - Whenever there is change in local IRK (privacy) the resolving list entries in the device is updated.
Whitelist - filter policies for whitelist is updated based on LL_adress resolution support.
Reload Resolving list - device reset/sysmte reboot the Resolving list reloaded in to the device.

Sathish Narsimman (7):
Bluetooth: LL Privacy Delete Store Resolving list
Bluetooth: Add device to Resolving List
Bluetooth: Update the Resolving list when Local IRK changed
Bluetooth: LL_PRIVACY re-load resolving list
Bluetooth: LL Privacy Check and Update the Resolving List
Bluetooth: Enable LL Privacy
Bluetooth LL Privacy update White list

 include/net/bluetooth/hci.h      |   3 +
 include/net/bluetooth/hci_core.h |   7 +
 net/bluetooth/hci_conn.c         |  32 ++++
 net/bluetooth/hci_core.c         |  20 ++-
 net/bluetooth/hci_event.c        |  32 +++-
 net/bluetooth/hci_request.c      | 251 ++++++++++++++++++++++++++++++-
 net/bluetooth/hci_request.h      |   2 +
 net/bluetooth/mgmt.c             |  10 +-
 net/bluetooth/smp.c              |  11 ++
 9 files changed, 354 insertions(+), 14 deletions(-)

--
2.17.1

maintainer
#20 lore raw

Hi Abhishek,

Quoted 13 lines

Looking through the patches in this series, it looks like you are adding the IRK for all connected devices and I'm not sure that's the best method.
The resolv list seems to be useful in the same way as the le
whitelist: to filter incoming advertisements for devices we care about.

Thus, to simplify your design, could we not do the same thing as the le whitelist:
* Update the resolv list anytime passive/background scan is being enabled
* Only keep entries in the resolv list that are part of the pend_le_conn or pend_le_report lists

Quoted 4 lines

Then, you would only need to update the resolv list in hci_req_add_le_passive_scan and any IRK changes would just disable passive scan, remove IRKs if existing and re-enable passive scan (which would add it back with the new one).

so I have been looking at this again and yes, we should just put IRKs in the resolving list for devices that we also put in the whitelist. And we only use the whitelist for background scanning.

This means I would only focus on enabling background scanning. For everything else, we can just let the host do the resolving.

	Enable passive scanning
		-> Enable resolving list if privacy device in whitelist
		-> Set Scan Parameters
		-> Set Scan Enable

	Disable passive scanning
		-> Set Scan Disable
		-> Disable resolving list if enabled

And when updating the whitelist, also add update the resolving list with needed entries for the whitelist. This means if the privacy enabled device goes into the whitelist, add the IRK to the resolving list. Remove all no longer needed IRKs.

Regards

Marcel