public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] tools: Expose the raw advertising data available on D-bus to PTS tester
@ 2025-06-19 14:24 Adrian Dudau
  2025-06-19 14:24 ` [PATCH 1/1] " Adrian Dudau
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Adrian Dudau @ 2025-06-19 14:24 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: luiz.dentz, mihai-octavian.urzica, andrei.istodorescu,
	Adrian Dudau

This patch extracts the AdvertisingData property exposed by
bluetoothd on D-Bus. It will iterate the variable message structure
and will construct the eir buffer in the format described in
BLUETOOTH CORE SPECIFICATION Version 6.1 | Vol 3, Part C.

Adrian Dudau (1):
  tools: Expose the raw advertising data available on D-bus to PTS
    tester

 tools/btpclient.c | 80 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 76 insertions(+), 4 deletions(-)


base-commit: 5df9521ce4d50ffa48153503bc5156c11e6ed26b
-- 
2.45.2


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

* [PATCH 1/1] tools: Expose the raw advertising data available on D-bus to PTS tester
  2025-06-19 14:24 [PATCH 0/1] tools: Expose the raw advertising data available on D-bus to PTS tester Adrian Dudau
@ 2025-06-19 14:24 ` Adrian Dudau
  2025-06-19 15:47   ` bluez.test.bot
  2025-06-19 14:24 ` [PATCH v2 0/1] " Adrian Dudau
  2025-06-19 14:24 ` [PATCH v2 1/1] " Adrian Dudau
  2 siblings, 1 reply; 6+ messages in thread
From: Adrian Dudau @ 2025-06-19 14:24 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: luiz.dentz, mihai-octavian.urzica, andrei.istodorescu,
	Adrian Dudau

This patch extracts the AdvertisingData property exposed by
bluetoothd on D-Bus. It will iterate the variable message structure
and will construct the eir buffer in the format described in
BLUETOOTH CORE SPECIFICATION Version 6.1 | Vol 3, Part C.

Signed-off-by: Adrian Dudau <adrian-constantin.dudau@nxp.com>
---
 tools/btpclient.c | 80 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 76 insertions(+), 4 deletions(-)

diff --git a/tools/btpclient.c b/tools/btpclient.c
index 055270edb51b..f80b4532a248 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -2510,12 +2510,23 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 {
 	struct btp_device *device = find_device_by_proxy(proxy);
 	struct btp_adapter *adapter = find_adapter_by_device(device);
+	struct l_dbus_message_iter dict_iter;
+	struct l_dbus_message_iter variant_iter;
+	struct l_dbus_message_iter array_iter;
+	struct btp_device_found_ev *p_ev = NULL;
+	struct btp_device_found_ev *p_ev_temp = NULL;
 	struct btp_device_found_ev ev;
 	struct btp_gap_device_connected_ev ev_conn;
 	const char *str, *addr_str;
 	int16_t rssi;
 	uint8_t address_type;
 	bool connected;
+	uint8_t key = 0U; /* AD Type will be stored here */
+	uint8_t *data = NULL; /* AD Data will be stored here */
+	uint32_t len = 0U; /* Length of the AD Data buffer */
+	uint32_t eir_couter = 0U; /* Byte count of AD Type, AD Length, AD Data */
+
+	ev.eir_len =  0U;
 
 	if (!l_dbus_proxy_get_property(proxy, "Address", "s", &addr_str) ||
 					str2ba(addr_str, &ev.address) < 0)
@@ -2538,11 +2549,72 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 					BTP_EV_GAP_DEVICE_FOUND_FLAG_AD |
 					BTP_EV_GAP_DEVICE_FOUND_FLAG_SR);
 
-	/* TODO Add eir to device found event */
-	ev.eir_len = 0;
+	/* dict_iter will contain the variant for AdvertisingData */
+	if (l_dbus_proxy_get_property(proxy, "AdvertisingData", "a{yv}", &dict_iter)) {
+		/* key will contain the AD Type, variant_iter will contain the variant
+		 * for the current elem
+		 */
+		while (l_dbus_message_iter_next_entry(&dict_iter, &key, &variant_iter)) {
+			/* Unpack the variant to get the byte array */
+			if (!l_dbus_message_iter_get_variant(&variant_iter, "ay", &array_iter))
+				continue;
+
+			/* data contains AD Data, len is the length excluding the AD Type*/
+			if (!l_dbus_message_iter_get_fixed_array(&array_iter, &data, &len))
+				continue;
+
+			if (len <= 0U)
+				continue;
 
-	btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND, adapter->index,
-						sizeof(ev) + ev.eir_len, &ev);
+			p_ev_temp = p_ev;
+
+			/* Allocate new buffer, recalculated to sustain new data
+			 * eir_counter length from previous data,
+			 * len is size for new data,
+			 * 2U (1Byte AD Type, 1Byte AD Length)
+			 */
+			p_ev = (struct btp_device_found_ev *)
+					malloc(sizeof(struct btp_device_found_ev) +
+					eir_couter + len + 2U);
+
+			if (!p_ev) {
+				p_ev = p_ev_temp;
+				break;
+			}
+
+			/* There is AD data elemets to be moved after resize */
+			if (p_ev_temp && eir_couter != 0U) {
+				memcpy(p_ev, p_ev_temp,
+					sizeof(struct btp_device_found_ev) + eir_couter);
+				free(p_ev_temp);
+			} else {
+				memcpy(p_ev, &ev, sizeof(struct btp_device_found_ev));
+			}
+
+			/* Populate buffer with length */
+			p_ev->eir[eir_couter++] = len + 1U;
+			/* Populate buffer with AD Type */
+			p_ev->eir[eir_couter++] = key;
+
+			/* Move the data in the p_ev->eir that will be sent via btp */
+			for (uint32_t i = 0U; i < len; i++)
+				p_ev->eir[eir_couter + i] = data[i];
+
+			eir_couter += len;
+		}
+	}
+
+	if (p_ev) {
+		p_ev->eir_len = eir_couter;
+
+		btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND, adapter->index,
+		 sizeof(struct btp_device_found_ev) + eir_couter, p_ev);
+
+		free(p_ev);
+	} else {
+		btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND, adapter->index,
+		 sizeof(ev) + ev.eir_len, &ev);
+	}
 
 	if (l_dbus_proxy_get_property(proxy, "Connected", "b", &connected) &&
 								connected) {
-- 
2.45.2


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

* [PATCH v2 0/1] tools: Expose the raw advertising data available on D-bus to PTS tester
  2025-06-19 14:24 [PATCH 0/1] tools: Expose the raw advertising data available on D-bus to PTS tester Adrian Dudau
  2025-06-19 14:24 ` [PATCH 1/1] " Adrian Dudau
@ 2025-06-19 14:24 ` Adrian Dudau
  2025-06-19 14:24 ` [PATCH v2 1/1] " Adrian Dudau
  2 siblings, 0 replies; 6+ messages in thread
From: Adrian Dudau @ 2025-06-19 14:24 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: luiz.dentz, mihai-octavian.urzica, andrei.istodorescu,
	Adrian Dudau

This patch extracts the AdvertisingData property exposed by
bluetoothd on D-Bus. It will iterate the variable message structure
and will construct the eir buffer in the format described in
BLUETOOTH CORE SPECIFICATION Version 6.1 | Vol 3, Part C.

Adrian Dudau (1):
  tools: Expose the raw advertising data available on D-bus to PTS
    tester

 tools/btpclient.c | 98 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 4 deletions(-)


base-commit: 5df9521ce4d50ffa48153503bc5156c11e6ed26b
-- 
2.45.2


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

* [PATCH v2 1/1] tools: Expose the raw advertising data available on D-bus to PTS tester
  2025-06-19 14:24 [PATCH 0/1] tools: Expose the raw advertising data available on D-bus to PTS tester Adrian Dudau
  2025-06-19 14:24 ` [PATCH 1/1] " Adrian Dudau
  2025-06-19 14:24 ` [PATCH v2 0/1] " Adrian Dudau
@ 2025-06-19 14:24 ` Adrian Dudau
  2025-06-19 15:49   ` [v2,1/1] " bluez.test.bot
  2 siblings, 1 reply; 6+ messages in thread
From: Adrian Dudau @ 2025-06-19 14:24 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: luiz.dentz, mihai-octavian.urzica, andrei.istodorescu,
	Adrian Dudau

This patch extracts the AdvertisingData property exposed by
bluetoothd on D-Bus. It will iterate the variable message structure
and will construct the eir buffer in the format described in
BLUETOOTH CORE SPECIFICATION Version 6.1 | Vol 3, Part C.

Signed-off-by: Adrian Dudau <adrian-constantin.dudau@nxp.com>
---
 tools/btpclient.c | 98 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 4 deletions(-)

diff --git a/tools/btpclient.c b/tools/btpclient.c
index 055270edb51b..5d5a7ea4a2ae 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -2510,12 +2510,23 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 {
 	struct btp_device *device = find_device_by_proxy(proxy);
 	struct btp_adapter *adapter = find_adapter_by_device(device);
+	struct l_dbus_message_iter dict_iter;
+	struct l_dbus_message_iter variant_iter;
+	struct l_dbus_message_iter array_iter;
+	struct btp_device_found_ev *p_ev = NULL;
+	struct btp_device_found_ev *p_ev_temp = NULL;
 	struct btp_device_found_ev ev;
 	struct btp_gap_device_connected_ev ev_conn;
 	const char *str, *addr_str;
 	int16_t rssi;
 	uint8_t address_type;
 	bool connected;
+	uint8_t key = 0U; /* AD Type will be stored here */
+	const uint8_t *data = NULL; /* AD Data will be stored here */
+	uint32_t len = 0U; /* Length of the AD Data buffer */
+	uint32_t eir_counter = 0U; /* Count of AD Type, AD Length, AD Data */
+
+	ev.eir_len = 0U;
 
 	if (!l_dbus_proxy_get_property(proxy, "Address", "s", &addr_str) ||
 					str2ba(addr_str, &ev.address) < 0)
@@ -2538,11 +2549,90 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 					BTP_EV_GAP_DEVICE_FOUND_FLAG_AD |
 					BTP_EV_GAP_DEVICE_FOUND_FLAG_SR);
 
-	/* TODO Add eir to device found event */
-	ev.eir_len = 0;
+	/* dict_iter will contain the variant for AdvertisingData */
+	if (l_dbus_proxy_get_property(proxy,
+					"AdvertisingData",
+					"a{yv}",
+					&dict_iter)) {
+		/* key will contain the AD Type,
+		 * variant_iter will contain the variant
+		 * for the current elem
+		 */
+		while (l_dbus_message_iter_next_entry(&dict_iter,
+							&key,
+							&variant_iter)) {
+			/* Unpack the variant to get the byte array */
+			if (!l_dbus_message_iter_get_variant(&variant_iter,
+								"ay",
+								&array_iter))
+				continue;
+
+			/* data contains AD Data,
+			 * len is the length excluding the AD Type
+			 */
+			if (!l_dbus_message_iter_get_fixed_array(&array_iter,
+									&data,
+									&len))
+				continue;
+
+			if (len <= 0U)
+				continue;
+
+			p_ev_temp = p_ev;
+
+			/* Allocate new buffer, recalculated to sustain new data
+			 * eir_counter length from previous data,
+			 * len is size for new data,
+			 * 2U (1Byte AD Type, 1Byte AD Length)
+			 */
+			p_ev = (struct btp_device_found_ev *)
+				l_malloc(sizeof(*p_ev) +
+				eir_counter + len + 2U);
+
+			if (!p_ev) {
+				p_ev = p_ev_temp;
+				break;
+			}
+
+			/* There is AD data elemets to be moved after resize */
+			if (p_ev_temp && eir_counter != 0U) {
+				memcpy(p_ev, p_ev_temp,
+					sizeof(*p_ev) +
+					eir_counter);
+				l_free(p_ev_temp);
+			} else {
+				memcpy(p_ev, &ev,
+					sizeof(ev));
+			}
+
+			/* Populate buffer with length */
+			p_ev->eir[eir_counter++] = len + 1U;
+			/* Populate buffer with AD Type */
+			p_ev->eir[eir_counter++] = key;
+
+			/* Move the data in the p_ev->eir
+			 * that will be sent via btp
+			 */
+			for (uint32_t i = 0U; i < len; i++)
+				p_ev->eir[eir_counter + i] = data[i];
 
-	btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND, adapter->index,
-						sizeof(ev) + ev.eir_len, &ev);
+			eir_counter += len;
+		}
+	}
+
+	if (p_ev) {
+		p_ev->eir_len = eir_counter;
+
+		btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND,
+				adapter->index, sizeof(*p_ev) + eir_counter,
+				p_ev);
+
+		l_free(p_ev);
+	} else {
+		btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND,
+				adapter->index, sizeof(ev) + ev.eir_len,
+				&ev);
+	}
 
 	if (l_dbus_proxy_get_property(proxy, "Connected", "b", &connected) &&
 								connected) {
-- 
2.45.2


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

* RE: tools: Expose the raw advertising data available on D-bus to PTS tester
  2025-06-19 14:24 ` [PATCH 1/1] " Adrian Dudau
@ 2025-06-19 15:47   ` bluez.test.bot
  0 siblings, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2025-06-19 15:47 UTC (permalink / raw)
  To: linux-bluetooth, adrian-constantin.dudau

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

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

---Test result---

Test Summary:
CheckPatch                    PENDING   0.32 seconds
GitLint                       PENDING   0.34 seconds
BuildEll                      PASS      20.04 seconds
BluezMake                     PASS      2635.66 seconds
MakeCheck                     PASS      20.79 seconds
MakeDistcheck                 PASS      200.26 seconds
CheckValgrind                 PASS      274.98 seconds
CheckSmatch                   PASS      305.23 seconds
bluezmakeextell               PASS      127.92 seconds
IncrementalBuild              PENDING   0.33 seconds
ScanBuild                     PASS      915.46 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


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

* RE: [v2,1/1] tools: Expose the raw advertising data available on D-bus to PTS tester
  2025-06-19 14:24 ` [PATCH v2 1/1] " Adrian Dudau
@ 2025-06-19 15:49   ` bluez.test.bot
  0 siblings, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2025-06-19 15:49 UTC (permalink / raw)
  To: linux-bluetooth, adrian-constantin.dudau

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

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

---Test result---

Test Summary:
CheckPatch                    PENDING   0.43 seconds
GitLint                       PENDING   0.34 seconds
BuildEll                      PASS      20.31 seconds
BluezMake                     PASS      2711.77 seconds
MakeCheck                     PASS      20.01 seconds
MakeDistcheck                 PASS      198.83 seconds
CheckValgrind                 PASS      273.97 seconds
CheckSmatch                   PASS      306.00 seconds
bluezmakeextell               PASS      127.79 seconds
IncrementalBuild              PENDING   0.25 seconds
ScanBuild                     PASS      930.35 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


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

end of thread, other threads:[~2025-06-19 15:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-19 14:24 [PATCH 0/1] tools: Expose the raw advertising data available on D-bus to PTS tester Adrian Dudau
2025-06-19 14:24 ` [PATCH 1/1] " Adrian Dudau
2025-06-19 15:47   ` bluez.test.bot
2025-06-19 14:24 ` [PATCH v2 0/1] " Adrian Dudau
2025-06-19 14:24 ` [PATCH v2 1/1] " Adrian Dudau
2025-06-19 15:49   ` [v2,1/1] " 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