btdev: Add support for LE Set Privacy mode
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/6 btdev: Add support for LE Set Privacy mode
From: Luiz Augusto von Dentz <[email protected]>
This adds support for LE Set Privacy mode which is required when using Device Privacy mode:
< HCI Command: LE Set Priva.. (0x08|0x004e) plen 8
Peer Identity address type: Public (0x00)
Peer Identity address: BC:9A:78:56:34:12 (OUI BC-9A-78)
Privacy Mode: Use Device Privacy (0x01)Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4
LE Set Privacy Mode (0x08|0x004e) ncmd 1 --- emulator/btdev.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
emulator/btdev.c +46 -1
@@ -72,6 +72,7 @@ struct btdev_al {struct btdev_rl {uint8_t type;bdaddr_t addr; +uint8_t mode;uint8_t peer_irk[16 ];uint8_t local_irk[16 ]; };
@@ -5336,6 +5337,48 @@ static int cmd_read_tx_power(struct btdev *dev, const void *data, uint8_t len)return 0 ; } +static int cmd_set_privacy_mode (struct btdev *dev,const void *data, +uint8_t len) +{ +const struct bt_hci_cmd_le_set_priv_mode *cmd = data; +const struct btdev_rl *rl; +uint8_t status; + +/* This command shall not be used when address resolution is enabled in +* the Controller and: +* • Advertising (other than periodic advertising) is enabled, +* • Scanning is enabled, or +* • an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, +* or HCI_LE_Periodic_Advertising_Create_Sync command is pending. +*/ +if (dev->le_rl_enable || dev->le_adv_enable || dev->le_scan_enable) { + status =BT_HCI_ERR_COMMAND_DISALLOWED ; + goto done; + } + +/* If the device is not on the resolving list, the Controller shall +* return the error code Unknown Connection Identifier (0x02). +*/ + rl =rl_find (dev, cmd->peer_id_addr_type, cmd->peer_id_addr); +if (!rl) { + status =BT_HCI_ERR_UNKNOWN_CONN_ID ; + goto done; + } + +if (cmd->priv_mode >0x01 ) { + status =BT_HCI_ERR_INVALID_PARAMETERS ; + goto done; + } + + ((struct btdev_rl *)rl)->mode = cmd->priv_mode; + status =BT_HCI_ERR_SUCCESS ; + +done: +cmd_complete (dev,BT_HCI_CMD_LE_SET_PRIV_MODE , &status,sizeof (status)); + +return 0 ; +} +#define CMD_LE_50 \ CMD(BT_HCI_CMD_LE_SET_DEFAULT_PHY, cmd_set_default_phy, NULL), \ CMD(BT_HCI_CMD_LE_SET_ADV_SET_RAND_ADDR, cmd_set_adv_rand_addr, NULL), \
@@ -5372,7 +5415,8 @@ static int cmd_read_tx_power(struct btdev *dev, const void *data, uint8_t len)CMD (BT_HCI_CMD_LE_CLEAR_PERIODIC_ADV_LIST , cmd_per_adv_clear,NULL ), \CMD (BT_HCI_CMD_LE_READ_PERIODIC_ADV_LIST_SIZE , \ cmd_read_per_adv_list_size,NULL ), \ - CMD(BT_HCI_CMD_LE_READ_TX_POWER, cmd_read_tx_power, NULL) +CMD (BT_HCI_CMD_LE_READ_TX_POWER , cmd_read_tx_power,NULL ), \ + CMD(BT_HCI_CMD_LE_SET_PRIV_MODE, cmd_set_privacy_mode, NULL)static const struct btdev_cmd cmd_le_5_0[] = {CMD_COMMON_ALL ,
@@ -5408,6 +5452,7 @@ static void set_le_50_commands(struct btdev *btdev) btdev->commands[38 ] |=0x20 ;/* LE Clear Periodic Adv List */ btdev->commands[38 ] |=0x40 ;/* LE Read Periodic Adv List Size */ btdev->commands[38 ] |=0x80 ;/* LE Read Transmit Power */ + btdev->commands[39 ] |=0x04 ;/* LE Set Privacy Mode */ btdev->cmds = cmd_le_5_0; }
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 2/6 mgmt-api: Add new Device Flag to use Device Privacy Mode
From: Luiz Augusto von Dentz <[email protected]>
This adds a new flag to Get/Set Device Flag commands so it is possible to set the Device Privacy Mode which allows to connect when the remote device uses either identity or random address.
--- doc/mgmt-api.txt | 1 + 1 file changed, 1 insertion(+)
doc/mgmt-api.txt +1 -0
@@ -3421,6 +3421,7 @@ Get Device Flags Command available bits: 0 Remote Wakeup enabled + 1 Device Privacy Mode enabled This command generates a Command Complete event on success or a Command Status event on failure.
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode
Hi Marcel,
Quoted 23 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds a new flag to Get/Set Device Flag commands so it is possible to set the Device Privacy Mode which allows to connect when the remote device uses either identity or random address.
--- doc/mgmt-api.txt | 1 + 1 file changed, 1 insertion(+)doc/mgmt-api.txt +1
-1@@ -3421,6 +3421,7 @@ Get Device Flags Command available bits: 0 Remote Wakeup enabled + 1 Device Privacy Mode enabled This command generates a Command Complete event on success or a Command Status event on failure. --
Quoted 1 line
2.31.1
Any comments on this? I'd like to apply it if that's ok with you.
Signature · 1 line
Luiz Augusto von Dentz
Marcel Holtmann
maintainerRe: [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode
Hi Luiz,
Quoted 17 lines
Quoted 17 lines
This adds a new flag to Get/Set Device Flag commands so it is possible to set the Device Privacy Mode which allows to connect when the remote device uses either identity or random address.
---doc/mgmt-api.txt| 1 +1 file changed, 1 insertion(+)doc/mgmt-api.txt +1
-0@@ -3421,6 +3421,7 @@ Get Device Flags Command available bits: 0 Remote Wakeup enabled + 1 Device Privacy Mode enabled
Quoted 6 lines
Quoted 4 lines
doc/mgmt-api.txt +0
-1This command generates a Command Complete event on success or a Command Status event on failure. --2.31.1
Any comments on this? I'd like to apply it if that's ok with you.
just go ahead with this.
Regards
Marcel
Luiz Augusto von Dentz
maintainerPATCH 3/6 main.conf: Rework privacy options
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This reworks privacy options so the limited discoverable is only available when controller mode is set to dual.
--- src/btd.h | 1 + src/main.c | 22 ++++++++++++++++++---- src/main.conf | 25 ++++++++++++++++++++----- 3 files changed, 39 insertions(+), 9 deletions(-)
src/btd.h +1 -0
@@ -103,6 +103,7 @@ struct btd_opts {uint32_t discovto;uint32_t tmpto;uint8_t privacy; +bool device_privacy;struct btd_defaults defaults;
src/main.c +18 -4
@@ -666,13 +666,27 @@ static void parse_config(GKeyFile *config) }else {DBG ("privacy=%s" , str); -if (!strcmp (str,"network" ) || !strcmp (str,"on" )) +if (!strcmp (str,"network" ) || !strcmp (str,"on" )) { btd_opts.privacy =0x01 ; -if (!strcmp (str,"device" ) || !strcmp (str,"limited" )) + }else if (!strcmp (str,"device" )) { + btd_opts.privacy =0x01 ; + btd_opts.device_privacy = true; + }else if (!strcmp (str,"limited-network" )) { +if (btd_opts.mode !=BT_MODE_DUAL ) { +DBG ("Invalid privacy option: %s" , str); + btd_opts.privacy =0x00 ; + } + btd_opts.privacy =0x01 ; + }else if (!strcmp (str,"limited-device" )) { +if (btd_opts.mode !=BT_MODE_DUAL ) { +DBG ("Invalid privacy option: %s" , str); + btd_opts.privacy =0x00 ; + } btd_opts.privacy =0x02 ; -else if (!strcmp (str,"off" )) + btd_opts.device_privacy = true; + }else if (!strcmp (str,"off" )) { btd_opts.privacy =0x00 ; -else { + }else {DBG ("Invalid privacy option: %s" , str); btd_opts.privacy =0x00 ; }
src/main.conf +20 -5
@@ -67,14 +67,29 @@ # Default privacy setting. # Enables use of private address. -# Possible values: "off", "network/on", "device/limited" -# "network/on": a device will only accept advertising packets from peer devices -# that contain private addresses. It may not be compatible with some legacy -# devices since it requires the use of RPA(s) all the time. -# "device/limited": A device in device privacy mode is only concerned about the +# Possible values for LE mode: "off", "network/on", "device" +# Possible values for Dual mode: "off", "network/on", "device", +# "limited-network", "limited-device" +# +# - off: Local privacy disabled. +# +# - network/on: A device will only accept advertising packets from peer +# devices that contain private addresses. It may not be compatible with some +# legacy devices since it requires the use of RPA(s) all the time. +# +# - device: A device in device privacy mode is only concerned about the # privacy of the device and will accept advertising packets from peer devices # that contain their Identity Address as well as ones that contain a private # address, even if the peer device has distributed its IRK in the past. + +# - limited-network: Apply Limited Discoverable Mode to advertising, which +# follows the same policy as to BR/EDR that publishes the identity address when +# discoverable, and Network Privacy Mode for scanning. +# +# - limited-device: Apply Limited Discoverable Mode to advertising, which +# follows the same policy as to BR/EDR that publishes the identity address when +# discoverable, and Device Privacy Mode for scanning. +# # Defaults to "off" #Privacy = off
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 4/6 adapter: Set Device Privacy Mode
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds support for setting Device Privacy flag when enabled in main.conf via Privacy = device,limited-device.
--- lib/mgmt.h | 3 +- src/adapter.c | 76 +++++++++++++++++++++++---------------------------- src/adapter.h | 9 ++++-- src/device.c | 58 +++++++++++++++++++++++++++++---------- src/device.h | 1 - 5 files changed, 86 insertions(+), 61 deletions(-)
lib/mgmt.h +2 -1
@@ -665,7 +665,8 @@ struct mgmt_rp_get_device_flags {uint32_t current_flags; } __packed; -#define DEVICE_FLAG_REMOTE_WAKEUP (1 << 0) +#define DEVICE_FLAG_REMOTE_WAKEUP BIT(0) +#define DEVICE_FLAG_DEVICE_PRIVACY BIT(1)#define MGMT_OP_SET_DEVICE_FLAGS 0x0050#define MGMT_SET_DEVICE_FLAGS_SIZE 11
src/adapter.c +34 -42
102 lines not on this page · raw message
src/adapter.h +7 -2
@@ -219,8 +219,13 @@ int adapter_connect_list_add(struct btd_adapter *adapter, struct btd_device *device);void adapter_connect_list_remove (struct btd_adapter *adapter,struct btd_device *device); -void adapter_set_device_wakeable (struct btd_adapter *adapter, -struct btd_device *dev,bool wakeable); +typedef void (*adapter_set_device_flags_func_t )(uint8_t status,uint16_t length, +const void *param, +void *user_data); +void adapter_set_device_flags (struct btd_adapter *adapter, +struct btd_device *device,uint32_t flags, +adapter_set_device_flags_func_t func, +void *user_data);void adapter_auto_connect_add (struct btd_adapter *adapter,struct btd_device *device); void adapter_auto_connect_remove(struct btd_adapter *adapter,
src/device.c +43 -15
77 lines not on this page · raw message
src/device.h +0 -1
@@ -132,7 +132,6 @@ void device_set_wake_support(struct btd_device *device, bool wake_support);void device_set_wake_override (struct btd_device *device,bool wake_override);void device_set_wake_allowed (struct btd_device *device,bool wake_allowed,guint32 id); -void device_set_wake_allowed_complete (struct btd_device *device);void device_set_refresh_discovery (struct btd_device *dev,bool refresh); typedef void (*disconnect_watch) (struct btd_device *device, gboolean removal,
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 5/6 monitor: Add support for Device Privacy Mode flag
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds proper decoding for Device Privacy Mode flag:
@ MGMT Command: Set Device... (0x0050) plen 11 {0x0001}
LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
Current Flags: 0x00000002
Device Privacy Mode
@ MGMT Event: Device Flags... (0x002a) plen 15 {0x0002}
LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
Supported Flags: 0x00000003
Remote Wakeup
Device Privacy Mode
Current Flags: 0x00000002
Device Privacy Mode
---
monitor/packet.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)monitor/packet.c +2 -1
@@ -13378,7 +13378,8 @@ static void mgmt_set_exp_feature_rsp(const void *data, uint16_t size) }static const struct bitfield_data mgmt_added_device_flags_table[] = { - {0 ,"Remote Wakeup" }, + {0 ,"Remote Wakeup" }, + {1 ,"Device Privacy Mode" }, { } };
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 6/6 mgmt-tester: Add test for Device Privacy Mode flag
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This tests the use of Set Device Flags to set Device Privacy Mode which results in the following sequence:
@ MGMT Event: Command Compl.. (0x0001) plen 10 {0x0001}
Set Device Flags (0x0050) plen 7
Status: Success (0x00)
LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
< HCI Command: LE Set Exten.. (0x08|0x0042) plen 6
Extended scan: Disabled (0x00)
Filter duplicates: Disabled (0x00)
Duration: 0 msec (0x0000)
Period: 0.00 sec (0x0000)= mgmt-tester: Set Device Flags (0x0050): Success (0x00) = mgmt-tester: Test condition complete, 4 left = mgmt-tester: New Device Flags Changed event received = mgmt-tester: Test condition complete, 3 left
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4
LE Set Extended Scan Enable (0x08|0x0042) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Addre.. (0x08|0x002d) plen 1
Address resolution: Disabled (0x00)= mgmt-tester: HCI Command 0x2042 length 6
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4
LE Set Address Resolution Enable (0x08|0x002d) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Priva.. (0x08|0x004e) plen 8
Peer Identity address type: Public (0x00)
Peer Identity address: BC:9A:78:56:34:12 (OUI BC-9A-78)
Privacy Mode: Use Device Privacy (0x01)= mgmt-tester: HCI Command 0x202d length 1
= mgmt-tester: Test condition complete, 2 left
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4
LE Set Privacy Mode (0x08|0x004e) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Addre.. (0x08|0x002d) plen 1
Address resolution: Enabled (0x01)= mgmt-tester: HCI Command 0x204e length 8
= mgmt-tester: Test condition complete, 1 left
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4
LE Set Address Resolution Enable (0x08|0x002d) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Exten.. (0x08|0x0041) plen 8
Own address type: Random (0x03)
Filter policy: Ignore not in accept list (0x01)
PHYs: 0x01
Entry 0: LE 1M
Type: Passive (0x00)
Interval: 60.000 msec (0x0060)
Window: 30.000 msec (0x0030)
= mgmt-tester: HCI Command 0x202d length 1
= mgmt-tester: Test condition complete, 0 left
---
tools/mgmt-tester.c | 88 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)tools/mgmt-tester.c +88 -0
@@ -10578,6 +10578,63 @@ static const struct generic_data ll_privacy_unpair_2 = { .expect_hci_len = sizeof(add_to_al_client), }; +static const uint8_t set_device_flags_param_1[] = { +0x12 ,0x34 ,0x56 ,0x78 ,0x9a ,0xbc ,/* BDADDR */ +0x01 ,/* Type - LE Public */ +0x02 ,0x00 ,0x00 ,0x00 /* Flags - Device Privacy */ +}; + +static const uint8_t set_device_flags_rsp[] = { +0x12 ,0x34 ,0x56 ,0x78 ,0x9a ,0xbc ,/* BDADDR */ +0x01 /* Type - LE Public */ +}; + +static const uint8_t le_set_priv_mode_param[] = { +0x00 ,/* Type */ +0x12 ,0x34 ,0x56 ,0x78 ,0x9a ,0xbc ,/* BDADDR */ +0x01 /* Privacy Mode */ +}; + +static const struct hci_cmd_data ll_privacy_set_device_flags_1_hci_list[] = { + { + .opcode =BT_HCI_CMD_LE_SET_RESOLV_ENABLE , + .param = set_resolv_off_param, + .len =sizeof (set_resolv_off_param), + }, + { + .opcode =BT_HCI_CMD_LE_SET_PRIV_MODE , + .param = le_set_priv_mode_param, + .len =sizeof (le_set_priv_mode_param), + }, + { + .opcode =BT_HCI_CMD_LE_SET_RESOLV_ENABLE , + .param = set_resolv_on_param, + .len =sizeof (set_resolv_on_param), + }, +}; + +static const uint8_t device_flags_changed_params_1[] = { +0x12 ,0x34 ,0x56 ,0x78 ,0x9a ,0xbc ,/* BDADDR */ +0x01 ,/* Type - LE Public */ +0x03 ,0x00 ,0x00 ,0x00 ,/* Supported Flags */ +0x02 ,0x00 ,0x00 ,0x00 /* Current Flags */ +}; + +static const struct generic_data ll_privacy_set_device_flag_1 = { + .setup_settings = settings_le_privacy_ll_privacy, + .setup_exp_feat_param = set_exp_feat_param_ll_privacy, + .send_opcode =MGMT_OP_SET_DEVICE_FLAGS , + .send_param = set_device_flags_param_1, + .send_len =sizeof (set_device_flags_param_1), + .expect_param = set_device_flags_rsp, + .expect_len =sizeof (set_device_flags_rsp), + .expect_status =MGMT_STATUS_SUCCESS , + .expect_alt_ev =MGMT_EV_DEVICE_FLAGS_CHANGED , + .expect_alt_ev_param = device_flags_changed_params_1, + .expect_alt_ev_len =sizeof (device_flags_changed_params_1), + .expect_hci_list = ll_privacy_set_device_flags_1_hci_list, +}; +static void setup_load_irks_callback (uint8_t status,uint16_t length,const void *param,void *user_data) {
@@ -11085,6 +11142,27 @@ static void setup_ll_privacy_add_adv(const void *test_data) setup_powered_callback, NULL, NULL); } +static void setup_ll_privacy_add_device (const void *test_data) +{ +struct test_data *data =tester_get_data (); +unsigned char param[] = {0x01 }; + +mgmt_send (data->mgmt,MGMT_OP_LOAD_IRKS , data->mgmt_index, +sizeof (load_irks_le_public_param_1), + load_irks_le_public_param_1, + setup_load_irks_callback,NULL ,NULL ); + +mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index, +sizeof (param), param, + setup_powered_callback,NULL ,NULL ); + +mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index, +sizeof (add_device_le_public_param_1), + add_device_le_public_param_1, + setup_add_device_callback,NULL ,NULL ); + +} +static bool power_off (uint16_t index) {int sk, err;
@@ -14406,5 +14484,15 @@ int main(int argc, char *argv[])NULL , test_ll_privacy_unpair_2, 5); +/* LL Privacy +* Setup: Enable LL Privacy, add IRK of new device, Add Device +* Run: Set Device Flags +* Expect: Device Privacy Mode is set. +*/ +test_bredrle50 ("LL Privacy - Set Device Flag 1 (Device Privacy)" , + &ll_privacy_set_device_flag_1, + setup_ll_privacy_add_device, + test_command_generic); +return tester_run (); }
Signature · 1 line
2.31.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=576261
---Test result---
Test Summary:
CheckPatch PASS 9.31 seconds GitLint PASS 6.26 seconds Prep - Setup ELL PASS 48.36 seconds Build - Prep PASS 0.55 seconds Build - Configure PASS 9.27 seconds Build - Make PASS 210.26 seconds Make Check PASS 9.43 seconds Make Distcheck PASS 251.47 seconds Build w/ext ELL - Configure PASS 9.52 seconds Build w/ext ELL - Make PASS 200.26 seconds
---
Regards,
Linux Bluetooth
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=576261
---Test result---
Test Summary:
CheckPatch PASS 3.26 seconds GitLint PASS 1.89 seconds Prep - Setup ELL PASS 52.41 seconds Build - Prep PASS 0.26 seconds Build - Configure PASS 9.43 seconds Build - Make PASS 224.72 seconds Make Check PASS 9.45 seconds Make Distcheck PASS 261.29 seconds Build w/ext ELL - Configure PASS 9.39 seconds Build w/ext ELL - Make PASS 210.38 seconds
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi,
Quoted 25 lines · On Wed, Nov 10, 2021 at 10:40 AM <[email protected]> wrote:
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=576261---Test result---
Test Summary:
CheckPatch PASS 3.26 seconds GitLint PASS 1.89 seconds Prep - Setup ELL PASS 52.41 seconds Build - Prep PASS 0.26 seconds Build - Configure PASS 9.43 seconds Build - Make PASS 224.72 seconds Make Check PASS 9.45 seconds Make Distcheck PASS 261.29 seconds Build w/ext ELL - Configure PASS 9.39 seconds Build w/ext ELL - Make PASS 210.38 seconds
Quoted 3 lines
---
Regards,
Linux Bluetooth
Pushed.
Signature · 1 line
Luiz Augusto von Dentz