linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode
@ 2021-11-05 21:12 Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode Luiz Augusto von Dentz
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-05 21:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 7b311f347..72ce21517 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -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;
 }
 
-- 
2.31.1


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

* [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
@ 2021-11-05 21:12 ` Luiz Augusto von Dentz
  2021-11-09 22:22   ` Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 3/6] main.conf: Rework privacy options Luiz Augusto von Dentz
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-05 21:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 97d33e30a..b7a152c14 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -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.
-- 
2.31.1


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

* [PATCH BlueZ 3/6] main.conf: Rework privacy options
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode Luiz Augusto von Dentz
@ 2021-11-05 21:12 ` Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 4/6] adapter: Set Device Privacy Mode Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-05 21:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/src/btd.h b/src/btd.h
index f83591f8f..ff9f082f1 100644
--- a/src/btd.h
+++ b/src/btd.h
@@ -103,6 +103,7 @@ struct btd_opts {
 	uint32_t	discovto;
 	uint32_t	tmpto;
 	uint8_t		privacy;
+	bool		device_privacy;
 
 	struct btd_defaults defaults;
 
diff --git a/src/main.c b/src/main.c
index 2835c81b2..dd954e1ab 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
 		}
diff --git a/src/main.conf b/src/main.conf
index 4019ea903..c82d7e648 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -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
 
-- 
2.31.1


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

* [PATCH BlueZ 4/6] adapter: Set Device Privacy Mode
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 3/6] main.conf: Rework privacy options Luiz Augusto von Dentz
@ 2021-11-05 21:12 ` Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 5/6] monitor: Add support for Device Privacy Mode flag Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-05 21:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 0d1678f01..400167e9b 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -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
diff --git a/src/adapter.c b/src/adapter.c
index 508917e58..309956bbb 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -5308,6 +5308,23 @@ void adapter_accept_list_remove(struct btd_adapter *adapter,
 				remove_accept_list_complete, adapter, NULL);
 }
 
+static void set_device_privacy_complete(uint8_t status, uint16_t length,
+					 const void *param, void *user_data)
+{
+	const struct mgmt_rp_set_device_flags *rp = param;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Set device flags return status: %s",
+					mgmt_errstr(status));
+		return;
+	}
+
+	if (length < sizeof(*rp)) {
+		error("Too small Set Device Flags complete event: %d", length);
+		return;
+	}
+}
+
 static void add_device_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -5342,6 +5359,18 @@ static void add_device_complete(uint8_t status, uint16_t length,
 	}
 
 	DBG("%s (%u) added to kernel connect list", addr, rp->addr.type);
+
+	if (btd_opts.device_privacy) {
+		uint32_t flags = btd_device_get_current_flags(dev);
+
+		/* Set Device Privacy Mode has not set the flag yet. */
+		if (!(flags & DEVICE_FLAG_DEVICE_PRIVACY)) {
+			adapter_set_device_flags(adapter, dev, flags |
+						DEVICE_FLAG_DEVICE_PRIVACY,
+						set_device_privacy_complete,
+						NULL);
+		}
+	}
 }
 
 void adapter_auto_connect_add(struct btd_adapter *adapter,
@@ -5383,42 +5412,9 @@ void adapter_auto_connect_add(struct btd_adapter *adapter,
 	adapter->connect_list = g_slist_append(adapter->connect_list, device);
 }
 
-static void set_device_wakeable_complete(uint8_t status, uint16_t length,
-					 const void *param, void *user_data)
-{
-	const struct mgmt_rp_set_device_flags *rp = param;
-	struct btd_adapter *adapter = user_data;
-	struct btd_device *dev;
-	char addr[18];
-
-	if (status != MGMT_STATUS_SUCCESS) {
-		btd_error(adapter->dev_id, "Set device flags return status: %s",
-			  mgmt_errstr(status));
-		return;
-	}
-
-	if (length < sizeof(*rp)) {
-		btd_error(adapter->dev_id,
-			  "Too small Set Device Flags complete event: %d",
-			  length);
-		return;
-	}
-
-	ba2str(&rp->addr.bdaddr, addr);
-
-	dev = btd_adapter_find_device(adapter, &rp->addr.bdaddr, rp->addr.type);
-	if (!dev) {
-		btd_error(adapter->dev_id,
-			  "Set Device Flags complete for unknown device %s",
-			  addr);
-		return;
-	}
-
-	device_set_wake_allowed_complete(dev);
-}
-
-void adapter_set_device_wakeable(struct btd_adapter *adapter,
-				 struct btd_device *device, bool wakeable)
+void adapter_set_device_flags(struct btd_adapter *adapter,
+				struct btd_device *device, uint32_t flags,
+				mgmt_request_func_t func, void *user_data)
 {
 	struct mgmt_cp_set_device_flags cp;
 	const bdaddr_t *bdaddr;
@@ -5433,14 +5429,10 @@ void adapter_set_device_wakeable(struct btd_adapter *adapter,
 	memset(&cp, 0, sizeof(cp));
 	bacpy(&cp.addr.bdaddr, bdaddr);
 	cp.addr.type = bdaddr_type;
-	cp.current_flags = btd_device_get_current_flags(device);
-	if (wakeable)
-		cp.current_flags |= DEVICE_FLAG_REMOTE_WAKEUP;
-	else
-		cp.current_flags &= ~DEVICE_FLAG_REMOTE_WAKEUP;
+	cp.current_flags = cpu_to_le32(flags);
 
 	mgmt_send(adapter->mgmt, MGMT_OP_SET_DEVICE_FLAGS, adapter->dev_id,
-		  sizeof(cp), &cp, set_device_wakeable_complete, adapter, NULL);
+		  sizeof(cp), &cp, func, user_data, NULL);
 }
 
 static void device_flags_changed_callback(uint16_t index, uint16_t length,
diff --git a/src/adapter.h b/src/adapter.h
index db3c17f23..d191daf5d 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -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,
diff --git a/src/device.c b/src/device.c
index 1b4dae685..6b398bd39 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1403,9 +1403,45 @@ void device_set_wake_override(struct btd_device *device, bool wake_override)
 	}
 }
 
+static void device_set_wake_allowed_complete(struct btd_device *device)
+{
+	if (device->wake_id != -1U) {
+		g_dbus_pending_property_success(device->wake_id);
+		device->wake_id = -1U;
+	}
+
+	device->wake_allowed = device->pending_wake_allowed;
+	g_dbus_emit_property_changed(dbus_conn, device->path,
+					DEVICE_INTERFACE, "WakeAllowed");
+
+	store_device_info(device);
+}
+
+static void set_wake_allowed_complete(uint8_t status, uint16_t length,
+					 const void *param, void *user_data)
+{
+	const struct mgmt_rp_set_device_flags *rp = param;
+	struct btd_device *dev = user_data;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Set device flags return status: %s",
+					mgmt_errstr(status));
+		return;
+	}
+
+	if (length < sizeof(*rp)) {
+		error("Too small Set Device Flags complete event: %d", length);
+		return;
+	}
+
+	device_set_wake_allowed_complete(dev);
+}
+
 void device_set_wake_allowed(struct btd_device *device, bool wake_allowed,
 			     GDBusPendingPropertySet id)
 {
+	uint32_t flags;
+
 	/* Pending and current value are the same unless there is a change in
 	 * progress. Only update wake allowed if pending value doesn't match the
 	 * new value.
@@ -1415,25 +1451,17 @@ void device_set_wake_allowed(struct btd_device *device, bool wake_allowed,
 
 	device->wake_id = id;
 	device->pending_wake_allowed = wake_allowed;
-	adapter_set_device_wakeable(device_get_adapter(device), device,
-				    wake_allowed);
-}
 
-void device_set_wake_allowed_complete(struct btd_device *device)
-{
-	if (device->wake_id != -1U) {
-		g_dbus_pending_property_success(device->wake_id);
-		device->wake_id = -1U;
-	}
-
-	device->wake_allowed = device->pending_wake_allowed;
-	g_dbus_emit_property_changed(dbus_conn, device->path,
-					DEVICE_INTERFACE, "WakeAllowed");
+	flags = device->current_flags;
+	if (wake_allowed)
+		flags |= DEVICE_FLAG_REMOTE_WAKEUP;
+	else
+		flags &= ~DEVICE_FLAG_REMOTE_WAKEUP;
 
-	store_device_info(device);
+	adapter_set_device_flags(device->adapter, device, flags,
+					set_wake_allowed_complete, device);
 }
 
-
 static gboolean
 dev_property_get_wake_allowed(const GDBusPropertyTable *property,
 			     DBusMessageIter *iter, void *data)
diff --git a/src/device.h b/src/device.h
index 5f615cb4b..b37a0a3d2 100644
--- a/src/device.h
+++ b/src/device.h
@@ -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,
-- 
2.31.1


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

* [PATCH BlueZ 5/6] monitor: Add support for Device Privacy Mode flag
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2021-11-05 21:12 ` [PATCH BlueZ 4/6] adapter: Set Device Privacy Mode Luiz Augusto von Dentz
@ 2021-11-05 21:12 ` Luiz Augusto von Dentz
  2021-11-05 21:12 ` [PATCH BlueZ 6/6] mgmt-tester: Add test " Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-05 21:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/monitor/packet.c b/monitor/packet.c
index 9030f2493..71f711dc5 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -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"	},
 	{ }
 };
 
-- 
2.31.1


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

* [PATCH BlueZ 6/6] mgmt-tester: Add test for Device Privacy Mode flag
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2021-11-05 21:12 ` [PATCH BlueZ 5/6] monitor: Add support for Device Privacy Mode flag Luiz Augusto von Dentz
@ 2021-11-05 21:12 ` Luiz Augusto von Dentz
  2021-11-05 21:34 ` [BlueZ,1/6] btdev: Add support for LE Set Privacy mode bluez.test.bot
  2021-11-10 18:40 ` bluez.test.bot
  6 siblings, 0 replies; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-05 21:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index e9fcb2602..e5319d123 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -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();
 }
-- 
2.31.1


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

* RE: [BlueZ,1/6] btdev: Add support for LE Set Privacy mode
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2021-11-05 21:12 ` [PATCH BlueZ 6/6] mgmt-tester: Add test " Luiz Augusto von Dentz
@ 2021-11-05 21:34 ` bluez.test.bot
  2021-11-10 18:40 ` bluez.test.bot
  6 siblings, 0 replies; 11+ messages in thread
From: bluez.test.bot @ 2021-11-05 21:34 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

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

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


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

* Re: [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode
  2021-11-05 21:12 ` [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode Luiz Augusto von Dentz
@ 2021-11-09 22:22   ` Luiz Augusto von Dentz
  2021-11-10  5:48     ` Marcel Holtmann
  0 siblings, 1 reply; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-09 22:22 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcel Holtmann

Hi Marcel,

On Fri, Nov 5, 2021 at 2:12 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> 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(+)
>
> diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
> index 97d33e30a..b7a152c14 100644
> --- a/doc/mgmt-api.txt
> +++ b/doc/mgmt-api.txt
> @@ -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.
> --
> 2.31.1

Any comments on this? I'd like to apply it if that's ok with you.

-- 
Luiz Augusto von Dentz

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

* Re: [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode
  2021-11-09 22:22   ` Luiz Augusto von Dentz
@ 2021-11-10  5:48     ` Marcel Holtmann
  0 siblings, 0 replies; 11+ messages in thread
From: Marcel Holtmann @ 2021-11-10  5:48 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

>> 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(+)
>> 
>> diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
>> index 97d33e30a..b7a152c14 100644
>> --- a/doc/mgmt-api.txt
>> +++ b/doc/mgmt-api.txt
>> @@ -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.
>> --
>> 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


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

* RE: [BlueZ,1/6] btdev: Add support for LE Set Privacy mode
  2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
                   ` (5 preceding siblings ...)
  2021-11-05 21:34 ` [BlueZ,1/6] btdev: Add support for LE Set Privacy mode bluez.test.bot
@ 2021-11-10 18:40 ` bluez.test.bot
  2021-11-11  0:26   ` Luiz Augusto von Dentz
  6 siblings, 1 reply; 11+ messages in thread
From: bluez.test.bot @ 2021-11-10 18:40 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

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

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


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

* Re: [BlueZ,1/6] btdev: Add support for LE Set Privacy mode
  2021-11-10 18:40 ` bluez.test.bot
@ 2021-11-11  0:26   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 11+ messages in thread
From: Luiz Augusto von Dentz @ 2021-11-11  0:26 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Wed, Nov 10, 2021 at 10:40 AM <bluez.test.bot@gmail.com> 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
>
>
>
> ---
> Regards,
> Linux Bluetooth

Pushed.


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2021-11-11  0:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 21:12 [PATCH BlueZ 1/6] btdev: Add support for LE Set Privacy mode Luiz Augusto von Dentz
2021-11-05 21:12 ` [PATCH BlueZ 2/6] mgmt-api: Add new Device Flag to use Device Privacy Mode Luiz Augusto von Dentz
2021-11-09 22:22   ` Luiz Augusto von Dentz
2021-11-10  5:48     ` Marcel Holtmann
2021-11-05 21:12 ` [PATCH BlueZ 3/6] main.conf: Rework privacy options Luiz Augusto von Dentz
2021-11-05 21:12 ` [PATCH BlueZ 4/6] adapter: Set Device Privacy Mode Luiz Augusto von Dentz
2021-11-05 21:12 ` [PATCH BlueZ 5/6] monitor: Add support for Device Privacy Mode flag Luiz Augusto von Dentz
2021-11-05 21:12 ` [PATCH BlueZ 6/6] mgmt-tester: Add test " Luiz Augusto von Dentz
2021-11-05 21:34 ` [BlueZ,1/6] btdev: Add support for LE Set Privacy mode bluez.test.bot
2021-11-10 18:40 ` bluez.test.bot
2021-11-11  0:26   ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).