Skip to contentSkip to conversation

shared/gatt-db: Fix gatt_db_clone

PATCH Applied Luiz Augusto von Dentz 3 participants 4 messages Jun 11, 2024 – Jun 12, 2024 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 shared/gatt-db: Fix gatt_db_clone

From: Luiz Augusto von Dentz <[email protected]>

The process of cloning an existing db shall also clone certain values that are considered when calculating the hash since the resulting clone shall have the same hash.

---
 src/shared/gatt-db.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
src/shared/gatt-db.c +20 -3
index 16abcba2ec1c..b35763410d17 100644
@@ -281,18 +281,35 @@ static void service_clone(void *data, void *user_data)
 		/* Only clone values for characteristics declaration since that
 		 * is considered when calculating the db hash.
 		 */
-		if (bt_uuid_len(&attr->uuid) == 2 &&
-				attr->uuid.value.u16 == GATT_CHARAC_UUID)
+		if (bt_uuid_len(&attr->uuid) != 2) {
+			clone->attributes[i] = new_attribute(clone,
+							attr->handle,
+							&attr->uuid,
+							NULL, 0);
+			continue;
+		}
+
+		/* Attribute values that are used for generating the hash needs
+		 * to be cloned as well.
+		 */
+		switch (attr->uuid.value.u16) {
+		case GATT_PRIM_SVC_UUID:
+		case GATT_SND_SVC_UUID:
+		case GATT_INCLUDE_UUID:
+		case GATT_CHARAC_UUID:
 			clone->attributes[i] = new_attribute(clone,
 							attr->handle,
 							&attr->uuid,
 							attr->value,
 							attr->value_len);
-		else
+			break;
+		default:
 			clone->attributes[i] = new_attribute(clone,
 							attr->handle,
 							&attr->uuid,
 							NULL, 0);
+			break;
+		}
 	}
 
 	queue_push_tail(db->services, clone);
Signature · 1 line
2.45.2
author maintainer
#1 lore raw

PATCH 2/2 settings: Add more debug logs

From: Luiz Augusto von Dentz <[email protected]>

This adds more debug logs to indicate exacly where and what could not be parsed.

---
 src/settings.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
src/settings.c +21 -7
index 033e9670ac40..996eaacd36b2 100644
@@ -58,13 +58,17 @@ static int load_desc(struct gatt_db *db, char *handle, char *value,
 	uint16_t val;
 	bt_uuid_t uuid, ext_uuid;
 
-	if (sscanf(handle, "%04hx", &handle_int) != 1)
+	if (sscanf(handle, "%04hx", &handle_int) != 1) {
+		DBG("Failed to parse handle: %s", handle);
 		return -EIO;
+	}
 
 	/* Check if there is any value stored, otherwise it is just the UUID */
 	if (sscanf(value, "%04hx:%36s", &val, uuid_str) != 2) {
-		if (sscanf(value, "%36s", uuid_str) != 1)
+		if (sscanf(value, "%36s", uuid_str) != 1) {
+			DBG("Failed to parse value: %s", value);
 			return -EIO;
+		}
 		val = 0;
 	}
 
@@ -104,8 +108,10 @@ static int load_chrc(struct gatt_db *db, char *handle, char *value,
 	size_t val_len;
 	bt_uuid_t uuid;
 
-	if (sscanf(handle, "%04hx", &handle_int) != 1)
+	if (sscanf(handle, "%04hx", &handle_int) != 1) {
+		DBG("Failed to parse handle: %s", handle);
 		return -EIO;
+	}
 
 	/* Check if there is any value stored */
 	if (sscanf(value, GATT_CHARAC_UUID_STR ":%04hx:%02hx:%32s:%36s",
@@ -148,12 +154,16 @@ static int load_incl(struct gatt_db *db, char *handle, char *value,
 	struct gatt_db_attribute *att;
 	uint16_t start, end;
 
-	if (sscanf(handle, "%04hx", &start) != 1)
+	if (sscanf(handle, "%04hx", &start) != 1) {
+		DBG("Failed to parse handle: %s", handle);
 		return -EIO;
+	}
 
 	if (sscanf(value, GATT_INCLUDE_UUID_STR ":%04hx:%04hx:%36s", &start,
-							&end, uuid_str) != 3)
+							&end, uuid_str) != 3) {
+		DBG("Failed to parse value: %s", value);
 		return -EIO;
+	}
 
 	/* Log debug message. */
 	DBG("loading included service: 0x%04x, end: 0x%04x, uuid: %s",
@@ -178,11 +188,15 @@ static int load_service(struct gatt_db *db, char *handle, char *value)
 	bt_uuid_t uuid;
 	bool primary;
 
-	if (sscanf(handle, "%04hx", &start) != 1)
+	if (sscanf(handle, "%04hx", &start) != 1) {
+		DBG("Failed to parse handle: %s", handle);
 		return -EIO;
+	}
 
-	if (sscanf(value, "%[^:]:%04hx:%36s", type, &end, uuid_str) != 3)
+	if (sscanf(value, "%[^:]:%04hx:%36s", type, &end, uuid_str) != 3) {
+		DBG("Failed to parse value: %s", value);
 		return -EIO;
+	}
 
 	if (g_str_equal(type, GATT_PRIM_SVC_UUID_STR))
 		primary = true;
Signature · 1 line
2.45.2
#2 lore raw
In reply to Luiz Augusto von Dentz

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=860868

---Test result---

Test Summary:

CheckPatch                    PASS      1.03 seconds
GitLint                       PASS      0.71 seconds
BuildEll                      PASS      25.32 seconds
BluezMake                     PASS      1756.78 seconds
MakeCheck                     PASS      13.33 seconds
MakeDistcheck                 PASS      185.65 seconds
CheckValgrind                 PASS      260.47 seconds
CheckSmatch                   PASS      366.67 seconds
bluezmakeextell               PASS      122.96 seconds
IncrementalBuild              PASS      3149.71 seconds
ScanBuild                     PASS      1051.62 seconds

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 8 lines · On Tue, 11 Jun 2024 12:35:41 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

The process of cloning an existing db shall also clone certain values that are considered when calculating the hash since the resulting clone shall have the same hash.

---
 src/shared/gatt-db.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

Here is the summary with links:
- [BlueZ,v1,1/2] shared/gatt-db: Fix gatt_db_clone

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a37e475f7252
  - [BlueZ,v1,2/2] settings: Add more debug logs
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=891552999317

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html