Skip to contentSkip to conversation

Bluetooth: hci_sync: Set Privacy Mode when updating the resolving list

PATCH In review Luiz Augusto von Dentz 2 participants 5 messages Nov 2, 2021 – Nov 3, 2021

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: hci_sync: Set Privacy Mode when updating the resolving list

From: Luiz Augusto von Dentz <[email protected]>

This adds support for Set Privacy Mode when updating the resolving list when HCI_LIMITED_PRIVACY so the controller shall use Device Mode for devices programmed in the resolving list, Device Mode is actually required when the remote device are not able to use RPA as otherwise the default mode is Network Privacy Mode in which only RPA are allowed thus the controller would filter out advertisement using the identity address for which there is an IRK.

---
 include/net/bluetooth/hci.h |  7 ++++++
 net/bluetooth/hci_sync.c    | 48 ++++++++++++++++++++++++++++++++-----
 2 files changed, 49 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +7 -0
index 63065bc01b76..aa856dfd5b9f 100644
@@ -1930,6 +1930,13 @@ struct hci_rp_le_read_transmit_power {
 	__s8  max_le_tx_power;
 } __packed;
 
+#define HCI_OP_LE_SET_PRIVACY_MODE	0x204e
+struct hci_cp_le_set_privacy_mode {
+	__u8  bdaddr_type;
+	bdaddr_t  bdaddr;
+	__u8  mode;
+} __packed;
+
 #define HCI_OP_LE_READ_BUFFER_SIZE_V2	0x2060
 struct hci_rp_le_read_buffer_size_v2 {
 	__u8    status;
net/bluetooth/hci_sync.c +42 -6

67 lines not on this page · raw message

Signature · 1 line
2.31.1
maintainer
#1 lore raw

Hi Luiz,

Quoted 54 lines

This adds support for Set Privacy Mode when updating the resolving list when HCI_LIMITED_PRIVACY so the controller shall use Device Mode for devices programmed in the resolving list, Device Mode is actually required when the remote device are not able to use RPA as otherwise the default mode is Network Privacy Mode in which only RPA are allowed thus the controller would filter out advertisement using the identity address for which there is an IRK.

---
include/net/bluetooth/hci.h | 7 ++++++
net/bluetooth/hci_sync.c | 48 ++++++++++++++++++++++++++++++++-----

2 files changed, 49 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +7 -0
index 63065bc01b76..aa856dfd5b9f 100644
@@ -1930,6 +1930,13 @@ struct hci_rp_le_read_transmit_power {
 	__s8  max_le_tx_power;
 } __packed;
 
+#define HCI_OP_LE_SET_PRIVACY_MODE	0x204e
+struct hci_cp_le_set_privacy_mode {
+	__u8  bdaddr_type;
+	bdaddr_t  bdaddr;
+	__u8  mode;
+} __packed;
+
 #define HCI_OP_LE_READ_BUFFER_SIZE_V2	0x2060
 struct hci_rp_le_read_buffer_size_v2 {
 	__u8    status;
net/bluetooth/hci_sync.c +14 -0
index b794605dc882..43173d645436 100644
@@ -1580,8 +1580,37 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev,
 				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
 
+/* Set Device Privacy Mode. */
+static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev,
+					struct hci_conn_params *params)
+{
+	struct hci_cp_le_set_privacy_mode cp;
+	struct smp_irk *irk;
+
+	/* Set Privacy Mode requires the use of resolving list (aka. LL Privacy)
+	 * by default Network Mode is used so only really send the command if
+	 * Device Mode is required (HCI_LIMITED_PRIVACY).
+	 */
+	if (!use_ll_privacy(hdev) ||
+	    !hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY))
+		return 0;

net/bluetooth/hci_sync.c static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, · line 1606

Quoted 10 lines
net/bluetooth/hci_sync.c +10 -0
+
+	irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type);
+	if (!irk)
+		return 0;
+
+	memset(&cp, 0, sizeof(cp));
+	cp.bdaddr_type = irk->addr_type;
+	bacpy(&cp.bdaddr, &irk->bdaddr);
+	cp.mode = 0x01;
+

you need to check if this command is actually supported.

I think the best option is to add it to Set Device Flags and let bluetoothd set it on a per device basis like it does with the wakeup flag.

Trying to tie it to the Limited Privacy mode seems weird. Since that is for discoverability and this is for outgoing connections.

Regards

Marcel

author maintainer
#2 lore raw

Hi Marcel,

Quoted 61 lines · Marcel Holtmann

Hi Luiz,

Quoted 58 lines

This adds support for Set Privacy Mode when updating the resolving list when HCI_LIMITED_PRIVACY so the controller shall use Device Mode for devices programmed in the resolving list, Device Mode is actually required when the remote device are not able to use RPA as otherwise the default mode is Network Privacy Mode in which only RPA are allowed thus the controller would filter out advertisement using the identity address for which there is an IRK.

---
include/net/bluetooth/hci.h | 7 ++++++
net/bluetooth/hci_sync.c | 48 ++++++++++++++++++++++++++++++++-----

2 files changed, 49 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +7 -0
index 63065bc01b76..aa856dfd5b9f 100644
@@ -1930,6 +1930,13 @@ struct hci_rp_le_read_transmit_power {
      __s8  max_le_tx_power;
 } __packed;
 
+#define HCI_OP_LE_SET_PRIVACY_MODE   0x204e
+struct hci_cp_le_set_privacy_mode {
+     __u8  bdaddr_type;
+     bdaddr_t  bdaddr;
+     __u8  mode;
+} __packed;
+
 #define HCI_OP_LE_READ_BUFFER_SIZE_V2 0x2060
 struct hci_rp_le_read_buffer_size_v2 {
      __u8    status;
net/bluetooth/hci_sync.c +18 -0
index b794605dc882..43173d645436 100644
@@ -1580,8 +1580,37 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev,
                                   sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
 
+/* Set Device Privacy Mode. */
+static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev,
+                                     struct hci_conn_params *params)
+{
+     struct hci_cp_le_set_privacy_mode cp;
+     struct smp_irk *irk;
+
+     /* Set Privacy Mode requires the use of resolving list (aka. LL Privacy)
+      * by default Network Mode is used so only really send the command if
+      * Device Mode is required (HCI_LIMITED_PRIVACY).
+      */
+     if (!use_ll_privacy(hdev) ||
+         !hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY))
+             return 0;
+
+     irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type);
+     if (!irk)
+             return 0;
Quoted 8 lines

net/bluetooth/hci_sync.c static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, · line 1606

Quoted 6 lines
net/bluetooth/hci_sync.c +6 -0
+
+     memset(&cp, 0, sizeof(cp));
+     cp.bdaddr_type = irk->addr_type;
+     bacpy(&cp.bdaddr, &irk->bdaddr);
+     cp.mode = 0x01;
+

you need to check if this command is actually supported.

The spec suggests it is mandatory if LL Privacy is supported:

'C9: Mandatory if LE Feature (LL Privacy) is supported, otherwise excluded.'

Quoted 1 line

I think the best option is to add it to Set Device Flags and let bluetoothd set it on a per device basis like it does with the wakeup flag.

Got it, I guess

Quoted 1 line

Trying to tie it to the Limited Privacy mode seems weird. Since that is for discoverability and this is for outgoing connections.

Hmm, I'm afraid this wouldn't follow the spec to the letter then since it doesn't actually split Incoming/advertising and Outgoing/scanning privacy, it does seems to be global so if we go with different settings to control each direction separately we may end up with a custom mode e.g: limited discoverability for advertising vs network privacy mode for scanning, for instance limited discoverability does blast the public address while discoverable and bondable but both privacy modes seems to require the use of RPA, anyway it would probably be a good idea to document the interactions, also main.conf seem to have gone with privacy from the specification so we may either need add more modes:

Privacy:
"on"/"network": Apply Network Privacy Mode both for advertising and scanning "limited-network": Apply Limited Discoverable Mode to advertising and Network Privacy Mode for scanning
"device": Apply Device Privacy Mode both for advertising and scanning "limited-device": Apply Limited Discoverable Mode to advertising and Device Privacy Mode for scanning

Signature · 1 line
Luiz Augusto von Dentz
maintainer
#3 lore raw

Hi Luiz,

Quoted 67 lines
Quoted 58 lines
Quoted 58 lines

This adds support for Set Privacy Mode when updating the resolving list when HCI_LIMITED_PRIVACY so the controller shall use Device Mode for devices programmed in the resolving list, Device Mode is actually required when the remote device are not able to use RPA as otherwise the default mode is Network Privacy Mode in which only RPA are allowed thus the controller would filter out advertisement using the identity address for which there is an IRK.

---
include/net/bluetooth/hci.h | 7 ++++++
net/bluetooth/hci_sync.c | 48 ++++++++++++++++++++++++++++++++-----

2 files changed, 49 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +7 -0
index 63065bc01b76..aa856dfd5b9f 100644
@@ -1930,6 +1930,13 @@ struct hci_rp_le_read_transmit_power {
     __s8  max_le_tx_power;
 } __packed;
 
+#define HCI_OP_LE_SET_PRIVACY_MODE   0x204e
+struct hci_cp_le_set_privacy_mode {
+     __u8  bdaddr_type;
+     bdaddr_t  bdaddr;
+     __u8  mode;
+} __packed;
+
 #define HCI_OP_LE_READ_BUFFER_SIZE_V2 0x2060
 struct hci_rp_le_read_buffer_size_v2 {
     __u8    status;
net/bluetooth/hci_sync.c +18 -0
index b794605dc882..43173d645436 100644
@@ -1580,8 +1580,37 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev,
                                  sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
 
+/* Set Device Privacy Mode. */
+static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev,
+                                     struct hci_conn_params *params)
+{
+     struct hci_cp_le_set_privacy_mode cp;
+     struct smp_irk *irk;
+
+     /* Set Privacy Mode requires the use of resolving list (aka. LL Privacy)
+      * by default Network Mode is used so only really send the command if
+      * Device Mode is required (HCI_LIMITED_PRIVACY).
+      */
+     if (!use_ll_privacy(hdev) ||
+         !hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY))
+             return 0;
+
+     irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type);
+     if (!irk)
+             return 0;
Quoted 8 lines

net/bluetooth/hci_sync.c static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, · line 1606

Quoted 6 lines
net/bluetooth/hci_sync.c +6 -0
+
+     memset(&cp, 0, sizeof(cp));
+     cp.bdaddr_type = irk->addr_type;
+     bacpy(&cp.bdaddr, &irk->bdaddr);
+     cp.mode = 0x01;
+

you need to check if this command is actually supported.

Quoted 3 lines

The spec suggests it is mandatory if LL Privacy is supported:

'C9: Mandatory if LE Feature (LL Privacy) is supported, otherwise excluded.'

and what about Bluetooth 4.2 spec. devices? Not all earlier specs have both features.

Quoted 3 lines
Quoted 1 line

I think the best option is to add it to Set Device Flags and let bluetoothd set it on a per device basis like it does with the wakeup flag.

Got it, I guess

I prefer Set Device Flags since with Get Device Flags you can indicate if this is supported or not.

Quoted 14 lines
Quoted 1 line

Trying to tie it to the Limited Privacy mode seems weird. Since that is for discoverability and this is for outgoing connections.

Hmm, I'm afraid this wouldn't follow the spec to the letter then since it doesn't actually split Incoming/advertising and Outgoing/scanning privacy, it does seems to be global so if we go with different settings to control each direction separately we may end up with a custom mode e.g: limited discoverability for advertising vs network privacy mode for scanning, for instance limited discoverability does blast the public address while discoverable and bondable but both privacy modes seems to require the use of RPA, anyway it would probably be a good idea to document the interactions, also main.conf seem to have gone with privacy from the specification so we may either need add more modes:

Quoted 7 lines

Privacy:
"on"/"network": Apply Network Privacy Mode both for advertising and scanning "limited-network": Apply Limited Discoverable Mode to advertising and Network Privacy Mode for scanning
"device": Apply Device Privacy Mode both for advertising and scanning "limited-device": Apply Limited Discoverable Mode to advertising and Device Privacy Mode for scanning

Then we can do that and use Limited Privacy mode for exactly that. However in addition I would use the Set Device Flags to allow punching holes for specific devices.

Regards

Marcel

author maintainer
#4 lore raw

Hi Marcel,

Quoted 70 lines · Marcel Holtmann

Hi Luiz,

Quoted 67 lines
Quoted 66 lines
Quoted 54 lines

This adds support for Set Privacy Mode when updating the resolving list when HCI_LIMITED_PRIVACY so the controller shall use Device Mode for devices programmed in the resolving list, Device Mode is actually required when the remote device are not able to use RPA as otherwise the default mode is Network Privacy Mode in which only RPA are allowed thus the controller would filter out advertisement using the identity address for which there is an IRK.

---
include/net/bluetooth/hci.h | 7 ++++++
net/bluetooth/hci_sync.c | 48 ++++++++++++++++++++++++++++++++-----

2 files changed, 49 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +7 -0
index 63065bc01b76..aa856dfd5b9f 100644
@@ -1930,6 +1930,13 @@ struct hci_rp_le_read_transmit_power {
     __s8  max_le_tx_power;
 } __packed;
 
+#define HCI_OP_LE_SET_PRIVACY_MODE   0x204e
+struct hci_cp_le_set_privacy_mode {
+     __u8  bdaddr_type;
+     bdaddr_t  bdaddr;
+     __u8  mode;
+} __packed;
+
 #define HCI_OP_LE_READ_BUFFER_SIZE_V2 0x2060
 struct hci_rp_le_read_buffer_size_v2 {
     __u8    status;
net/bluetooth/hci_sync.c +14 -0
index b794605dc882..43173d645436 100644
@@ -1580,8 +1580,37 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev,
                                  sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
 
+/* Set Device Privacy Mode. */
+static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev,
+                                     struct hci_conn_params *params)
+{
+     struct hci_cp_le_set_privacy_mode cp;
+     struct smp_irk *irk;
+
+     /* Set Privacy Mode requires the use of resolving list (aka. LL Privacy)
+      * by default Network Mode is used so only really send the command if
+      * Device Mode is required (HCI_LIMITED_PRIVACY).
+      */
+     if (!use_ll_privacy(hdev) ||
+         !hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY))
+             return 0;

net/bluetooth/hci_sync.c static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, · line 1606

Quoted 10 lines
net/bluetooth/hci_sync.c +10 -0
+
+     irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type);
+     if (!irk)
+             return 0;
+
+     memset(&cp, 0, sizeof(cp));
+     cp.bdaddr_type = irk->addr_type;
+     bacpy(&cp.bdaddr, &irk->bdaddr);
+     cp.mode = 0x01;
+

you need to check if this command is actually supported.

Quoted 5 lines
Quoted 3 lines

The spec suggests it is mandatory if LL Privacy is supported:

'C9: Mandatory if LE Feature (LL Privacy) is supported, otherwise excluded.'

and what about Bluetooth 4.2 spec. devices? Not all earlier specs have both features.

Right looks like Privacy Mode was introduced in 5.0 but LL Privacy was already part of 4.2, so I guess we will need to check if the command is really supported after all.

Quoted 28 lines
Quoted 3 lines
Quoted 1 line

I think the best option is to add it to Set Device Flags and let bluetoothd set it on a per device basis like it does with the wakeup flag.

Got it, I guess

I prefer Set Device Flags since with Get Device Flags you can indicate if this is supported or not.

Quoted 14 lines
Quoted 1 line

Trying to tie it to the Limited Privacy mode seems weird. Since that is for discoverability and this is for outgoing connections.

Hmm, I'm afraid this wouldn't follow the spec to the letter then since it doesn't actually split Incoming/advertising and Outgoing/scanning privacy, it does seems to be global so if we go with different settings to control each direction separately we may end up with a custom mode e.g: limited discoverability for advertising vs network privacy mode for scanning, for instance limited discoverability does blast the public address while discoverable and bondable but both privacy modes seems to require the use of RPA, anyway it would probably be a good idea to document the interactions, also main.conf seem to have gone with privacy from the specification so we may either need add more modes:

Quoted 7 lines

Privacy:
"on"/"network": Apply Network Privacy Mode both for advertising and scanning "limited-network": Apply Limited Discoverable Mode to advertising and Network Privacy Mode for scanning
"device": Apply Device Privacy Mode both for advertising and scanning "limited-device": Apply Limited Discoverable Mode to advertising and Device Privacy Mode for scanning

Quoted 1 line

Then we can do that and use Limited Privacy mode for exactly that. However in addition I would use the Set Device Flags to allow punching holes for specific devices.

Yep, I actually realized that the reason we have limited privacy as a mode for LE is that on dual-mode while discoverable it would already blast the address over BR/EDR, so we might as well only allow the use of limited-* modes on dual mode.

Quoted 4 lines

Regards

Marcel

Signature · 1 line
Luiz Augusto von Dentz