Skip to contentSkip to conversation

a2dp: Fix caching endpoints for unknown version

PATCH Superseded Luiz Augusto von Dentz 2 participants 7 messages May 18, 2020 Bluetooth drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/4 a2dp: Fix caching endpoints for unknown version

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

Don't cache the capabilities of endpoints which the version is unknown since so capabilities may not be available in such case.

---
 profiles/audio/a2dp.c  | 11 +++++++++--
 profiles/audio/avdtp.c |  7 ++++++-
 profiles/audio/avdtp.h |  1 +
 3 files changed, 16 insertions(+), 3 deletions(-)
profiles/audio/a2dp.c +9 -2
index a2ce3204d..15e211b95 100644
@@ -2667,15 +2667,22 @@ static void discover_cb(struct avdtp *session, GSList *seps,
 				struct avdtp_error *err, void *user_data)
 {
 	struct a2dp_setup *setup = user_data;
+	uint16_t version = avdtp_get_version(session);
 
-	DBG("err %p", err);
+	DBG("version 0x%04x err %p", version, err);
 
 	setup->seps = seps;
 	setup->err = err;
 
 	if (!err) {
 		g_slist_foreach(seps, register_remote_sep, setup->chan);
-		store_remote_seps(setup->chan);
+
+		/* Only store version has been initialized as features like
+		 * Delay Reporting may not be queried if the version in
+		 * unknown.
+		 */
+		if (version)
+			store_remote_seps(setup->chan);
 	}
 
 	finalize_discover(setup);
profiles/audio/avdtp.c +6 -1
index b632e41c5..1fd2be051 100644
@@ -2256,7 +2256,7 @@ static uint16_t get_version(struct avdtp *session)
 	const sdp_record_t *rec;
 	sdp_list_t *protos;
 	sdp_data_t *proto_desc;
-	uint16_t ver = 0x0100;
+	uint16_t ver = 0x0000;
 
 	rec = btd_device_get_record(session->device, A2DP_SINK_UUID);
 	if (!rec)
@@ -2396,6 +2396,11 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 	return session;
 }
 
+uint16_t avdtp_get_version(struct avdtp *session)
+{
+	return session->version;
+}
+
 static GIOChannel *l2cap_connect(struct avdtp *session)
 {
 	GError *err = NULL;
profiles/audio/avdtp.h +1 -0
index ad2cb9bcb..f1e51d4e3 100644
@@ -310,3 +310,4 @@ struct avdtp_server *avdtp_get_server(struct avdtp_local_sep *lsep);
 
 struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 							struct queue *lseps);
+uint16_t avdtp_get_version(struct avdtp *session);
Signature · 1 line
2.25.3
author maintainer
#1 lore raw

PATCH 1/4 a2dp: Fix caching endpoints for unkown version

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

Don't cache the capabilities of endpoints which the version is unkown since so capabilities may not be available in such case.

---
 profiles/audio/a2dp.c  | 11 +++++++++--
 profiles/audio/avdtp.c |  7 ++++++-
 profiles/audio/avdtp.h |  1 +
 3 files changed, 16 insertions(+), 3 deletions(-)
profiles/audio/a2dp.c +9 -2
index a2ce3204d..15e211b95 100644
@@ -2667,15 +2667,22 @@ static void discover_cb(struct avdtp *session, GSList *seps,
 				struct avdtp_error *err, void *user_data)
 {
 	struct a2dp_setup *setup = user_data;
+	uint16_t version = avdtp_get_version(session);
 
-	DBG("err %p", err);
+	DBG("version 0x%04x err %p", version, err);
 
 	setup->seps = seps;
 	setup->err = err;
 
 	if (!err) {
 		g_slist_foreach(seps, register_remote_sep, setup->chan);
-		store_remote_seps(setup->chan);
+
+		/* Only store version has been initialized as features like
+		 * Delay Reporting may not be queried if the version in
+		 * unknown.
+		 */
+		if (version)
+			store_remote_seps(setup->chan);
 	}
 
 	finalize_discover(setup);
profiles/audio/avdtp.c +6 -1
index b632e41c5..1fd2be051 100644
@@ -2256,7 +2256,7 @@ static uint16_t get_version(struct avdtp *session)
 	const sdp_record_t *rec;
 	sdp_list_t *protos;
 	sdp_data_t *proto_desc;
-	uint16_t ver = 0x0100;
+	uint16_t ver = 0x0000;
 
 	rec = btd_device_get_record(session->device, A2DP_SINK_UUID);
 	if (!rec)
@@ -2396,6 +2396,11 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 	return session;
 }
 
+uint16_t avdtp_get_version(struct avdtp *session)
+{
+	return session->version;
+}
+
 static GIOChannel *l2cap_connect(struct avdtp *session)
 {
 	GError *err = NULL;
profiles/audio/avdtp.h +1 -0
index ad2cb9bcb..f1e51d4e3 100644
@@ -310,3 +310,4 @@ struct avdtp_server *avdtp_get_server(struct avdtp_local_sep *lsep);
 
 struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 							struct queue *lseps);
+uint16_t avdtp_get_version(struct avdtp *session);
Signature · 1 line
2.25.3
#2 lore raw

RE: [BlueZ,1/4] a2dp: Fix caching endpoints for unkown version

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. While we are preparing for reviewing the patches, we found the following issue/warning.

Test Result:
checkpatch Failed

Outputs:
WARNING:TYPO_SPELLING: 'unkown' may be misspelled - perhaps 'unknown'? #4:
Subject: [PATCH] a2dp: Fix caching endpoints for unkown version

WARNING:TYPO_SPELLING: 'unkown' may be misspelled - perhaps 'unknown'? #6:
Don't cache the capabilities of endpoints which the version is unkown

- total: 0 errors, 2 warnings, 47 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

Your patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPLIT_STRING

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

author maintainer
#3 lore raw

PATCH v2 2/4 doc/media-api: Add documentation for DelayReporting

In reply to Luiz Augusto von Dentz

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

The code was expecting the endpoint to expose MediaEndpoint.DelayReporting property in order to expose MediaTransport.Delay property.

---
 doc/media-api.txt | 4 ++++
 1 file changed, 4 insertions(+)
doc/media-api.txt +4 -0
index 07f7ac3e0..dabc69936 100644
@@ -580,6 +580,10 @@ Properties	string UUID [readonly, optional]:
 
 			Device object which the endpoint is belongs to.
 
+		bool DelayReporting [readonly, optional]:
+
+			Indicates if endpoint supports Delay Reporting.
+
 MediaTransport1 hierarchy
 =========================
 
Signature · 1 line
2.25.3
author maintainer
#4 lore raw

PATCH v2 3/4 a2dp: Store Delay Reporting capability

In reply to Luiz Augusto von Dentz

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

This stores Delay Reporting capability so it is properly restored when loading from cache.

---
 profiles/audio/a2dp.c  | 57 +++++++++++++++++++++++++++++++++---------
 profiles/audio/avdtp.c | 13 ++++++++--
 profiles/audio/avdtp.h |  5 +++-
 3 files changed, 60 insertions(+), 15 deletions(-)
profiles/audio/a2dp.c +45 -12
index 15e211b95..e47187e5e 100644
@@ -1847,11 +1847,25 @@ static gboolean get_device(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean get_delay_reporting(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct a2dp_remote_sep *sep = data;
+	dbus_bool_t delay_report;
+
+	delay_report = avdtp_get_delay_reporting(sep->sep);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &delay_report);
+
+	return TRUE;
+}
+
 static const GDBusPropertyTable sep_properties[] = {
 	{ "UUID", "s", get_uuid, NULL, NULL },
 	{ "Codec", "y", get_codec, NULL, NULL },
 	{ "Capabilities", "ay", get_capabilities, NULL, NULL },
 	{ "Device", "o", get_device, NULL, NULL },
+	{ "DelayReporting", "b", get_delay_reporting, NULL, NULL },
 	{ }
 };
 
@@ -1935,10 +1949,14 @@ static void load_remote_sep(struct a2dp_channel *chan, GKeyFile *key_file,
 	struct avdtp_remote_sep *rsep;
 	uint8_t lseid, rseid;
 	char *value;
+	bool delay_report;
 
 	if (!seids)
 		return;
 
+	delay_report = g_key_file_get_boolean(key_file, "Endpoints",
+						"DelayReporting", NULL);
+
 	for (; *seids; seids++) {
 		uint8_t type;
 		uint8_t codec;
@@ -1979,7 +1997,8 @@ static void load_remote_sep(struct a2dp_channel *chan, GKeyFile *key_file,
 
 		caps_add_codec(&l, codec, data, size / 2);
 
-		rsep = avdtp_register_remote_sep(chan->session, rseid, type, l);
+		rsep = avdtp_register_remote_sep(chan->session, rseid, type, l,
+								delay_report);
 		if (!rsep) {
 			warn("Unable to register Endpoint: seid %u", rseid);
 			continue;
@@ -2602,10 +2621,15 @@ static struct queue *a2dp_select_eps(struct avdtp *session, uint8_t type,
 	return a2dp_find_eps(session, l, NULL);
 }
 
+struct store_data {
+	GKeyFile *key_file;
+	bool delay_reporting;
+};
+
 static void store_remote_sep(void *data, void *user_data)
 {
 	struct a2dp_remote_sep *sep = data;
-	GKeyFile *key_file = (void *) user_data;
+	struct store_data *store = user_data;
 	char seid[4], value[256];
 	struct avdtp_service_capability *service = avdtp_get_codec(sep->sep);
 	struct avdtp_media_codec_capability *codec = (void *) service->data;
@@ -2620,8 +2644,10 @@ static void store_remote_sep(void *data, void *user_data)
 	for (i = 0; i < service->length - sizeof(*codec); i++)
 		offset += sprintf(value + offset, "%02hhx", codec->data[i]);
 
+	g_key_file_set_string(store->key_file, "Endpoints", seid, value);
 
-	g_key_file_set_string(key_file, "Endpoints", seid, value);
+	if (!store->delay_reporting && avdtp_get_delay_reporting(sep->sep))
+		store->delay_reporting = true;
 }
 
 static void store_remote_seps(struct a2dp_channel *chan)
@@ -2629,9 +2655,9 @@ static void store_remote_seps(struct a2dp_channel *chan)
 	struct btd_device *device = chan->device;
 	char filename[PATH_MAX];
 	char dst_addr[18];
-	GKeyFile *key_file;
 	char *data;
 	gsize length = 0;
+	struct store_data store;
 
 	if (queue_isempty(chan->seps))
 		return;
@@ -2641,26 +2667,33 @@ static void store_remote_seps(struct a2dp_channel *chan)
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s",
 			btd_adapter_get_storage_dir(device_get_adapter(device)),
 			dst_addr);
-	key_file = g_key_file_new();
-	g_key_file_load_from_file(key_file, filename, 0, NULL);
+	store.key_file = g_key_file_new();
+	g_key_file_load_from_file(store.key_file, filename, 0, NULL);
 
-	data = g_key_file_get_string(key_file, "Endpoints", "LastUsed", NULL);
+	data = g_key_file_get_string(store.key_file, "Endpoints", "LastUsed",
+								NULL);
 
 	/* Remove current endpoints since it might have changed */
-	g_key_file_remove_group(key_file, "Endpoints", NULL);
+	g_key_file_remove_group(store.key_file, "Endpoints", NULL);
 
-	queue_foreach(chan->seps, store_remote_sep, key_file);
+	queue_foreach(chan->seps, store_remote_sep, &store);
+
+	if (store.delay_reporting)
+		g_key_file_set_boolean(store.key_file, "Endpoints",
+						"DelayReporting",
+						store.delay_reporting);
 
 	if (data) {
-		g_key_file_set_string(key_file, "Endpoints", "LastUsed", data);
+		g_key_file_set_string(store.key_file, "Endpoints", "LastUsed",
+						data);
 		g_free(data);
 	}
 
-	data = g_key_file_to_data(key_file, &length, NULL);
+	data = g_key_file_to_data(store.key_file, &length, NULL);
 	g_file_set_contents(filename, data, length, NULL);
 
 	g_free(data);
-	g_key_file_free(key_file);
+	g_key_file_free(store.key_file);
 }
 
 static void discover_cb(struct avdtp *session, GSList *seps,
profiles/audio/avdtp.c +11 -2
index 1fd2be051..cf471cb22 100644
@@ -3210,6 +3210,11 @@ struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep)
 	return sep->codec;
 }
 
+bool avdtp_get_delay_reporting(struct avdtp_remote_sep *sep)
+{
+	return sep->delay_reporting;
+}
+
 struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
 							void *data, int length)
 {
@@ -3229,7 +3234,8 @@ struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
 struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
 							uint8_t seid,
 							uint8_t type,
-							GSList *caps)
+							GSList *caps,
+							bool delay_report)
 {
 	struct avdtp_remote_sep *sep;
 	GSList *l;
@@ -3244,6 +3250,7 @@ struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
 	sep->type = type;
 	sep->media_type = AVDTP_MEDIA_TYPE_AUDIO;
 	sep->caps = caps;
+	sep->delay_reporting = delay_report;
 
 	for (l = caps; l; l = g_slist_next(l)) {
 		struct avdtp_service_capability *cap = l->data;
@@ -3252,7 +3259,9 @@ struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
 			sep->codec = cap;
 	}
 
-	DBG("seid %d type %d media %d", sep->seid, sep->type, sep->media_type);
+	DBG("seid %d type %d media %d delay_reporting %s", sep->seid, sep->type,
+				sep->media_type,
+				sep->delay_reporting ? "true" : "false");
 
 	return sep;
 }
profiles/audio/avdtp.h +4 -1
index f1e51d4e3..08b9063bc 100644
@@ -226,7 +226,8 @@ struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
 struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
 							uint8_t seid,
 							uint8_t type,
-							GSList *caps);
+							GSList *caps,
+							bool delay_report);
 
 uint8_t avdtp_get_seid(struct avdtp_remote_sep *sep);
 
@@ -234,6 +235,8 @@ uint8_t avdtp_get_type(struct avdtp_remote_sep *sep);
 
 struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
 
+bool avdtp_get_delay_reporting(struct avdtp_remote_sep *sep);
+
 int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
 			void *user_data);
 
Signature · 1 line
2.25.3
author maintainer
#5 lore raw

PATCH v2 4/4 doc/settings-storage: Update documentation of Endpoints

In reply to Luiz Augusto von Dentz

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

Add documentation of DelayReporting storage as that has been added to the cache.

---
 doc/settings-storage.txt | 2 ++
 1 file changed, 2 insertions(+)
doc/settings-storage.txt +2 -0
index 5f6d25141..6e67ddc9c 100644
@@ -225,6 +225,8 @@ Sample Attributes section:
 	LastUsed:<xx>:<xx>	String	LastUsed has two fields which are the
 					local and remote seids as hexadecimal
 					encoded string.
+	DelayReporting:		Bool	DelayReporting indicates remote
+					support Delay Reporting feature.
 
 Info file format
 ================
Signature · 1 line
2.25.3
#6 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. While we are preparing for reviewing the patches, we found the following issue/warning.

Test Result:
makecheck Failed

Outputs:
./test-driver: line 107: 14841 Aborted (core dumped) "$@" > $log_file 2>&1
make[3]: *** [Makefile:9726: test-suite.log] Error 1 make[2]: *** [Makefile:9834: check-TESTS] Error 2 make[1]: *** [Makefile:10228: check-am] Error 2
make: *** [Makefile:10230: check] Error 2

---
Regards,
Linux Bluetooth