linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] bthost: Allow sending ISO packets with sequence number and timestamp
@ 2023-02-25 21:42 Pauli Virtanen
  2023-02-25 21:42 ` [PATCH BlueZ 2/2] iso-tester: Add test for central receiving timestamped ISO packet Pauli Virtanen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pauli Virtanen @ 2023-02-25 21:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

Change bthost_send_iso to take packet sequence number and timestamp, and
allow it to send timestamped HCI ISO data packets.

Currently, btdev passes through ISO packets, so this can also be used to
test RX timestamping.
---

Notes:
    This series adds a test case for
    
    https://lore.kernel.org/linux-bluetooth/1fd2d4523c139deda93aab2c31f1508d79c32472.1676921889.git.pav@iki.fi/
    
    Here, it seems simplest if btdev simply passes through the timestamps
    and sequence numbers it receives, instead of modifying them.  One side
    of the "connection" generally is bthost, and it is easier for writing
    tests if nothing modifies the values in between.
    
    Also if dummy ISOAL like timestamping is added to the emulator later, we
    can still consider timestamped input packet as the trigger for enabling
    RX timestamping, or add something like
    hciemu_set_central_iso_timestamping(bool).

 emulator/bthost.c  | 45 ++++++++++++++++++++++++++++++++-------------
 emulator/bthost.h  |  3 ++-
 tools/iso-tester.c |  3 ++-
 3 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/emulator/bthost.c b/emulator/bthost.c
index 3cce4666c..4671fe17d 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -38,6 +38,8 @@
 #define acl_flags(h)		(h >> 12)
 
 #define iso_flags_pb(f)		(f & 0x0003)
+#define iso_flags_ts(f)		((f >> 2) & 0x0001)
+#define iso_flags_pack(pb, ts)	(((pb) & 0x03) | (((ts) & 0x01) << 2))
 #define iso_data_len_pack(h, f)	((uint16_t) ((h) | ((f) << 14)))
 
 #define L2CAP_FEAT_FIXED_CHAN	0x00000080
@@ -728,41 +730,58 @@ void bthost_send_cid_v(struct bthost *bthost, uint16_t handle, uint16_t cid,
 	send_iov(bthost, handle, cid, iov, iovcnt);
 }
 
-static void send_iso(struct bthost *bthost, uint16_t handle,
+static void send_iso(struct bthost *bthost, uint16_t handle, bool ts,
+					uint16_t sn, uint32_t timestamp,
 					const struct iovec *iov, int iovcnt)
 {
 	struct bt_hci_iso_hdr iso_hdr;
 	struct bt_hci_iso_data_start data_hdr;
 	uint8_t pkt = BT_H4_ISO_PKT;
-	struct iovec pdu[3 + iovcnt];
+	struct iovec pdu[4 + iovcnt];
+	uint16_t flags, dlen;
 	int i, len = 0;
-	static uint16_t sn;
 
 	for (i = 0; i < iovcnt; i++) {
-		pdu[3 + i].iov_base = iov[i].iov_base;
-		pdu[3 + i].iov_len = iov[i].iov_len;
+		pdu[4 + i].iov_base = iov[i].iov_base;
+		pdu[4 + i].iov_len = iov[i].iov_len;
 		len += iov[i].iov_len;
 	}
 
 	pdu[0].iov_base = &pkt;
 	pdu[0].iov_len = sizeof(pkt);
 
-	iso_hdr.handle = acl_handle_pack(handle, 0x02);
-	iso_hdr.dlen = cpu_to_le16(len + sizeof(data_hdr));
+	flags = iso_flags_pack(0x02, ts);
+	dlen = len + sizeof(data_hdr);
+	if (ts)
+		dlen += sizeof(timestamp);
+
+	iso_hdr.handle = acl_handle_pack(handle, flags);
+	iso_hdr.dlen = cpu_to_le16(dlen);
 
 	pdu[1].iov_base = &iso_hdr;
 	pdu[1].iov_len = sizeof(iso_hdr);
 
-	data_hdr.sn = cpu_to_le16(sn++);
+	if (ts) {
+		timestamp = cpu_to_le32(timestamp);
+
+		pdu[2].iov_base = &timestamp;
+		pdu[2].iov_len = sizeof(timestamp);
+	} else {
+		pdu[2].iov_base = NULL;
+		pdu[2].iov_len = 0;
+	}
+
+	data_hdr.sn = cpu_to_le16(sn);
 	data_hdr.slen = cpu_to_le16(iso_data_len_pack(len, 0));
 
-	pdu[2].iov_base = &data_hdr;
-	pdu[2].iov_len = sizeof(data_hdr);
+	pdu[3].iov_base = &data_hdr;
+	pdu[3].iov_len = sizeof(data_hdr);
 
-	send_packet(bthost, pdu, 3 + iovcnt);
+	send_packet(bthost, pdu, 4 + iovcnt);
 }
 
-void bthost_send_iso(struct bthost *bthost, uint16_t handle,
+void bthost_send_iso(struct bthost *bthost, uint16_t handle, bool ts,
+					uint16_t sn, uint32_t timestamp,
 					const struct iovec *iov, int iovcnt)
 {
 	struct btconn *conn;
@@ -771,7 +790,7 @@ void bthost_send_iso(struct bthost *bthost, uint16_t handle,
 	if (!conn)
 		return;
 
-	send_iso(bthost, handle, iov, iovcnt);
+	send_iso(bthost, handle, ts, sn, timestamp, iov, iovcnt);
 }
 
 bool bthost_l2cap_req(struct bthost *bthost, uint16_t handle, uint8_t code,
diff --git a/emulator/bthost.h b/emulator/bthost.h
index c42444476..92182687f 100644
--- a/emulator/bthost.h
+++ b/emulator/bthost.h
@@ -79,7 +79,8 @@ void bthost_send_cid(struct bthost *bthost, uint16_t handle, uint16_t cid,
 					const void *data, uint16_t len);
 void bthost_send_cid_v(struct bthost *bthost, uint16_t handle, uint16_t cid,
 					const struct iovec *iov, int iovcnt);
-void bthost_send_iso(struct bthost *bthost, uint16_t handle,
+void bthost_send_iso(struct bthost *bthost, uint16_t handle, bool ts,
+					uint16_t sn, uint32_t timestamp,
 					const struct iovec *iov, int iovcnt);
 
 typedef void (*bthost_l2cap_rsp_cb) (uint8_t code, const void *data,
diff --git a/tools/iso-tester.c b/tools/iso-tester.c
index d790b1556..dcfd6a045 100644
--- a/tools/iso-tester.c
+++ b/tools/iso-tester.c
@@ -1146,6 +1146,7 @@ static void iso_recv(struct test_data *data, GIOChannel *io)
 {
 	const struct iso_client_data *isodata = data->test_data;
 	struct bthost *host;
+	static uint16_t sn;
 
 	tester_print("Receive %zu bytes of data", isodata->recv->iov_len);
 
@@ -1156,7 +1157,7 @@ static void iso_recv(struct test_data *data, GIOChannel *io)
 	}
 
 	host = hciemu_client_get_host(data->hciemu);
-	bthost_send_iso(host, data->handle, isodata->recv, 1);
+	bthost_send_iso(host, data->handle, false, sn++, 0, isodata->recv, 1);
 
 	data->io_id[0] = g_io_add_watch(io, G_IO_IN, iso_recv_data, data);
 }
-- 
2.39.2


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

* [PATCH BlueZ 2/2] iso-tester: Add test for central receiving timestamped ISO packet
  2023-02-25 21:42 [PATCH BlueZ 1/2] bthost: Allow sending ISO packets with sequence number and timestamp Pauli Virtanen
@ 2023-02-25 21:42 ` Pauli Virtanen
  2023-02-25 23:31 ` [BlueZ,1/2] bthost: Allow sending ISO packets with sequence number and timestamp bluez.test.bot
  2023-02-27 21:40 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: Pauli Virtanen @ 2023-02-25 21:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

This attempts to receive a timestamped HCI ISO data packet on central.

With kernel 6.2 HCI ISO packet parsing this test fails with
Bluetooth: Frame malformed (len 40, expected len 0)

Link: https://lore.kernel.org/linux-bluetooth/1fd2d4523c139deda93aab2c31f1508d79c32472.1676921889.git.pav@iki.fi/
---
 tools/iso-tester.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/iso-tester.c b/tools/iso-tester.c
index dcfd6a045..7bcb1b3ca 100644
--- a/tools/iso-tester.c
+++ b/tools/iso-tester.c
@@ -149,6 +149,7 @@ struct iso_client_data {
 	bool bcast;
 	bool defer;
 	bool disconnect;
+	bool ts;
 };
 
 static void mgmt_debug(const char *str, void *user_data)
@@ -572,6 +573,14 @@ static const struct iso_client_data listen_16_2_1_recv = {
 	.server = true,
 };
 
+static const struct iso_client_data listen_16_2_1_recv_ts = {
+	.qos = QOS_16_2_1,
+	.expect_err = 0,
+	.recv = &send_16_2_1,
+	.server = true,
+	.ts = true,
+};
+
 static const struct iso_client_data defer_16_2_1 = {
 	.qos = QOS_16_2_1,
 	.expect_err = 0,
@@ -1157,7 +1166,8 @@ static void iso_recv(struct test_data *data, GIOChannel *io)
 	}
 
 	host = hciemu_client_get_host(data->hciemu);
-	bthost_send_iso(host, data->handle, false, sn++, 0, isodata->recv, 1);
+	bthost_send_iso(host, data->handle, isodata->ts, sn++, 0,
+							isodata->recv, 1);
 
 	data->io_id[0] = g_io_add_watch(io, G_IO_IN, iso_recv_data, data);
 }
@@ -1809,6 +1819,10 @@ int main(int argc, char *argv[])
 	test_iso("ISO Receive - Success", &listen_16_2_1_recv, setup_powered,
 							test_listen);
 
+	test_iso("ISO Receive Timestamped - Success", &listen_16_2_1_recv_ts,
+							setup_powered,
+							test_listen);
+
 	test_iso("ISO Defer - Success", &defer_16_2_1, setup_powered,
 							test_defer);
 
-- 
2.39.2


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

* RE: [BlueZ,1/2] bthost: Allow sending ISO packets with sequence number and timestamp
  2023-02-25 21:42 [PATCH BlueZ 1/2] bthost: Allow sending ISO packets with sequence number and timestamp Pauli Virtanen
  2023-02-25 21:42 ` [PATCH BlueZ 2/2] iso-tester: Add test for central receiving timestamped ISO packet Pauli Virtanen
@ 2023-02-25 23:31 ` bluez.test.bot
  2023-02-27 21:40 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2023-02-25 23:31 UTC (permalink / raw)
  To: linux-bluetooth, pav

[-- Attachment #1: Type: text/plain, Size: 2590 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=724874

---Test result---

Test Summary:
CheckPatch                    PASS      0.72 seconds
GitLint                       FAIL      0.81 seconds
BuildEll                      PASS      30.91 seconds
BluezMake                     PASS      956.76 seconds
MakeCheck                     PASS      12.69 seconds
MakeDistcheck                 PASS      169.88 seconds
CheckValgrind                 PASS      281.35 seconds
CheckSmatch                   WARNING   371.67 seconds
bluezmakeextell               PASS      112.03 seconds
IncrementalBuild              PASS      1553.96 seconds
ScanBuild                     PASS      1146.92 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,1/2] bthost: Allow sending ISO packets with sequence number and timestamp

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
12: B2 Line has trailing whitespace: "    "
13: B1 Line exceeds max length (111>80): "    https://lore.kernel.org/linux-bluetooth/1fd2d4523c139deda93aab2c31f1508d79c32472.1676921889.git.pav@iki.fi/"
14: B2 Line has trailing whitespace: "    "
19: B2 Line has trailing whitespace: "    "
[BlueZ,2/2] iso-tester: Add test for central receiving timestamped ISO packet

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
8: B1 Line exceeds max length (113>80): "Link: https://lore.kernel.org/linux-bluetooth/1fd2d4523c139deda93aab2c31f1508d79c32472.1676921889.git.pav@iki.fi/"
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
emulator/bthost.c:583:28: warning: Variable length array is used.emulator/bthost.c:740:28: warning: Variable length array is used.


---
Regards,
Linux Bluetooth


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

* Re: [PATCH BlueZ 1/2] bthost: Allow sending ISO packets with sequence number and timestamp
  2023-02-25 21:42 [PATCH BlueZ 1/2] bthost: Allow sending ISO packets with sequence number and timestamp Pauli Virtanen
  2023-02-25 21:42 ` [PATCH BlueZ 2/2] iso-tester: Add test for central receiving timestamped ISO packet Pauli Virtanen
  2023-02-25 23:31 ` [BlueZ,1/2] bthost: Allow sending ISO packets with sequence number and timestamp bluez.test.bot
@ 2023-02-27 21:40 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2023-02-27 21:40 UTC (permalink / raw)
  To: Pauli Virtanen; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Sat, 25 Feb 2023 21:42:50 +0000 you wrote:
> Change bthost_send_iso to take packet sequence number and timestamp, and
> allow it to send timestamped HCI ISO data packets.
> 
> Currently, btdev passes through ISO packets, so this can also be used to
> test RX timestamping.
> ---
> 
> [...]

Here is the summary with links:
  - [BlueZ,1/2] bthost: Allow sending ISO packets with sequence number and timestamp
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=80a45cb6a240
  - [BlueZ,2/2] iso-tester: Add test for central receiving timestamped ISO packet
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2be849c2398b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-02-27 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-25 21:42 [PATCH BlueZ 1/2] bthost: Allow sending ISO packets with sequence number and timestamp Pauli Virtanen
2023-02-25 21:42 ` [PATCH BlueZ 2/2] iso-tester: Add test for central receiving timestamped ISO packet Pauli Virtanen
2023-02-25 23:31 ` [BlueZ,1/2] bthost: Allow sending ISO packets with sequence number and timestamp bluez.test.bot
2023-02-27 21:40 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).