public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v1 1/2] shared/ad: Add bt_ad_length
@ 2024-05-15 16:12 Luiz Augusto von Dentz
  2024-05-15 16:12 ` [PATCH BlueZ v1 2/2] advertising: Detect when EA needs to be used Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2024-05-15 16:12 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds bt_ad_length which can be used to return the current size of
the bt_ad data.
---
 src/shared/ad.c | 11 ++++++++---
 src/shared/ad.h |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/shared/ad.c b/src/shared/ad.c
index f3fb428e25c6..d08ce7af9b85 100644
--- a/src/shared/ad.c
+++ b/src/shared/ad.c
@@ -520,9 +520,14 @@ static size_t data_length(struct queue *queue)
 	return length;
 }
 
-static size_t calculate_length(struct bt_ad *ad)
+size_t bt_ad_length(struct bt_ad *ad)
 {
-	size_t length = 0;
+	size_t length;
+
+	if (!ad)
+		return 0;
+
+	length = 0;
 
 	length += uuid_list_length(ad->service_uuids);
 
@@ -698,7 +703,7 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length)
 	if (!ad)
 		return NULL;
 
-	*length = calculate_length(ad);
+	*length = bt_ad_length(ad);
 
 	if (*length > ad->max_len)
 		return NULL;
diff --git a/src/shared/ad.h b/src/shared/ad.h
index 11900706f9ed..90cc82de9d63 100644
--- a/src/shared/ad.h
+++ b/src/shared/ad.h
@@ -108,6 +108,8 @@ struct bt_ad *bt_ad_ref(struct bt_ad *ad);
 
 void bt_ad_unref(struct bt_ad *ad);
 
+size_t bt_ad_length(struct bt_ad *ad);
+
 uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length);
 
 bool bt_ad_is_empty(struct bt_ad *ad);
-- 
2.45.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-15 18:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-15 16:12 [PATCH BlueZ v1 1/2] shared/ad: Add bt_ad_length Luiz Augusto von Dentz
2024-05-15 16:12 ` [PATCH BlueZ v1 2/2] advertising: Detect when EA needs to be used Luiz Augusto von Dentz
2024-05-15 17:40 ` [PATCH BlueZ v1 1/2] shared/ad: Add bt_ad_length patchwork-bot+bluetooth
2024-05-15 18:07 ` [BlueZ,v1,1/2] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox