Diff between cf8b2f308e31be757b5aa08a6c11887244cb5b21 and a0d6d3c78b28e667e53524b5e5961711e60ff13e

Changed Files

File Additions Deletions Status
lib/mgmt.h +1 -0 modified
src/adapter.c +3 -1 modified
src/gatt-database.c +14 -7 modified

Full Patch

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 6a39764..6af82fc 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/adapter.c b/src/adapter.c
index c0d647e..f66024b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -5693,6 +5693,8 @@ void adapter_set_device_flags(struct btd_adapter *adapter,
 	uint32_t pending = btd_device_get_pending_flags(device);
 	const bdaddr_t *bdaddr;
 	uint8_t bdaddr_type;
+	bool ll_privacy = btd_adapter_has_settings(adapter,
+						MGMT_SETTING_LL_PRIVACY);
 
 	if (!btd_has_kernel_features(KERNEL_CONN_CONTROL) ||
 				(supported | flags) != supported)
@@ -5707,7 +5709,7 @@ void adapter_set_device_flags(struct btd_adapter *adapter,
 		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 &&
+	if (ll_privacy && btd_opts.defaults.le.addr_resolution &&
 			device_address_is_private(device) &&
 			!(flags & DEVICE_FLAG_ADDRESS_RESOLUTION))
 		flags |= DEVICE_FLAG_ADDRESS_RESOLUTION & supported & ~pending;
diff --git a/src/gatt-database.c b/src/gatt-database.c
index 239a0dc..1498720 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);