btvirt improvements for LE Audio
Subsystems (2)
cover btvirt improvements for LE Audio
This patch series improves some bits around btvirt, its interfaces, advertising and isochronous channel handling.
These changes enable btvirt to be used for simulation testing of Zephyr Bluetooth stack implementation of BAP server for LE Audio.
Dmitrii Sharshakov (4):
btdev: implement extended advertising
btdev: fix LE Remove ISO Data Path command
emulator: add option to listen on TCP
emulator: server: handle ISO, use BR/EDR+LE 5.2 by default
emulator/btdev.c | 52 +++++++++++++++++++++++++++++++---------------- emulator/main.c | 20 ++++++++++++++++-- emulator/server.c | 19 +++++++++++------ emulator/server.h | 2 +- lib/hci.h | 6 ++++++ 5 files changed, 72 insertions(+), 27 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/4 btdev: implement extended advertising
Increase maximum advertising data length and implement LE Read Maximum Advertising Data Length command.
As expected by Zephyr BAP Server
--- emulator/btdev.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
emulator/btdev.c +18 -7
@@ -25,6 +25,8 @@#include <fcntl.h> #include <unistd.h> +#include <glib.h> +#include "lib/bluetooth.h" #include "lib/hci.h"
@@ -45,6 +47,7 @@#define CIG_SIZE 3#define MAX_PA_DATA_LEN 252 +#define MAX_EXT_ADV_LEN 252#define has_bredr (btdev) (!((btdev)->features[4] & 0x20))#define has_le (btdev) (!!((btdev)->features[4] & 0x40))
@@ -99,9 +102,9 @@ struct le_ext_adv {uint8_t filter_policy;/* filter_policy */ uint8_t random_addr[6 ];bool rpa; -uint8_t adv_data[252 ]; +uint8_t adv_data[MAX_EXT_ADV_LEN ];uint8_t adv_data_len; -uint8_t scan_data[252 ]; +uint8_t scan_data[MAX_EXT_ADV_LEN ];uint8_t scan_data_len;unsigned int broadcast_id;unsigned int timeout_id;
@@ -4950,7 +4953,7 @@ static int cmd_set_ext_adv_data(struct btdev *dev, const void *data,return 0 ; } - ext_adv->adv_data_len = cmd->data_len; + ext_adv->adv_data_len =MIN (cmd->data_len,MAX_EXT_ADV_LEN );memcpy (ext_adv->adv_data, cmd->data, cmd->data_len);cmd_complete (dev,BT_HCI_CMD_LE_SET_EXT_ADV_DATA , &status,sizeof (status));
@@ -4974,7 +4977,7 @@ static int cmd_set_ext_scan_rsp_data(struct btdev *dev, const void *data,return 0 ; } - ext_adv->scan_data_len = cmd->data_len; + ext_adv->scan_data_len =MIN (cmd->data_len,MAX_EXT_ADV_LEN );memcpy (ext_adv->scan_data, cmd->data, cmd->data_len);cmd_complete (dev,BT_HCI_CMD_LE_SET_EXT_SCAN_RSP_DATA , &status,sizeof (status));
@@ -5008,7 +5011,7 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote,uint8_t num_reports;union {struct bt_hci_le_ext_adv_report lear; -uint8_t raw[24 +31 ]; +uint8_t raw[24 +MAX_EXT_ADV_LEN ]; }; } meta_event;
@@ -5213,8 +5216,16 @@ exit_complete:static int cmd_read_max_adv_data_len (struct btdev *dev,const void *data,uint8_t len) { -/* TODO */ -return -ENOTSUP ; +struct bt_hci_rsp_le_read_max_adv_data_len rsp; + +memset (&rsp,0 ,sizeof (rsp)); + + rsp.status =BT_HCI_ERR_SUCCESS ; + rsp.max_len =MAX_EXT_ADV_LEN ; +cmd_complete (dev,BT_HCI_CMD_LE_READ_MAX_ADV_DATA_LEN , &rsp, +sizeof (rsp)); + +return 0 ; } static int cmd_read_num_adv_sets(struct btdev *dev, const void *data,
Signature · 1 line
2.49.0
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=969870
---Test result---
Test Summary:
CheckPatch PENDING 0.29 seconds GitLint PENDING 1.29 seconds BuildEll PASS 20.47 seconds BluezMake PASS 2720.79 seconds MakeCheck PASS 20.21 seconds MakeDistcheck PASS 201.55 seconds CheckValgrind PASS 276.85 seconds CheckSmatch WARNING 304.40 seconds bluezmakeextell PASS 129.18 seconds IncrementalBuild PENDING 0.26 seconds ScanBuild PASS 922.29 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:emulator/btdev.c:456:29: warning: Variable length array is used.emulator/btdev.c:456:29: warning: Variable length array is used.
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
PATCH 2/4 btdev: fix LE Remove ISO Data Path command
In reply to Dmitrii SharshakovFix errors in BAP server
--- emulator/btdev.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
emulator/btdev.c +16 -11
@@ -6726,30 +6726,35 @@ done:static int cmd_remove_iso_path (struct btdev *dev,const void *data,uint8_t len) {const struct bt_hci_cmd_le_remove_iso_path *cmd = data; -uint8_t status =BT_HCI_ERR_SUCCESS ; +struct bt_hci_rsp_le_remove_iso_path rsp;struct btdev_conn *conn; +memset (&rsp,0 ,sizeof (rsp)); + + rsp.handle = cmd->handle; + conn =queue_find (dev->conns, match_handle,UINT_TO_PTR (cpu_to_le16 (cmd->handle)));if (!conn) { - status =BT_HCI_ERR_UNKNOWN_CONN_ID ; + rsp.status =BT_HCI_ERR_UNKNOWN_CONN_ID ; goto done; } -switch (cmd->direction) { -case 0x00 : +if (cmd->direction >0x3 ) { + rsp.status =BT_HCI_ERR_INVALID_PARAMETERS ; + goto done; + } + +if (cmd->direction &0x1 ) { dev->le_iso_path[0 ] =0x00 ; -break ; -case 0x01 : + } +if (cmd->direction &0x2 ) { dev->le_iso_path[1 ] =0x00 ; -break ; -default : - status =BT_HCI_ERR_INVALID_PARAMETERS ; } done: -cmd_complete (dev,BT_HCI_CMD_LE_REMOVE_ISO_PATH , &status, -sizeof (status)); +cmd_complete (dev,BT_HCI_CMD_LE_REMOVE_ISO_PATH , &rsp, +sizeof (rsp));return 0 ; }
Signature · 1 line
2.49.0
PATCH 3/4 emulator: add option to listen on TCP
In reply to Dmitrii Sharshakov--- emulator/main.c | 20 ++++++++++++++++++-- emulator/server.c | 8 ++++---- emulator/server.h | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-)
emulator/main.c +18 -2
@@ -47,6 +47,7 @@ static void usage(void)"\t-d Enable debug\n" "\t-S Create local serial port\n" "\t-s Create local server sockets\n" +"\t-t[port=45550] Create a TCP server\n" "\t-l[num] Number of local controllers\n" "\t-L Create LE only controller\n" "\t-U[num] Number of test LE controllers\n"
@@ -60,6 +61,7 @@ static const struct option main_options[] = { { "debug", no_argument, NULL, 'd' }, { "serial", no_argument, NULL, 'S' }, { "server", no_argument, NULL, 's' }, + { "tcp", optional_argument, NULL, 't' }, { "local", optional_argument, NULL, 'l' }, { "le", no_argument, NULL, 'L' }, { "bredr", no_argument, NULL, 'B' },
@@ -86,6 +88,7 @@ int main(int argc, char *argv[])struct server *server5;bool debug_enabled = false;bool server_enabled = false; +uint16_t tcp_port =0 ;bool serial_enabled = false;int letest_count =0 ;int vhci_count =0 ;
@@ -97,7 +100,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"dSsl::LBAU::T::vh" , + opt =getopt_long (argc, argv,"dSst::l::LBAU::T::vh" , main_options,NULL );if (opt <0 )break ;
@@ -112,6 +115,12 @@ int main(int argc, char *argv[])case 's' : server_enabled = true;break ; +case 't' : +if (optarg) + tcp_port =atoi (optarg); +else + tcp_port =45550 ; +break ;case 'l' :if (optarg) vhci_count =atoi (optarg);
@@ -145,7 +154,7 @@ int main(int argc, char *argv[]) }if (letest_count <1 && vhci_count <1 && !server_enabled && - !serial_enabled) { + !tcp_port && !serial_enabled) {fprintf (stderr,"No emulator specified\n" );return EXIT_FAILURE ; }
@@ -213,5 +222,12 @@ int main(int argc, char *argv[])fprintf (stderr,"Failed to open monitor server\n" ); } +if (tcp_port) { +struct server *tcp_server =server_open_tcp (SERVER_TYPE_BREDRLE , tcp_port); +if (!tcp_server) +fprintf (stderr,"Failed to open TCP port\n" ); +fprintf (stderr,"Listening TCP on 127.0.0.1:%d\n" , tcp_port); + } +return mainloop_run_with_signal (signal_callback,NULL ); }
emulator/server.c +4 -4
@@ -311,7 +311,7 @@ struct server *server_open_unix(enum server_type type, const char *path)return server; } -static int open_tcp (void ) +static int open_tcp (uint16_t port) {struct sockaddr_in addr;int fd, opt =1 ;
@@ -332,7 +332,7 @@ static int open_tcp(void) addr.sin_family =AF_INET ; addr.sin_addr.s_addr =INADDR_ANY ; addr.sin_addr.s_addr =inet_addr ("127.0.0.1" ); - addr.sin_port =htons (45550 ); + addr.sin_port =htons (port);if (bind (fd, (struct sockaddr *) &addr,sizeof (addr)) <0 ) {perror ("Failed to bind server socket" );
@@ -349,7 +349,7 @@ static int open_tcp(void)return fd; } -struct server *server_open_tcp (enum server_type type) +struct server *server_open_tcp (enum server_type type,uint16_t port) {struct server *server;
@@ -361,7 +361,7 @@ struct server *server_open_tcp(enum server_type type) server->type = type; server->id =0x43 ; - server->fd =open_tcp (); + server->fd =open_tcp (port);if (server->fd <0 ) {free (server);return NULL ;
emulator/server.h +1 -1
@@ -22,5 +22,5 @@ enum server_type {struct server ;struct server *server_open_unix (enum server_type type,const char *path); -struct server *server_open_tcp (enum server_type type); +struct server *server_open_tcp (enum server_type type,uint16_t port);void server_close (struct server *server);
Signature · 1 line
2.49.0
PATCH 4/4 emulator: server: handle ISO, use BR/EDR+LE 5.2 by default
In reply to Dmitrii SharshakovAllow passing of ISO packets via the socket by parsing their header.
Set version to 5.2 to expose ISO/CIS and other LE Audio related features when using server mode.
--- emulator/server.c | 11 +++++++++-- lib/hci.h | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
emulator/server.c +9 -2
@@ -118,6 +118,7 @@ again:while (count >0 ) {hci_command_hdr *cmd_hdr;hci_acl_hdr *acl_hdr; +hci_iso_hdr *iso_hdr;if (!client->pkt_data) { client->pkt_type = ptr[0 ];
@@ -140,8 +141,14 @@ again: client->pkt_data =malloc (client->pkt_expect); client->pkt_len =0 ;break ; +case HCI_ISODATA_PKT : + iso_hdr = (hci_iso_hdr *)(ptr +1 ); + client->pkt_expect =HCI_ISO_HDR_SIZE + iso_hdr->dlen +1 ; + client->pkt_data =malloc (client->pkt_expect); + client->pkt_len =0 ; +break ;default : -printf ("packet error\n" ); +printf ("packet error, unknown type: %d\n" , client->pkt_type);return ; }
@@ -218,7 +225,7 @@ static void server_accept_callback(int fd, uint32_t events, void *user_data)switch (server->type) {case SERVER_TYPE_BREDRLE : - type =BTDEV_TYPE_BREDRLE ; + type =BTDEV_TYPE_BREDRLE52 ;break ;case SERVER_TYPE_BREDR : type =BTDEV_TYPE_BREDR ;
lib/hci.h +6 -0
@@ -2311,6 +2311,12 @@ typedef struct { } __attribute__ ((packed)) hci_msg_hdr;#define HCI_MSG_HDR_SIZE 6 +typedef struct { +uint16_t handle; +uint16_t dlen; +} __attribute__ ((packed))hci_iso_hdr ; +#define HCI_ISO_HDR_SIZE 4 +/* Command opcode pack/unpack */ #define cmd_opcode_pack (ogf, ocf) (uint16_t)((ocf & 0x03ff)|(ogf << 10))#define cmd_opcode_ogf (op) (op >> 10)
Signature · 1 line
2.49.0
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 6 lines · On Mon, 9 Jun 2025 16:38:07 +0200 you wrote:
This patch series improves some bits around btvirt, its interfaces, advertising and isochronous channel handling.
These changes enable btvirt to be used for simulation testing of Zephyr Bluetooth stack implementation of BAP server for LE Audio.
Quoted 7 lines
Dmitrii Sharshakov (4):
btdev: implement extended advertising
btdev: fix LE Remove ISO Data Path command
emulator: add option to listen on TCP
emulator: server: handle ISO, use BR/EDR+LE 5.2 by default[...]
Here is the summary with links:
- [BlueZ,1/4] btdev: implement extended advertising
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=964585e3b352
- [BlueZ,2/4] btdev: fix LE Remove ISO Data Path command
(no matching commit)
- [BlueZ,3/4] emulator: add option to listen on TCP
(no matching commit)
- [BlueZ,4/4] emulator: server: handle ISO, use BR/EDR+LE 5.2 by default (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Luiz Augusto von Dentz
maintainerHi Dmitrii,
Quoted 23 lines · On Mon, Jun 9, 2025 at 3:05 PM <[email protected]> wrote:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 6 lines · On Mon, 9 Jun 2025 16:38:07 +0200 you wrote:
This patch series improves some bits around btvirt, its interfaces, advertising and isochronous channel handling.
These changes enable btvirt to be used for simulation testing of Zephyr Bluetooth stack implementation of BAP server for LE Audio.
Quoted 7 lines
Dmitrii Sharshakov (4):
btdev: implement extended advertising
btdev: fix LE Remove ISO Data Path command
emulator: add option to listen on TCP
emulator: server: handle ISO, use BR/EDR+LE 5.2 by default[...]
Here is the summary with links:
- [BlueZ,1/4] btdev: implement extended advertising
Quoted 7 lines
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=964585e3b352- [BlueZ,2/4] btdev: fix LE Remove ISO Data Path command
(no matching commit)
- [BlueZ,3/4] emulator: add option to listen on TCP
(no matching commit)
- [BlueZ,4/4] emulator: server: handle ISO, use BR/EDR+LE 5.2 by default (no matching commit)
Did some minor changes to coding style. Btw, I wonder if we could do some cross testing with this, so testing zephyr vs bluez.
Quoted 7 lines
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Signature · 1 line
Luiz Augusto von Dentz