Skip to contentSkip to conversation

LL Privacy Support

PATCH Superseded Sathish Narasimman 2 participants 12 messages Jul 13, 2020 – Jul 23, 2020

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover LL Privacy Support

V4: patches are rebased
Added support to use set Experimental feature to enable controller address resolution

Marcel Holtmann (3):
Bluetooth: Translate additional address type correctly
Bluetooth: Configure controller address resolution if available
Bluetooth: Update resolving list when updating whitelist

Sathish Narasimman (5):
Bluetooth: Translate additional address type during le_conn
Bluetooth: Let controller creates RPA during le create conn
Bluetooth: Enable/Disable address resolution during le create conn
Bluetooth: Enable RPA Timeout
Bluetooth: Enable controller RPA resolution using Experimental feature

 include/net/bluetooth/hci.h      |   9 ++-
 include/net/bluetooth/hci_core.h |   3 +
 net/bluetooth/hci_conn.c         |   7 +-
 net/bluetooth/hci_core.c         |  17 +++++
 net/bluetooth/hci_event.c        |  21 ++++++
 net/bluetooth/hci_request.c      | 120 ++++++++++++++++++++++++++-----
 net/bluetooth/hci_request.h      |   3 +-
 net/bluetooth/mgmt.c             |  54 +++++++++++++-
 8 files changed, 213 insertions(+), 21 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 1/8 Bluetooth: Translate additional address type correctly

From: Marcel Holtmann <[email protected]>

When using controller based address resolution, then the new address types 0x02 and 0x03 are used. These types need to be converted back into either public address or random address types.

---
 include/net/bluetooth/hci.h | 6 ++++--
 net/bluetooth/hci_core.c    | 9 +++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
include/net/bluetooth/hci.h +4 -2
index 1f18f71363e9..abab8b5981a7 100644
@@ -2268,8 +2268,10 @@ struct hci_ev_le_conn_complete {
 #define LE_EXT_ADV_SCAN_RSP		0x0008
 #define LE_EXT_ADV_LEGACY_PDU		0x0010
 
-#define ADDR_LE_DEV_PUBLIC	0x00
-#define ADDR_LE_DEV_RANDOM	0x01
+#define ADDR_LE_DEV_PUBLIC		0x00
+#define ADDR_LE_DEV_RANDOM		0x01
+#define ADDR_LE_DEV_PUBLIC_RESOLVED	0x02
+#define ADDR_LE_DEV_RANDOM_RESOLVED	0x03
 
 #define HCI_EV_LE_ADVERTISING_REPORT	0x02
 struct hci_ev_le_advertising_info {
net/bluetooth/hci_core.c +9 -0
index 6509f785dd14..4af208b82138 100644
@@ -3290,6 +3290,15 @@ struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
 {
 	struct hci_conn_params *param;
 
+	switch (addr_type) {
+	case ADDR_LE_DEV_PUBLIC_RESOLVED:
+		addr_type = ADDR_LE_DEV_PUBLIC;
+		break;
+	case ADDR_LE_DEV_RANDOM_RESOLVED:
+		addr_type = ADDR_LE_DEV_RANDOM;
+		break;
+	}
+
 	list_for_each_entry(param, list, action) {
 		if (bacmp(&param->addr, addr) == 0 &&
 		    param->addr_type == addr_type)
Signature · 1 line
2.17.1
#2 lore raw

PATCH v4 2/8 Bluetooth: Configure controller address resolution if available

In reply to Sathish Narasimman

From: Marcel Holtmann <[email protected]>

When the LL Privacy support is available, then as part of enabling or disabling passive background scanning, it is required to set up the controller based address resolution as well.

Since only passive background scanning is utilizing the whitelist, the address resolution is now bound to the whitelist and passive background scanning. All other resolution can be easily done by the host stack.

---
 include/net/bluetooth/hci_core.h |  3 +++
 net/bluetooth/hci_request.c      | 26 +++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)
include/net/bluetooth/hci_core.h +3 -0
index 34ad5b207598..065250242a1b 100644
@@ -1359,6 +1359,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
 			 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
 
+/* Use LL Privacy based address resolution if supported */
+#define use_ll_privacy(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
+
 /* Use ext scanning if set ext scan param and ext scan enable is supported */
 #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
 			   ((dev)->commands[37] & 0x40))
net/bluetooth/hci_request.c +23 -3
index 770b93758112..d3c7ddbcff33 100644
@@ -675,6 +675,12 @@ void hci_req_add_le_scan_disable(struct hci_request *req)
 		cp.enable = LE_SCAN_DISABLE;
 		hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
 	}
+
+	if (use_ll_privacy(hdev) &&
+	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) {
+		__u8 enable = 0x00;
+		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
+	}
 }
 
 static void del_from_white_list(struct hci_request *req, bdaddr_t *bdaddr,
@@ -816,7 +822,8 @@ static bool scan_use_rpa(struct hci_dev *hdev)
 }
 
 static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
-			       u16 window, u8 own_addr_type, u8 filter_policy)
+			       u16 window, u8 own_addr_type, u8 filter_policy,
+			       bool addr_resolv)
 {
 	struct hci_dev *hdev = req->hdev;
 
@@ -825,6 +832,11 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 		return;
 	}
 
+	if (use_ll_privacy(hdev) && addr_resolv) {
+		u8 enable = 0x01;
+		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
+	}
+
 	/* Use ext scanning if set ext scan param and ext scan enable is
 	 * supported
 	 */
@@ -898,12 +910,18 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 	}
 }
 
+/* Ensure to call hci_req_add_le_scan_disable() first to disable the
+ * controller based address resolution to be able to reconfigure
+ * resolving list.
+ */
 void hci_req_add_le_passive_scan(struct hci_request *req)
 {
 	struct hci_dev *hdev = req->hdev;
 	u8 own_addr_type;
 	u8 filter_policy;
 	u16 window, interval;
+	/* Background scanning should run with address resolution */
+	bool addr_resolv = true;
 
 	if (hdev->scanning_paused) {
 		bt_dev_dbg(hdev, "Scanning is paused for suspend");
@@ -949,7 +967,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req)
 
 	bt_dev_dbg(hdev, "LE passive scan with whitelist = %d", filter_policy);
 	hci_req_start_scan(req, LE_SCAN_PASSIVE, interval, window,
-			   own_addr_type, filter_policy);
+			   own_addr_type, filter_policy, addr_resolv);
 }
 
 static u8 get_adv_instance_scan_rsp_len(struct hci_dev *hdev, u8 instance)
@@ -2748,6 +2766,8 @@ static int active_scan(struct hci_request *req, unsigned long opt)
 	u8 own_addr_type;
 	/* White list is not used for discovery */
 	u8 filter_policy = 0x00;
+	/* Discovery doesn't require controller address resolution */
+	bool addr_resolv = false;
 	int err;
 
 	BT_DBG("%s", hdev->name);
@@ -2770,7 +2790,7 @@ static int active_scan(struct hci_request *req, unsigned long opt)
 
 	hci_req_start_scan(req, LE_SCAN_ACTIVE, interval,
 			   hdev->le_scan_window_discovery, own_addr_type,
-			   filter_policy);
+			   filter_policy, addr_resolv);
 	return 0;
 }
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH v4 3/8 Bluetooth: Update resolving list when updating whitelist

In reply to Sathish Narasimman

From: Marcel Holtmann <[email protected]>

When the whitelist is updated, then also update the entries of the resolving list for devices where IRKs are available.

---
 net/bluetooth/hci_request.c | 41 +++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
net/bluetooth/hci_request.c +39 -2
index d3c7ddbcff33..2dc00604412c 100644
@@ -694,6 +694,21 @@ static void del_from_white_list(struct hci_request *req, bdaddr_t *bdaddr,
 	bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from whitelist", &cp.bdaddr,
 		   cp.bdaddr_type);
 	hci_req_add(req, HCI_OP_LE_DEL_FROM_WHITE_LIST, sizeof(cp), &cp);
+
+	if (use_ll_privacy(req->hdev)) {
+		struct smp_irk *irk;
+
+		irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type);
+		if (irk) {
+			struct hci_cp_le_del_from_resolv_list cp;
+
+			cp.bdaddr_type = bdaddr_type;
+			bacpy(&cp.bdaddr, bdaddr);
+
+			hci_req_add(req, HCI_OP_LE_DEL_FROM_RESOLV_LIST,
+				    sizeof(cp), &cp);
+		}
+	}
 }
 
 /* Adds connection to white list if needed. On error, returns -1. */
@@ -714,7 +729,7 @@ static int add_to_white_list(struct hci_request *req,
 		return -1;
 
 	/* White list can not be used with RPAs */
-	if (!allow_rpa &&
+	if (!allow_rpa && !use_ll_privacy(hdev) &&
 	    hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
 		return -1;
 	}
@@ -732,6 +747,28 @@ static int add_to_white_list(struct hci_request *req,
 		   cp.bdaddr_type);
 	hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);
 
+	if (use_ll_privacy(hdev)) {
+		struct smp_irk *irk;
+
+		irk = hci_find_irk_by_addr(hdev, &params->addr,
+					   params->addr_type);
+		if (irk) {
+			struct hci_cp_le_add_to_resolv_list cp;
+
+			cp.bdaddr_type = params->addr_type;
+			bacpy(&cp.bdaddr, &params->addr);
+			memcpy(cp.peer_irk, irk->val, 16);
+
+			if (hci_dev_test_flag(hdev, HCI_PRIVACY))
+				memcpy(cp.local_irk, hdev->irk, 16);
+			else
+				memset(cp.local_irk, 0, 16);
+
+			hci_req_add(req, HCI_OP_LE_ADD_TO_RESOLV_LIST,
+				    sizeof(cp), &cp);
+		}
+	}
+
 	return 0;
 }
 
@@ -772,7 +809,7 @@ static u8 update_white_list(struct hci_request *req)
 		}
 
 		/* White list can not be used with RPAs */
-		if (!allow_rpa &&
+		if (!allow_rpa && !use_ll_privacy(hdev) &&
 		    hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) {
 			return 0x00;
 		}
Signature · 1 line
2.17.1
#4 lore raw

PATCH v4 4/8 Bluetooth: Translate additional address type during le_conn

In reply to Sathish Narasimman

When using controller based address resolution, then the new address types 0x02 and 0x03 are used. These types need to be converted back into either public address or random address types.

This patch is specially during LE_CREATE_CONN if using own_add_type as 0x02 or 0x03.

---
 net/bluetooth/hci_event.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/bluetooth/hci_event.c +16 -0
index 927bde511170..eae5bd4a53ac 100644
@@ -2296,6 +2296,22 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
 	if (!conn)
 		return;
 
+	/* When using controller based address resolution, then the new
+	 * address types 0x02 and 0x03 are used. These types need to be
+	 * converted back into either public address or random address type
+	 */
+	if (use_ll_privacy(hdev) &&
+	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) {
+		switch (own_address_type) {
+		case ADDR_LE_DEV_PUBLIC_RESOLVED:
+			own_address_type = ADDR_LE_DEV_PUBLIC;
+			break;
+		case ADDR_LE_DEV_RANDOM_RESOLVED:
+			own_address_type = ADDR_LE_DEV_RANDOM;
+			break;
+		}
+	}
+
 	/* Store the initiator and responder address information which
 	 * is needed for SMP. These values will not change during the
 	 * lifetime of the connection.
Signature · 1 line
2.17.1
#5 lore raw

PATCH v4 5/8 Bluetooth: Let controller creates RPA during le create conn

In reply to Sathish Narasimman

When address resolution is enabled and set_privacy is enabled let's use own address type as 0x03

---
 net/bluetooth/hci_request.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
net/bluetooth/hci_request.c +7 -1
index 2dc00604412c..e16d5154b2cf 100644
@@ -2201,7 +2201,13 @@ 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 Controller supports LL Privacy use own address type is
+		 * 0x03
+		 */
+		if (use_ll_privacy(hdev))
+			*own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
+		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))
Signature · 1 line
2.17.1
#6 lore raw

PATCH v4 6/8 Bluetooth: Enable/Disable address resolution during le create conn

In reply to Sathish Narasimman

In this patch if le_create_conn process is started restrict to disable address resolution and same is disabled during le_enh_connection_complete

---
 net/bluetooth/hci_conn.c    |  7 +++++-
 net/bluetooth/hci_event.c   |  4 ++++
 net/bluetooth/hci_request.c | 45 ++++++++++++++++++++++++++++---------
 net/bluetooth/hci_request.h |  3 ++-
 net/bluetooth/mgmt.c        |  2 +-
 5 files changed, 47 insertions(+), 14 deletions(-)
net/bluetooth/hci_conn.c +6 -1
index 8805d68e65f2..caf1598758bf 100644
@@ -1003,6 +1003,11 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 	struct hci_request req;
 	int err;
 
+	/* This ensures that during disable le_scan address resolution
+	 * will not be disabled if it is followed by le_create_conn
+	 */
+	bool rpa_le_conn = true;
+
 	/* Let's make sure that le is enabled.*/
 	if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
 		if (lmp_le_capable(hdev))
@@ -1103,7 +1108,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 	 * state.
 	 */
 	if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
-		hci_req_add_le_scan_disable(&req);
+		hci_req_add_le_scan_disable(&req, rpa_le_conn);
 		hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED);
 	}
 
net/bluetooth/hci_event.c +4 -0
index eae5bd4a53ac..684c68cb5c76 100644
@@ -5221,6 +5221,10 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
 			     le16_to_cpu(ev->interval),
 			     le16_to_cpu(ev->latency),
 			     le16_to_cpu(ev->supervision_timeout));
+
+	if (use_ll_privacy(hdev) &&
+	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
+		hci_req_disable_address_resolution(hdev);
 }
 
 static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb)
net/bluetooth/hci_request.c +34 -11

118 lines not on this page · raw message

net/bluetooth/hci_request.h +2 -1
index 0e81614d235e..12bea10e7d70 100644
@@ -65,11 +65,12 @@ void __hci_req_write_fast_connectable(struct hci_request *req, bool enable);
 void __hci_req_update_name(struct hci_request *req);
 void __hci_req_update_eir(struct hci_request *req);
 
-void hci_req_add_le_scan_disable(struct hci_request *req);
+void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn);
 void hci_req_add_le_passive_scan(struct hci_request *req);
 
 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next);
 
+void hci_req_disable_address_resolution(struct hci_dev *hdev);
 void hci_req_reenable_advertising(struct hci_dev *hdev);
 void __hci_req_enable_advertising(struct hci_request *req);
 void __hci_req_disable_advertising(struct hci_request *req);
net/bluetooth/mgmt.c +1 -1
index 686ef4792831..c292d5de4dc3 100644
@@ -5226,7 +5226,7 @@ static int set_scan_params(struct sock *sk, struct hci_dev *hdev,
 
 		hci_req_init(&req, hdev);
 
-		hci_req_add_le_scan_disable(&req);
+		hci_req_add_le_scan_disable(&req, false);
 		hci_req_add_le_passive_scan(&req);
 
 		hci_req_run(&req, NULL);
Signature · 1 line
2.17.1
#7 lore raw

PATCH v4 7/8 Bluetooth: Enable RPA Timeout

In reply to Sathish Narasimman

Enable RPA timeout during bluetooth initialization. The RPA timeout value is used from hdev, which initialized from debug_fs

---
 include/net/bluetooth/hci.h | 2 ++
 net/bluetooth/hci_core.c    | 8 ++++++++
 2 files changed, 10 insertions(+)
include/net/bluetooth/hci.h +2 -0
index abab8b5981a7..4ff2fc4498f3 100644
@@ -1637,6 +1637,8 @@ struct hci_rp_le_read_resolv_list_size {
 
 #define HCI_OP_LE_SET_ADDR_RESOLV_ENABLE 0x202d
 
+#define HCI_OP_LE_SET_RPA_TIMEOUT	0x202e
+
 #define HCI_OP_LE_READ_MAX_DATA_LEN	0x202f
 struct hci_rp_le_read_max_data_len {
 	__u8	status;
net/bluetooth/hci_core.c +8 -0
index 4af208b82138..2030536cc5d8 100644
@@ -762,6 +762,14 @@ 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] & 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);
Signature · 1 line
2.17.1
#8 lore raw

PATCH v4 8/8 Bluetooth: Enable controller RPA resolution using Experimental feature

In reply to Sathish Narasimman

This patch adds support to enable the use of RPA Address resolution using expermental feature mgmt command.

---
 include/net/bluetooth/hci.h |  1 +
 net/bluetooth/hci_event.c   |  3 ++-
 net/bluetooth/hci_request.c |  6 +++--
 net/bluetooth/mgmt.c        | 52 +++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 3 deletions(-)
include/net/bluetooth/hci.h +1 -0
index 4ff2fc4498f3..cb284365b4c1 100644
@@ -307,6 +307,7 @@ enum {
 	HCI_FORCE_BREDR_SMP,
 	HCI_FORCE_STATIC_ADDR,
 	HCI_LL_RPA_RESOLUTION,
+	HCI_ENABLE_RPA_RESOLUTION,
 	HCI_CMD_PENDING,
 	HCI_FORCE_NO_MITM,
 
net/bluetooth/hci_event.c +2 -1
index 684c68cb5c76..c8a5e1e4dba2 100644
@@ -5222,7 +5222,8 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
 			     le16_to_cpu(ev->latency),
 			     le16_to_cpu(ev->supervision_timeout));
 
-	if (use_ll_privacy(hdev) &&
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) &&
 	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
 		hci_req_disable_address_resolution(hdev);
 }
net/bluetooth/hci_request.c +4 -2
index c3193f7f9ff0..cb44b83539e6 100644
@@ -677,7 +677,8 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn)
 	}
 
 	/* Disable address resolution */
-	if (use_ll_privacy(hdev) &&
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) &&
 	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
 		__u8 enable = 0x00;
 		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
@@ -870,7 +871,8 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 		return;
 	}
 
-	if (use_ll_privacy(hdev) && addr_resolv) {
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) && addr_resolv) {
 		u8 enable = 0x01;
 		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
 	}
net/bluetooth/mgmt.c +52 -0

70 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#9 lore raw

Re: [PATCH v4 8/8] Bluetooth: Enable controller RPA resolution using Experimental feature

Hi Sathish,

Quoted 2 lines

This patch adds support to enable the use of RPA Address resolution using expermental feature mgmt command.

everything looks fine, except for this patch. I just prefer to only apply the others if we can apply this one as well.

Quoted 13 lines

---

include/net/bluetooth/hci.h |  1 +
net/bluetooth/hci_event.c   |  3 ++-
net/bluetooth/hci_request.c |  6 +++--
net/bluetooth/mgmt.c        | 52 +++++++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 3 deletions(-)
include/net/bluetooth/hci.h +0 -0
index 4ff2fc4498f3..cb284365b4c1 100644

include/net/bluetooth/hci.h enum { · line 310

Quoted 4 lines
include/net/bluetooth/hci.h +1 -0
@@ -307,6 +307,7 @@ enum {
 	HCI_FORCE_BREDR_SMP,
 	HCI_FORCE_STATIC_ADDR,
 	HCI_LL_RPA_RESOLUTION,
+	HCI_ENABLE_RPA_RESOLUTION,

I would call this ENABLE_LL_PRIVAY. It put its more in line with use_ll_privacy and clearly distinct from the LL_RPA_RESOLUTION with is a HCI operational mode.

Quoted 8 lines
include/net/bluetooth/hci.h +0 -0
 	HCI_CMD_PENDING,
 	HCI_FORCE_NO_MITM,
 
net/bluetooth/hci_event.c +0 -0
index 684c68cb5c76..c8a5e1e4dba2 100644

net/bluetooth/hci_event.c static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, · line 5227

Quoted 7 lines
net/bluetooth/hci_event.c +2 -1
@@ -5222,7 +5222,8 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
 			     le16_to_cpu(ev->latency),
 			     le16_to_cpu(ev->supervision_timeout));
 
-	if (use_ll_privacy(hdev) &&
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) &&
 	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))

I would leave use_ll_privacy at the top and add the new one after it.

net/bluetooth/hci_request.c void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn) · line 681

Quoted 13 lines
net/bluetooth/hci_event.c +0 -0
 		hci_req_disable_address_resolution(hdev);
 }
net/bluetooth/hci_request.c +2 -1
index c3193f7f9ff0..cb44b83539e6 100644
@@ -677,7 +677,8 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn)
 	}
 
 	/* Disable address resolution */
-	if (use_ll_privacy(hdev) &&
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) &&

Same here.

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

Quoted 10 lines
net/bluetooth/hci_request.c +2 -1
 	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
 		__u8 enable = 0x00;
 		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
@@ -870,7 +871,8 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 		return;
 	}
 
-	if (use_ll_privacy(hdev) && addr_resolv) {
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) && addr_resolv) {

And here.

Quoted 21 lines
net/bluetooth/hci_request.c +0 -0
 		u8 enable = 0x01;
 		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
 	}
net/bluetooth/mgmt.c +6 -0
index c292d5de4dc3..fbe02ab5fa05 100644
@@ -3759,6 +3759,12 @@ static const u8 simult_central_periph_uuid[16] = {
 	0x96, 0x46, 0xc0, 0x42, 0xb5, 0x10, 0x1b, 0x67,
 };
 
+/* 15c0a148-c273-11ea-b3de-0242ac130004 */
+static const u8 rpa_resolution_uuid[16] = {
+	0x04, 0x00, 0x13, 0xac, 0x42, 0x02, 0xde, 0xb3,
+	0xea, 0x11, 0x73, 0xc2, 0x48, 0xa1, 0xc0, 0x15,
+};
+
 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
 				  void *data, u16 data_len)
 {

net/bluetooth/mgmt.c static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · line 3804

Quoted 4 lines
net/bluetooth/mgmt.c +1 -0
@@ -3795,6 +3801,17 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
 		idx++;
 	}
 
+	if (hdev) {

If use_ll_privacy is not available, then we should also not expose this experimental feature.

net/bluetooth/mgmt.c static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · line 3809

Quoted 5 lines
net/bluetooth/mgmt.c +5 -0
+		if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION))
+			flags = BIT(0);
+		else
+			flags = 0;
+

And since we only support the RPA resolution for central mode at the moment, we really now need to disable advertising support. So this one needs to indicate the the supported settings will change when enabled.

Quoted 33 lines
net/bluetooth/mgmt.c +26 -0
+		memcpy(rp->features[idx].uuid, rpa_resolution_uuid, 16);
+		rp->features[idx].flags = cpu_to_le32(flags);
+		idx++;
+	}
+
 	rp->feature_count = cpu_to_le16(idx);
 
 	/* After reading the experimental features information, enable
@@ -3895,6 +3912,41 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
 	}
 #endif
 
+	if (!memcmp(cp->uuid, rpa_resolution_uuid, 16)) {
+		bool val;
+		int err;
+
+		/* Parameters are limited to a single octet */
+		if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1)
+			return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+					       MGMT_OP_SET_EXP_FEATURE,
+					       MGMT_STATUS_INVALID_PARAMS);
+
+		/* Only boolean on/off is supported */
+		if (cp->param[0] != 0x00 && cp->param[0] != 0x01)
+			return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+					       MGMT_OP_SET_EXP_FEATURE,
+					       MGMT_STATUS_INVALID_PARAMS);
+
+		val = !!cp->param[0];
+
+		if (val)
+			hci_dev_set_flag(hdev, HCI_ENABLE_RPA_RESOLUTION);
+		else

net/bluetooth/mgmt.c static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · line 3945

Quoted 10 lines
net/bluetooth/mgmt.c +10 -0
+			hci_dev_clear_flag(hdev, HCI_ENABLE_RPA_RESOLUTION);
+
+		memcpy(rp.uuid, rpa_resolution_uuid, 16);
+		rp.flags = cpu_to_le32(val ? BIT(0) : 0);
+
+		hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
+
+		err = mgmt_cmd_complete(sk, MGMT_INDEX_NONE,
+					MGMT_OP_SET_EXP_FEATURE, 0,
+					&rp, sizeof(rp));

The exp_feature_changed event is missing. In addition you need to handle the ZERO_KEY branch which means it will reset all experimental features back to default.

net/bluetooth/mgmt.c static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · line 3952

Quoted 7 lines
net/bluetooth/mgmt.c +4 -0
+
+		return err;
+	}
+
 	return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE,
 			       MGMT_OP_SET_EXP_FEATURE,
 			       MGMT_STATUS_NOT_SUPPORTED);

Regards

Marcel

#10 lore raw

Re: [PATCH v4 8/8] Bluetooth: Enable controller RPA resolution using Experimental feature

Hi Marcel

Quoted 16 lines · Marcel Holtmann

Hi Sathish,

Quoted 2 lines

This patch adds support to enable the use of RPA Address resolution using expermental feature mgmt command.

everything looks fine, except for this patch. I just prefer to only apply the others if we can apply this one as well.

Quoted 8 lines

---

include/net/bluetooth/hci.h |  1 +
net/bluetooth/hci_event.c   |  3 ++-
net/bluetooth/hci_request.c |  6 +++--
net/bluetooth/mgmt.c        | 52 +++++++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 3 deletions(-)
Quoted 12 lines

include/net/bluetooth/hci.h enum { · line 310

Quoted 9 lines
include/net/bluetooth/hci.h +1 -0
index 4ff2fc4498f3..cb284365b4c1 100644
@@ -307,6 +307,7 @@ enum {
      HCI_FORCE_BREDR_SMP,
      HCI_FORCE_STATIC_ADDR,
      HCI_LL_RPA_RESOLUTION,
+     HCI_ENABLE_RPA_RESOLUTION,

I would call this ENABLE_LL_PRIVAY. It put its more in line with use_ll_privacy and clearly distinct from the LL_RPA_RESOLUTION with is a HCI operational mode.

Will change it

Quoted 75 lines
Quoted 8 lines
include/net/bluetooth/hci.h +0 -0
      HCI_CMD_PENDING,
      HCI_FORCE_NO_MITM,
 
net/bluetooth/hci_event.c +0 -0
index 684c68cb5c76..c8a5e1e4dba2 100644

net/bluetooth/hci_event.c static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, · line 5227

Quoted 7 lines
net/bluetooth/hci_event.c +2 -1
@@ -5222,7 +5222,8 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
                           le16_to_cpu(ev->latency),
                           le16_to_cpu(ev->supervision_timeout));
 
-     if (use_ll_privacy(hdev) &&
+     if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+         use_ll_privacy(hdev) &&
          hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))

I would leave use_ll_privacy at the top and add the new one after it.

net/bluetooth/hci_request.c void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn) · line 681

Quoted 13 lines
net/bluetooth/hci_event.c +0 -0
              hci_req_disable_address_resolution(hdev);
 }
net/bluetooth/hci_request.c +2 -1
index c3193f7f9ff0..cb44b83539e6 100644
@@ -677,7 +677,8 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn)
      }
 
      /* Disable address resolution */
-     if (use_ll_privacy(hdev) &&
+     if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+         use_ll_privacy(hdev) &&

Same here.

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

Quoted 10 lines
net/bluetooth/hci_request.c +2 -1
          hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
              __u8 enable = 0x00;
              hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
@@ -870,7 +871,8 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
              return;
      }
 
-     if (use_ll_privacy(hdev) && addr_resolv) {
+     if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+         use_ll_privacy(hdev) && addr_resolv) {

And here.

Quoted 21 lines
net/bluetooth/hci_request.c +0 -0
              u8 enable = 0x01;
              hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
      }
net/bluetooth/mgmt.c +6 -0
index c292d5de4dc3..fbe02ab5fa05 100644
@@ -3759,6 +3759,12 @@ static const u8 simult_central_periph_uuid[16] = {
      0x96, 0x46, 0xc0, 0x42, 0xb5, 0x10, 0x1b, 0x67,
 };
 
+/* 15c0a148-c273-11ea-b3de-0242ac130004 */
+static const u8 rpa_resolution_uuid[16] = {
+     0x04, 0x00, 0x13, 0xac, 0x42, 0x02, 0xde, 0xb3,
+     0xea, 0x11, 0x73, 0xc2, 0x48, 0xa1, 0xc0, 0x15,
+};
+
 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
                                void *data, u16 data_len)
 {

net/bluetooth/mgmt.c static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · line 3804

Quoted 4 lines
net/bluetooth/mgmt.c +1 -0
@@ -3795,6 +3801,17 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
              idx++;
      }
 
+     if (hdev) {

If use_ll_privacy is not available, then we should also not expose this experimental feature.

Quoted 8 lines

net/bluetooth/mgmt.c static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · line 3809

Quoted 5 lines
net/bluetooth/mgmt.c +5 -0
+             if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION))
+                     flags = BIT(0);
+             else
+                     flags = 0;
+

And since we only support the RPA resolution for central mode at the moment, we really now need to disable advertising support. So this one needs to indicate the the supported settings will change when enabled.

Does disable advertising support means clearing HCI_ADVERTISING flag? Or __hci_req_disable_advertising
Please review the next version of the changes where i updated clearing the flag

Quoted 37 lines
Quoted 37 lines
net/bluetooth/mgmt.c +30 -0
+             memcpy(rp->features[idx].uuid, rpa_resolution_uuid, 16);
+             rp->features[idx].flags = cpu_to_le32(flags);
+             idx++;
+     }
+
      rp->feature_count = cpu_to_le16(idx);
 
      /* After reading the experimental features information, enable
@@ -3895,6 +3912,41 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
      }
 #endif
 
+     if (!memcmp(cp->uuid, rpa_resolution_uuid, 16)) {
+             bool val;
+             int err;
+
+             /* Parameters are limited to a single octet */
+             if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1)
+                     return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+                                            MGMT_OP_SET_EXP_FEATURE,
+                                            MGMT_STATUS_INVALID_PARAMS);
+
+             /* Only boolean on/off is supported */
+             if (cp->param[0] != 0x00 && cp->param[0] != 0x01)
+                     return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+                                            MGMT_OP_SET_EXP_FEATURE,
+                                            MGMT_STATUS_INVALID_PARAMS);
+
+             val = !!cp->param[0];
+
+             if (val)
+                     hci_dev_set_flag(hdev, HCI_ENABLE_RPA_RESOLUTION);
+             else
+                     hci_dev_clear_flag(hdev, HCI_ENABLE_RPA_RESOLUTION);
+
+             memcpy(rp.uuid, rpa_resolution_uuid, 16);
+             rp.flags = cpu_to_le32(val ? BIT(0) : 0);
Quoted 8 lines

net/bluetooth/mgmt.c static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · line 3945

Quoted 6 lines
net/bluetooth/mgmt.c +6 -0
+
+             hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
+
+             err = mgmt_cmd_complete(sk, MGMT_INDEX_NONE,
+                                     MGMT_OP_SET_EXP_FEATURE, 0,
+                                     &rp, sizeof(rp));

The exp_feature_changed event is missing. In addition you need to handle the ZERO_KEY branch which means it will reset all experimental features back to default.

Changes done please help to review version 5

Quoted 11 lines

net/bluetooth/mgmt.c static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · line 3952

Quoted 8 lines
net/bluetooth/mgmt.c +4 -0
+
+             return err;
+     }
+
      return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE,
                             MGMT_OP_SET_EXP_FEATURE,
                             MGMT_STATUS_NOT_SUPPORTED);

Regards

Quoted 2 lines

Marcel

Regards
Sathish N

#11 lore raw
In reply to Sathish Narasimman

Hi

Gentle reminder

Quoted 27 lines · Sathish Narasimman

V4: patches are rebased
Added support to use set Experimental feature to enable controller address resolution

Marcel Holtmann (3):
Bluetooth: Translate additional address type correctly
Bluetooth: Configure controller address resolution if available
Bluetooth: Update resolving list when updating whitelist

Sathish Narasimman (5):
Bluetooth: Translate additional address type during le_conn
Bluetooth: Let controller creates RPA during le create conn
Bluetooth: Enable/Disable address resolution during le create conn
Bluetooth: Enable RPA Timeout
Bluetooth: Enable controller RPA resolution using Experimental feature

 include/net/bluetooth/hci.h      |   9 ++-
 include/net/bluetooth/hci_core.h |   3 +
 net/bluetooth/hci_conn.c         |   7 +-
 net/bluetooth/hci_core.c         |  17 +++++
 net/bluetooth/hci_event.c        |  21 ++++++
 net/bluetooth/hci_request.c      | 120 ++++++++++++++++++++++++++-----
 net/bluetooth/hci_request.h      |   3 +-
 net/bluetooth/mgmt.c             |  54 +++++++++++++-
 8 files changed, 213 insertions(+), 21 deletions(-)
Quoted 3 lines

--
2.17.1

Regards
Sathish N