All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] LE LL Priavcy support enabled
@ 2020-03-12 10:07 Sathish Narsimman
  2020-03-12 10:07 ` [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list Sathish Narsimman
                   ` (7 more replies)
  0 siblings, 8 replies; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41; +Cc: chethan.tumkur.narayan, 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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-18 10:42   ` Marcel Holtmann
  2020-03-12 10:07 ` [PATCH 2/7] Bluetooth: Add device to Resolving List Sathish Narsimman
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41; +Cc: chethan.tumkur.narayan, Sathish Narsimman

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

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
---
 include/net/bluetooth/hci.h      |  1 +
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_request.c      | 33 ++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 5f60e135aeb6..352bc43940ff 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -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
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d4e28773d378..5f04ef88da35 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index bf83179ab9d1..f4bbd3b79210 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 2/7] Bluetooth: Add device to Resolving List
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
  2020-03-12 10:07 ` [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-18  9:29   ` Szymon Janc
  2020-03-12 10:07 ` [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed Sathish Narsimman
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41
  Cc: chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

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.

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
Signed-off-by: Joy Shermin <shermin.joy@intel.com>
---
 include/net/bluetooth/hci_core.h |  2 +
 net/bluetooth/hci_request.c      | 80 ++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 5f04ef88da35..e5e09d530ce7 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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);
 
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index f4bbd3b79210..88225a9ca1f8 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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) ||
+	      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.
+			 * No HCI communication is required.Sort the
+			 * Kernel list.
+			 */
+			hci_bdaddr_list_add_with_irk(&irk->list, bdaddr, type, irk_val, NULL);
+			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);
+
+	if (!irk)
+		return -1;
+
+remote:
+	hci_req_del_from_resolving_list(hdev, irk->bdaddr_type, &irk->bdaddr);
+
+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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
  2020-03-12 10:07 ` [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list Sathish Narsimman
  2020-03-12 10:07 ` [PATCH 2/7] Bluetooth: Add device to Resolving List Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-18 10:45   ` Marcel Holtmann
  2020-03-12 10:07 ` [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list Sathish Narsimman
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41
  Cc: chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

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

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
Signed-off-by: Joy Shermin <shermin.joy@intel.com>
---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_request.c      | 50 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index e5e09d530ce7..43d31a9339a6 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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);
 
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 88225a9ca1f8..9ffb62178d24 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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;
+
+	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;
+
+	/* 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;
+
+	/* 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);
+		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);
+	}
+
+	hci_req_run(&req, NULL);
+}
+
 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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
                   ` (2 preceding siblings ...)
  2020-03-12 10:07 ` [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-18 11:06   ` Marcel Holtmann
  2020-03-12 10:07 ` [PATCH 5/7] Bluetooth: LL Privacy Check and Update the Resolving List Sathish Narsimman
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41
  Cc: chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

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

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
Signed-off-by: Joy Shermin <shermin.joy@intel.com>
---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_request.c      | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 43d31a9339a6..46d2d3e10c97 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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,
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 9ffb62178d24..e17db3103a3d 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 5/7] Bluetooth: LL Privacy Check and Update the Resolving List
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
                   ` (3 preceding siblings ...)
  2020-03-12 10:07 ` [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-12 10:07 ` [PATCH 6/7] Bluetooth: Enable LL Privacy Sathish Narsimman
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41
  Cc: chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

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.

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
Signed-off-by: Joy Shermin <shermin.joy@intel.com>
---
 net/bluetooth/hci_request.c | 21 +++++++++++++++++++++
 net/bluetooth/hci_request.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index e17db3103a3d..6b685cdc7de5 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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;
diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h
index 0e81614d235e..92a71f35543b 100644
--- a/net/bluetooth/hci_request.h
+++ b/net/bluetooth/hci_request.h
@@ -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);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 6/7] Bluetooth: Enable LL Privacy
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
                   ` (4 preceding siblings ...)
  2020-03-12 10:07 ` [PATCH 5/7] Bluetooth: LL Privacy Check and Update the Resolving List Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-18 11:04   ` Marcel Holtmann
  2020-03-12 10:07 ` [PATCH 7/7] Bluetooth LL Privacy update White list Sathish Narsimman
  2020-03-18  8:56 ` [PATCH 0/7] LE LL Priavcy support enabled Sathish Narasimman
  7 siblings, 1 reply; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41; +Cc: chethan.tumkur.narayan, 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)
> 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
> 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
> 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)
> 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)

> HCI Event: Command Complete (0x0e) plen 4
      LE Add Device To Resolving List (0x08|0x0027) ncmd 1
        Status: Success (0x00)

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
---
 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(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 352bc43940ff..d8431ebb8baa 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -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;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index e245bc155cc2..06067c0852a6 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -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
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index dbd2ad3a26ed..7727be922084 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 20408d386268..d5ce1921fadd 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -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.
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 6b685cdc7de5..12868caf50ea 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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))
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 6552003a170e..2b2bc011a130 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -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);
 }
 
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 1476a91ce935..85be3f5d869a 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 7/7] Bluetooth LL Privacy update White list
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
                   ` (5 preceding siblings ...)
  2020-03-12 10:07 ` [PATCH 6/7] Bluetooth: Enable LL Privacy Sathish Narsimman
@ 2020-03-12 10:07 ` Sathish Narsimman
  2020-03-12 22:02   ` kbuild test robot
                     ` (2 more replies)
  2020-03-18  8:56 ` [PATCH 0/7] LE LL Priavcy support enabled Sathish Narasimman
  7 siblings, 3 replies; 21+ messages in thread
From: Sathish Narsimman @ 2020-03-12 10:07 UTC (permalink / raw)
  To: linux-bluetooth, nsathish41; +Cc: chethan.tumkur.narayan, 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

Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
---
 net/bluetooth/hci_request.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 12868caf50ea..47cb2602713a 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -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++;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH 7/7] Bluetooth LL Privacy update White list
  2020-03-12 10:07 ` [PATCH 7/7] Bluetooth LL Privacy update White list Sathish Narsimman
@ 2020-03-12 22:02   ` kbuild test robot
  2020-03-12 23:23   ` kbuild test robot
  2020-03-12 23:44   ` kbuild test robot
  2 siblings, 0 replies; 21+ messages in thread
From: kbuild test robot @ 2020-03-12 22:02 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3628 bytes --]

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
Reported-by: kbuild test robot <lkp@intel.com>

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 59437 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 7/7] Bluetooth LL Privacy update White list
  2020-03-12 10:07 ` [PATCH 7/7] Bluetooth LL Privacy update White list Sathish Narsimman
  2020-03-12 22:02   ` kbuild test robot
@ 2020-03-12 23:23   ` kbuild test robot
  2020-03-12 23:44   ` kbuild test robot
  2 siblings, 0 replies; 21+ messages in thread
From: kbuild test robot @ 2020-03-12 23:23 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3400 bytes --]

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
Reported-by: kbuild test robot <lkp@intel.com>

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 38353 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 7/7] Bluetooth LL Privacy update White list
  2020-03-12 10:07 ` [PATCH 7/7] Bluetooth LL Privacy update White list Sathish Narsimman
  2020-03-12 22:02   ` kbuild test robot
  2020-03-12 23:23   ` kbuild test robot
@ 2020-03-12 23:44   ` kbuild test robot
  2 siblings, 0 replies; 21+ messages in thread
From: kbuild test robot @ 2020-03-12 23:44 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4739 bytes --]

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
Reported-by: kbuild test robot <lkp@intel.com>

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 27406 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] LE LL Priavcy support enabled
  2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
                   ` (6 preceding siblings ...)
  2020-03-12 10:07 ` [PATCH 7/7] Bluetooth LL Privacy update White list Sathish Narsimman
@ 2020-03-18  8:56 ` Sathish Narasimman
  2020-04-01 20:04   ` Abhishek Pandit-Subedi
  7 siblings, 1 reply; 21+ messages in thread
From: Sathish Narasimman @ 2020-03-18  8:56 UTC (permalink / raw)
  To: Bluez mailing list, Sathish N; +Cc: Chethan T N, Sathish Narsimman

Hi

A gentle reminder to review the patches

On Thu, Mar 12, 2020 at 3:36 PM Sathish Narsimman <nsathish41@gmail.com> wrote:
>
> 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
>

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] Bluetooth: Add device to Resolving List
  2020-03-12 10:07 ` [PATCH 2/7] Bluetooth: Add device to Resolving List Sathish Narsimman
@ 2020-03-18  9:29   ` Szymon Janc
  2020-03-18 10:29     ` Sathish Narasimman
  0 siblings, 1 reply; 21+ messages in thread
From: Szymon Janc @ 2020-03-18  9:29 UTC (permalink / raw)
  To: Sathish Narsimman
  Cc: linux-bluetooth, chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

Hi,

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.
> 
> Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> Signed-off-by: Joy Shermin <shermin.joy@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |  2 +
>  net/bluetooth/hci_request.c      | 80 ++++++++++++++++++++++++++++++++
>  2 files changed, 82 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h
> b/include/net/bluetooth/hci_core.h index 5f04ef88da35..e5e09d530ce7 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -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);
> 
> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> index f4bbd3b79210..88225a9ca1f8 100644
> --- a/net/bluetooth/hci_request.c
> +++ b/net/bluetooth/hci_request.c
> @@ -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) ||
> +	      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.
> +			 * No HCI communication is required.Sort the
> +			 * Kernel list.
> +			 */
> +			hci_bdaddr_list_add_with_irk(&irk->list, bdaddr, 
type, irk_val, NULL);
> +			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); +
> +	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.

> +
> +remote:
> +	hci_req_del_from_resolving_list(hdev, irk->bdaddr_type, &irk-
>bdaddr);
> +
> +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;


-- 
pozdrawiam
Szymon Janc



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] Bluetooth: Add device to Resolving List
  2020-03-18  9:29   ` Szymon Janc
@ 2020-03-18 10:29     ` Sathish Narasimman
  0 siblings, 0 replies; 21+ messages in thread
From: Sathish Narasimman @ 2020-03-18 10:29 UTC (permalink / raw)
  To: Szymon Janc
  Cc: Bluez mailing list, Chethan T N, Sathish Narsimman, Joy Shermin

Hi Szymon,

On Wed, Mar 18, 2020 at 3:00 PM Szymon Janc <szymon.janc@codecoup.pl> wrote:
>
> Hi,
>
> 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.
> >
> > Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> > Signed-off-by: Joy Shermin <shermin.joy@intel.com>
> > ---
> >  include/net/bluetooth/hci_core.h |  2 +
> >  net/bluetooth/hci_request.c      | 80 ++++++++++++++++++++++++++++++++
> >  2 files changed, 82 insertions(+)
> >
> > diff --git a/include/net/bluetooth/hci_core.h
> > b/include/net/bluetooth/hci_core.h index 5f04ef88da35..e5e09d530ce7 100644
> > --- a/include/net/bluetooth/hci_core.h
> > +++ b/include/net/bluetooth/hci_core.h
> > @@ -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);
> >
> > diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> > index f4bbd3b79210..88225a9ca1f8 100644
> > --- a/net/bluetooth/hci_request.c
> > +++ b/net/bluetooth/hci_request.c
> > @@ -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) ||
> > +           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.
> > +                      * No HCI communication is required.Sort the
> > +                      * Kernel list.
> > +                      */
> > +                     hci_bdaddr_list_add_with_irk(&irk->list, bdaddr,
> type, irk_val, NULL);
> > +                     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); +
> > +     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.
>
> > +
> > +remote:
> > +     hci_req_del_from_resolving_list(hdev, irk->bdaddr_type, &irk-
> >bdaddr);
> > +
> > +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;
>
>
> --
> pozdrawiam
> Szymon Janc
>
>
Regards
Sathish N

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list
  2020-03-12 10:07 ` [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list Sathish Narsimman
@ 2020-03-18 10:42   ` Marcel Holtmann
  2020-03-18 10:47     ` Sathish Narasimman
  0 siblings, 1 reply; 21+ messages in thread
From: Marcel Holtmann @ 2020-03-18 10:42 UTC (permalink / raw)
  To: Sathish Narsimman; +Cc: linux-bluetooth, Chethan T N, Sathish Narsimman

Hi Sathish,

> This patch help to delte the resolving list stored in the BT
> Controller w.r.t BD_ADDR.
> 
> Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> ---
> include/net/bluetooth/hci.h      |  1 +
> include/net/bluetooth/hci_core.h |  2 ++
> net/bluetooth/hci_request.c      | 33 ++++++++++++++++++++++++++++++++
> 3 files changed, 36 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index 5f60e135aeb6..352bc43940ff 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -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
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index d4e28773d378..5f04ef88da35 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -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
> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> index bf83179ab9d1..f4bbd3b79210 100644
> --- a/net/bluetooth/hci_request.c
> +++ b/net/bluetooth/hci_request.c
> @@ -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;

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

Regards

Marcel


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed
  2020-03-12 10:07 ` [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed Sathish Narsimman
@ 2020-03-18 10:45   ` Marcel Holtmann
  0 siblings, 0 replies; 21+ messages in thread
From: Marcel Holtmann @ 2020-03-18 10:45 UTC (permalink / raw)
  To: Sathish Narsimman
  Cc: linux-bluetooth, chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

Hi Sathish,

> Whenever the Local IRK changes. i.e privacy mode is toggled
> this patch helps to change the IRK list in the bluetooth
> controller
> 
> Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> Signed-off-by: Joy Shermin <shermin.joy@intel.com>
> ---
> include/net/bluetooth/hci_core.h |  2 ++
> net/bluetooth/hci_request.c      | 50 ++++++++++++++++++++++++++++++++
> 2 files changed, 52 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index e5e09d530ce7..43d31a9339a6 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -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);
> 
> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> index 88225a9ca1f8..9ffb62178d24 100644
> --- a/net/bluetooth/hci_request.c
> +++ b/net/bluetooth/hci_request.c
> @@ -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;
> +
> +	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.

> +
> +	/* 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.

> +
> +	/* 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);
> +		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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list
  2020-03-18 10:42   ` Marcel Holtmann
@ 2020-03-18 10:47     ` Sathish Narasimman
  0 siblings, 0 replies; 21+ messages in thread
From: Sathish Narasimman @ 2020-03-18 10:47 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth, Chethan T N, Sathish Narsimman

Hi Marcel

On Wed, Mar 18, 2020 at 4:12 PM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Sathish,
>
> > This patch help to delte the resolving list stored in the BT
> > Controller w.r.t BD_ADDR.
> >
> > Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> > ---
> > include/net/bluetooth/hci.h      |  1 +
> > include/net/bluetooth/hci_core.h |  2 ++
> > net/bluetooth/hci_request.c      | 33 ++++++++++++++++++++++++++++++++
> > 3 files changed, 36 insertions(+)
> >
> > diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> > index 5f60e135aeb6..352bc43940ff 100644
> > --- a/include/net/bluetooth/hci.h
> > +++ b/include/net/bluetooth/hci.h
> > @@ -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
> > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> > index d4e28773d378..5f04ef88da35 100644
> > --- a/include/net/bluetooth/hci_core.h
> > +++ b/include/net/bluetooth/hci_core.h
> > @@ -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
> > diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> > index bf83179ab9d1..f4bbd3b79210 100644
> > --- a/net/bluetooth/hci_request.c
> > +++ b/net/bluetooth/hci_request.c
> > @@ -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;
>
> please don’t invent your own coding style. Follow the netdev convention.

Sure will correct the coding style in next version of the patch
>
> Regards
>
> Marcel
>

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 6/7] Bluetooth: Enable LL Privacy
  2020-03-12 10:07 ` [PATCH 6/7] Bluetooth: Enable LL Privacy Sathish Narsimman
@ 2020-03-18 11:04   ` Marcel Holtmann
  0 siblings, 0 replies; 21+ messages in thread
From: Marcel Holtmann @ 2020-03-18 11:04 UTC (permalink / raw)
  To: Sathish Narsimman
  Cc: linux-bluetooth, chethan.tumkur.narayan, Sathish Narsimman

Hi Sathish,

> 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)
>> 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
>> 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
>> 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)
>> 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)
> 
>> HCI Event: Command Complete (0x0e) plen 4
>      LE Add Device To Resolving List (0x08|0x0027) ncmd 1
>        Status: Success (0x00)
> 
> Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> ---
> 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(-)
> 
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index 352bc43940ff..d8431ebb8baa 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -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;
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index e245bc155cc2..06067c0852a6 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -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);
> +

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.

> 		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);
> +

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

> 		memset(&cp, 0, sizeof(cp));
> 
> 		/* Some controllers might reject command if intervals are not
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index dbd2ad3a26ed..7727be922084 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -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.

> @@ -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.

> +
> +			/* 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);
> +
> +		}
> +

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.

> 		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);
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 20408d386268..d5ce1921fadd 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -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.

> 	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;
> +

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

> 	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);
> +	}

This requires an appropriate comment change as well.

> 
> 	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;

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.

> +		}
> 
> 		/* If the controller is not using resolvable random
> 		 * addresses, then this report can be ignored.
> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> index 6b685cdc7de5..12868caf50ea 100644
> --- a/net/bluetooth/hci_request.c
> +++ b/net/bluetooth/hci_request.c
> @@ -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.
> 
> 		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.

> 	    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;

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

> 
> 		if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) &&
> 		    !bacmp(&hdev->random_addr, &hdev->rpa))
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index 6552003a170e..2b2bc011a130 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -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);
> }
> 
> diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
> index 1476a91ce935..85be3f5d869a 100644
> --- a/net/bluetooth/smp.c
> +++ b/net/bluetooth/smp.c
> @@ -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 */

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

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

Regards

Marcel


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list
  2020-03-12 10:07 ` [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list Sathish Narsimman
@ 2020-03-18 11:06   ` Marcel Holtmann
  0 siblings, 0 replies; 21+ messages in thread
From: Marcel Holtmann @ 2020-03-18 11:06 UTC (permalink / raw)
  To: Sathish Narsimman
  Cc: linux-bluetooth, chethan.tumkur.narayan, Sathish Narsimman, Joy Shermin

Hi Sathish,

> The patch is used to load the entries in the local IRK to the
> Bluetooth LE controller resolving list.
> 
> Signed-off-by: Sathish Narsimman <sathish.narasimman@intel.com>
> Signed-off-by: Joy Shermin <shermin.joy@intel.com>
> ---
> include/net/bluetooth/hci_core.h |  1 +
> net/bluetooth/hci_request.c      | 29 +++++++++++++++++++++++++++++
> 2 files changed, 30 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 43d31a9339a6..46d2d3e10c97 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -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,
> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
> index 9ffb62178d24..e17db3103a3d 100644
> --- a/net/bluetooth/hci_request.c
> +++ b/net/bluetooth/hci_request.c
> @@ -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);
> +	}

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] LE LL Priavcy support enabled
  2020-03-18  8:56 ` [PATCH 0/7] LE LL Priavcy support enabled Sathish Narasimman
@ 2020-04-01 20:04   ` Abhishek Pandit-Subedi
  2020-04-06 16:34     ` Marcel Holtmann
  0 siblings, 1 reply; 21+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-04-01 20:04 UTC (permalink / raw)
  To: Sathish Narasimman; +Cc: Bluez mailing list, Chethan T N, Sathish Narsimman

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

On Wed, Mar 18, 2020 at 1:56 AM Sathish Narasimman <nsathish41@gmail.com> wrote:
>
> Hi
>
> A gentle reminder to review the patches
>
> On Thu, Mar 12, 2020 at 3:36 PM Sathish Narsimman <nsathish41@gmail.com> wrote:
> >
> > 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
> >

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] LE LL Priavcy support enabled
  2020-04-01 20:04   ` Abhishek Pandit-Subedi
@ 2020-04-06 16:34     ` Marcel Holtmann
  0 siblings, 0 replies; 21+ messages in thread
From: Marcel Holtmann @ 2020-04-06 16:34 UTC (permalink / raw)
  To: Abhishek Pandit-Subedi
  Cc: Sathish Narasimman, Bluez mailing list, Chethan T N, Sathish Narsimman

Hi Abhishek,

> 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).

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-04-06 16:34 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 10:07 [PATCH 0/7] LE LL Priavcy support enabled Sathish Narsimman
2020-03-12 10:07 ` [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list Sathish Narsimman
2020-03-18 10:42   ` Marcel Holtmann
2020-03-18 10:47     ` Sathish Narasimman
2020-03-12 10:07 ` [PATCH 2/7] Bluetooth: Add device to Resolving List Sathish Narsimman
2020-03-18  9:29   ` Szymon Janc
2020-03-18 10:29     ` Sathish Narasimman
2020-03-12 10:07 ` [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed Sathish Narsimman
2020-03-18 10:45   ` Marcel Holtmann
2020-03-12 10:07 ` [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list Sathish Narsimman
2020-03-18 11:06   ` Marcel Holtmann
2020-03-12 10:07 ` [PATCH 5/7] Bluetooth: LL Privacy Check and Update the Resolving List Sathish Narsimman
2020-03-12 10:07 ` [PATCH 6/7] Bluetooth: Enable LL Privacy Sathish Narsimman
2020-03-18 11:04   ` Marcel Holtmann
2020-03-12 10:07 ` [PATCH 7/7] Bluetooth LL Privacy update White list Sathish Narsimman
2020-03-12 22:02   ` kbuild test robot
2020-03-12 23:23   ` kbuild test robot
2020-03-12 23:44   ` kbuild test robot
2020-03-18  8:56 ` [PATCH 0/7] LE LL Priavcy support enabled Sathish Narasimman
2020-04-01 20:04   ` Abhishek Pandit-Subedi
2020-04-06 16:34     ` Marcel Holtmann

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.