All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 3/5] gatt-database: Fix always registering CentralAddressResolution
Date: Mon, 24 Mar 2025 09:41:10 -0400	[thread overview]
Message-ID: <20250324134112.2108216-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20250324134112.2108216-1-luiz.dentz@gmail.com>

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

CentralAddressResolution shall be conditional to LL Privacy to avoid
peripherals assuming Directed Advertising can be used which may lead
to issues like:

Fixes: https://github.com/bluez/bluez/issues/1138
---
 lib/mgmt.h          |  1 +
 src/gatt-database.c | 21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 6a397645bcf2..6af82fc4a1a5 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -104,6 +104,7 @@ struct mgmt_rp_read_index_list {
 #define MGMT_SETTING_CIS_PERIPHERAL	BIT(19)
 #define MGMT_SETTING_ISO_BROADCASTER	BIT(20)
 #define MGMT_SETTING_ISO_SYNC_RECEIVER	BIT(21)
+#define MGMT_SETTING_LL_PRIVACY		BIT(22)
 
 #define MGMT_OP_READ_INFO		0x0004
 struct mgmt_rp_read_info {
diff --git a/src/gatt-database.c b/src/gatt-database.c
index 239a0dc72be9..1498720ad5a4 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -749,7 +749,7 @@ static void gap_car_read_cb(struct gatt_db_attribute *attrib,
 		device = btd_adapter_find_device_by_fd(bt_att_get_fd(att));
 		if (device)
 			value = btd_device_flags_enabled(device,
-					DEVICE_FLAG_ADDRESS_RESOLUTION);
+						DEVICE_FLAG_ADDRESS_RESOLUTION);
 	}
 
 	gatt_db_attribute_read_result(attrib, id, 0, &value, sizeof(value));
@@ -873,10 +873,13 @@ static void populate_gap_service(struct btd_gatt_database *database)
 {
 	bt_uuid_t uuid;
 	struct gatt_db_attribute *service, *attrib;
+	bool ll_privacy = btd_adapter_has_settings(database->adapter,
+						MGMT_SETTING_LL_PRIVACY);
 
 	/* Add the GAP service */
 	bt_uuid16_create(&uuid, UUID_GAP);
-	service = gatt_db_add_service(database->db, &uuid, true, 7);
+	service = gatt_db_add_service(database->db, &uuid, true,
+						ll_privacy ? 7 : 5);
 
 	/*
 	 * Device Name characteristic.
@@ -898,15 +901,19 @@ static void populate_gap_service(struct btd_gatt_database *database)
 							NULL, database);
 	gatt_db_attribute_set_fixed_length(attrib, 2);
 
-	/*
-	 * Central Address Resolution characteristic.
-	 */
-	bt_uuid16_create(&uuid, GATT_CHARAC_CAR);
-	attrib = gatt_db_service_add_characteristic(service, &uuid,
+	/* Only enable Central Address Resolution if LL Privacy is supported */
+	if (ll_privacy) {
+		/*
+		 * Central Address Resolution characteristic.
+		 */
+		bt_uuid16_create(&uuid, GATT_CHARAC_CAR);
+		attrib = gatt_db_service_add_characteristic(service, &uuid,
 							BT_ATT_PERM_READ,
 							BT_GATT_CHRC_PROP_READ,
 							gap_car_read_cb,
 							NULL, database);
+	}
+
 	gatt_db_attribute_set_fixed_length(attrib, 1);
 
 	gatt_db_service_set_active(service, true);
-- 
2.48.1


  parent reply	other threads:[~2025-03-24 13:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 13:41 [PATCH BlueZ v2 1/5] mgmt-api: Add missing Device Flag Luiz Augusto von Dentz
2025-03-24 13:41 ` [PATCH BlueZ v2 2/5] mgmt-api: Add LL Privacy setting Luiz Augusto von Dentz
2025-03-24 13:41 ` Luiz Augusto von Dentz [this message]
2025-03-24 13:41 ` [PATCH BlueZ v2 4/5] mgmt-tester: Fix missing MGMT_SETTING_LL_PRIVACY Luiz Augusto von Dentz
2025-03-24 13:41 ` [PATCH BlueZ v2 5/5] monitor: Add decoding of MGMT LL Privacy setting Luiz Augusto von Dentz
2025-03-24 14:39 ` [BlueZ,v2,1/5] mgmt-api: Add missing Device Flag bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250324134112.2108216-3-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.