diff mbox series

[RFC,BlueZ,v1,1/2] main.conf: Add LE.CentralAddressResolution option

Message ID 20240719200716.1557861-1-luiz.dentz@gmail.com (mailing list archive)
State New, archived
Headers show
Series [RFC,BlueZ,v1,1/2] main.conf: Add LE.CentralAddressResolution option | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/BuildEll success Build ELL PASS
tedd_an/BluezMake success Bluez Make PASS
tedd_an/MakeCheck success Bluez Make Check PASS
tedd_an/MakeDistcheck success Make Distcheck PASS
tedd_an/CheckValgrind success Check Valgrind PASS
tedd_an/CheckSmatch warning CheckSparse WARNING monitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1867:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3606:52: warning: array of flexible structuresmonitor/bt.h:3594:40: warning: array of flexible structures
tedd_an/bluezmakeextell success Make External ELL PASS
tedd_an/IncrementalBuild success Incremental Build PASS
tedd_an/ScanBuild warning ScanBuild: src/gatt-database.c:1165:10: warning: Value stored to 'bits' during its initialization is never read uint8_t bits[] = { BT_GATT_CHRC_CLI_FEAT_ROBUST_CACHING, ^~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.

Commit Message

Luiz Augusto von Dentz July 19, 2024, 8:07 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds CentralAddressResolution option to LE group which controls the
GATT attribute of the same name using the new MGMT Device Flag with the
fallback to LL Privacy experimental UUID.
---
 lib/mgmt.h          |  1 +
 src/adapter.c       |  6 ++++++
 src/btd.h           |  2 ++
 src/device.c        | 23 ++++++++++++++++++++++-
 src/device.h        |  2 ++
 src/gatt-database.c | 12 +++++++++++-
 src/main.c          | 23 +++++++++++++++++++++--
 src/main.conf       |  6 ++++++
 8 files changed, 71 insertions(+), 4 deletions(-)

Comments

bluez.test.bot@gmail.com July 19, 2024, 10:09 p.m. UTC | #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=872614

---Test result---

Test Summary:
CheckPatch                    PASS      1.00 seconds
GitLint                       PASS      0.71 seconds
BuildEll                      PASS      24.61 seconds
BluezMake                     PASS      1677.91 seconds
MakeCheck                     PASS      13.00 seconds
MakeDistcheck                 PASS      178.43 seconds
CheckValgrind                 PASS      252.76 seconds
CheckSmatch                   WARNING   354.08 seconds
bluezmakeextell               PASS      123.53 seconds
IncrementalBuild              PASS      3037.06 seconds
ScanBuild                     WARNING   1025.18 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
monitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1867:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3606:52: warning: array of flexible structuresmonitor/bt.h:3594:40: warning: array of flexible structures
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
src/gatt-database.c:1165:10: warning: Value stored to 'bits' during its initialization is never read
        uint8_t bits[] = { BT_GATT_CHRC_CLI_FEAT_ROBUST_CACHING,
                ^~~~     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 8f92b77315e3..6cd3b7397e18 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -678,6 +678,7 @@  struct mgmt_rp_get_device_flags {
 
 #define DEVICE_FLAG_REMOTE_WAKEUP	BIT(0)
 #define DEVICE_FLAG_DEVICE_PRIVACY	BIT(1)
+#define DEVICE_FLAG_ADDRESS_RESOLUTION	BIT(2)
 
 #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 85ddfc16568f..265c3f0edfbc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -5696,6 +5696,12 @@  void adapter_set_device_flags(struct btd_adapter *adapter,
 	if (btd_opts.device_privacy && !(flags & DEVICE_FLAG_DEVICE_PRIVACY))
 		flags |= DEVICE_FLAG_DEVICE_PRIVACY & supported & ~pending;
 
+	/* Set Address Resolution if it has not been set the flag yet. */
+	if (btd_opts.defaults.le.addr_resolution &&
+			device_address_is_private(device) &&
+			!(flags & DEVICE_FLAG_ADDRESS_RESOLUTION))
+		flags |= DEVICE_FLAG_ADDRESS_RESOLUTION & supported & ~pending;
+
 	bdaddr = device_get_address(device);
 	bdaddr_type = btd_device_get_bdaddr_type(device);
 
diff --git a/src/btd.h b/src/btd.h
index 383bd7c19600..b9c7647ef277 100644
--- a/src/btd.h
+++ b/src/btd.h
@@ -59,6 +59,8 @@  struct btd_br_defaults {
 };
 
 struct btd_le_defaults {
+	uint8_t		addr_resolution;
+
 	uint16_t	min_adv_interval;
 	uint16_t	max_adv_interval;
 	uint16_t	adv_rotation_interval;
diff --git a/src/device.c b/src/device.c
index a1dc0750ca41..063e32fe01b6 100644
--- a/src/device.c
+++ b/src/device.c
@@ -547,7 +547,7 @@  static gboolean store_device_info_cb(gpointer user_data)
 	return FALSE;
 }
 
-static bool device_address_is_private(struct btd_device *dev)
+bool device_address_is_private(struct btd_device *dev)
 {
 	if (dev->bdaddr_type != BDADDR_LE_RANDOM)
 		return false;
@@ -7234,6 +7234,27 @@  void btd_device_set_pnpid(struct btd_device *device, uint16_t source,
 	store_device_info(device);
 }
 
+bool btd_device_flags_enabled(struct btd_device *dev, uint32_t flags)
+{
+	const char *ll_privacy = "15c0a148-c273-11ea-b3de-0242ac130004";
+
+	if (!dev)
+		return false;
+
+	if (dev->current_flags & flags)
+		return true;
+
+	/* For backward compatibility check for LL Privacy experimental UUID
+	 * since that shall be equivalent to DEVICE_FLAG_ADDRESS_RESOLUTION on
+	 * older kernels.
+	 */
+	if ((flags & DEVICE_FLAG_ADDRESS_RESOLUTION) &&
+			btd_kernel_experimental_enabled(ll_privacy))
+		return true;
+
+	return false;
+}
+
 uint32_t btd_device_get_current_flags(struct btd_device *dev)
 {
 	return dev->current_flags;
diff --git a/src/device.h b/src/device.h
index 3742f6028040..36895db087ac 100644
--- a/src/device.h
+++ b/src/device.h
@@ -28,6 +28,7 @@  bool device_name_known(struct btd_device *device);
 bool device_is_name_resolve_allowed(struct btd_device *device);
 void device_name_resolve_fail(struct btd_device *device);
 void device_set_class(struct btd_device *device, uint32_t class);
+bool device_address_is_private(struct btd_device *dev);
 void device_set_rpa(struct btd_device *device, bool value);
 void device_update_addr(struct btd_device *device, const bdaddr_t *bdaddr,
 							uint8_t bdaddr_type);
@@ -189,6 +190,7 @@  struct btd_service *btd_device_get_service(struct btd_device *dev,
 int device_discover_services(struct btd_device *device);
 int btd_device_connect_services(struct btd_device *dev, GSList *services);
 
+bool btd_device_flags_enabled(struct btd_device *dev, uint32_t flags);
 uint32_t btd_device_get_current_flags(struct btd_device *dev);
 uint32_t btd_device_get_supported_flags(struct btd_device *dev);
 uint32_t btd_device_get_pending_flags(struct btd_device *dev);
diff --git a/src/gatt-database.c b/src/gatt-database.c
index 6c84b085ca29..92dc15641b9e 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -21,6 +21,7 @@ 
 #include "lib/sdp.h"
 #include "lib/sdp_lib.h"
 #include "lib/uuid.h"
+#include "lib/mgmt.h"
 #include "btio/btio.h"
 #include "gdbus/gdbus.h"
 #include "src/shared/util.h"
@@ -737,10 +738,19 @@  static void gap_car_read_cb(struct gatt_db_attribute *attrib,
 					uint8_t opcode, struct bt_att *att,
 					void *user_data)
 {
-	uint8_t value = 0x01;
+	uint8_t value = 0x00;
 
 	DBG("GAP Central Address Resolution read request\n");
 
+	if (btd_opts.defaults.le.addr_resolution) {
+		struct btd_device *device;
+
+		device = btd_adapter_find_device_by_fd(bt_att_get_fd(att));
+		if (device)
+			value = btd_device_flags_enabled(device,
+					DEVICE_FLAG_ADDRESS_RESOLUTION);
+	}
+
 	gatt_db_attribute_read_result(attrib, id, 0, &value, sizeof(value));
 }
 
diff --git a/src/main.c b/src/main.c
index 62453bffaf57..01fef7052108 100644
--- a/src/main.c
+++ b/src/main.c
@@ -108,6 +108,7 @@  static const char *br_options[] = {
 };
 
 static const char *le_options[] = {
+	"CentralAddressResolution",
 	"MinAdvertisementInterval",
 	"MaxAdvertisementInterval",
 	"MultiAdvertisementRotationInterval",
@@ -573,6 +574,11 @@  static void parse_br_config(GKeyFile *config)
 static void parse_le_config(GKeyFile *config)
 {
 	static const struct config_param params[] = {
+		{ "CentralAddressResolution",
+		  &btd_opts.defaults.le.addr_resolution,
+		  sizeof(btd_opts.defaults.le.addr_resolution),
+		  0,
+		  1},
 		{ "MinAdvertisementInterval",
 		  &btd_opts.defaults.le.min_adv_interval,
 		  sizeof(btd_opts.defaults.le.min_adv_interval),
@@ -700,9 +706,21 @@  static bool match_experimental(const void *data, const void *match_data)
 bool btd_kernel_experimental_enabled(const char *uuid)
 {
 	if (!btd_opts.kernel)
-		false;
+		goto done;
 
-	return queue_find(btd_opts.kernel, match_experimental, uuid);
+	if (queue_find(btd_opts.kernel, match_experimental, uuid))
+		return true;
+
+done:
+	/* For backward compatibility set LL Privacy as enabled if
+	 * CentralAddressResolution has been set so old kernel LL Privacy is
+	 * enabled.
+	 */
+	if (!strcmp(uuid, "15c0a148-c273-11ea-b3de-0242ac130004") &&
+			btd_opts.defaults.le.addr_resolution)
+		return true;
+
+	return false;
 }
 
 static const char *valid_uuids[] = {
@@ -1186,6 +1204,7 @@  static void init_defaults(void)
 	btd_opts.defaults.num_entries = 0;
 	btd_opts.defaults.br.page_scan_type = 0xFFFF;
 	btd_opts.defaults.br.scan_type = 0xFFFF;
+	btd_opts.defaults.le.addr_resolution = 0x01;
 	btd_opts.defaults.le.enable_advmon_interleave_scan = 0xFF;
 
 	if (sscanf(VERSION, "%hhu.%hhu", &major, &minor) != 2)
diff --git a/src/main.conf b/src/main.conf
index 82040b3fa33f..601cc61f7a26 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -178,6 +178,12 @@ 
 #MaxSniffInterval=
 
 [LE]
+# Enable/Disable Central Address Resolution.
+# 0: disable
+# 1: enable
+# Defaults to 1
+#CentralAddressResolution = 1
+
 # The following values are used to load default adapter parameters for LE.
 # BlueZ loads the values into the kernel before the adapter is powered if the
 # kernel supports the MGMT_LOAD_DEFAULT_PARAMETERS command. If a value isn't