sco: Integrate SCO socket option in user space.
Subsystems (3)
v2 cover sco: Integrate SCO socket option in user space.
Hi,
This is the required patches for taking advantage of SCO voice setting from userspace.
RFC v2:
btio option is now called BT_IO_OPT_VOICE as per Luiz suggestion. Last patch include additional test in sco-tester for outgoing 1.1 connection, this include a change to hciemu (hciemu_get_features) to access feature array from btdev to get/set features.
RFC v1:
add a sco-tester that uses hci_vhci to test SCO.
Regards,
Fred
Frédéric Dalleau (6):
lib: SCO voice setting support header
btio: Add option for SCO voice setting
btiotest: Add option for SCO voice setting
scotest: Add option for SCO voice setting
sco-tester: Initial sco tester implementation
sco-tester: Test BT_VOICE option with 1.1 adapter
Makefile.tools | 12 +- btio/btio.c | 18 +- btio/btio.h | 1 + emulator/btdev.c | 57 +++++ emulator/btdev.h | 1 + lib/bluetooth.h | 8 + src/shared/hciemu.c | 8 + src/shared/hciemu.h | 1 + tools/btiotest.c | 20 +- tools/sco-tester.c | 605 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/scotest.c | 40 +++- 11 files changed, 759 insertions(+), 12 deletions(-) create mode 100644 tools/sco-tester.c
Signature · 1 line
1.7.9.5
RFC v2 1/6 lib: SCO voice setting support header
Modify headers to enable support for changing SCO voice setting. Corresponding commit implements functionality on kernel side.
--- lib/bluetooth.h | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/bluetooth.h +8 -0
@@ -104,6 +104,14 @@ struct bt_security {*/ #define BT_CHANNEL_POLICY_AMP_PREFERRED 2 +#define BT_VOICE 11 +struct bt_voice { +uint16_t setting; +}; + +#define BT_VOICE_TRANSPARENT 0x0003 +#define BT_VOICE_CVSD_16BIT 0x0060 +/* Connection and socket states */ enum {BT_CONNECTED =1 ,/* Equal to TCP_ESTABLISHED to make net code happy */
Signature · 1 line
1.7.9.5
RFC v2 2/6 btio: Add option for SCO voice setting
In reply to Frédéric Dalleau--- btio/btio.c | 18 +++++++++++++++--- btio/btio.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-)
btio/btio.c +15 -3
@@ -78,6 +78,7 @@ struct set_opts {uint8_t mode;int flushable;uint32_t priority; +uint16_t voice; };struct connect {
@@ -723,9 +724,10 @@ static int sco_connect(int sock, const bdaddr_t *dst)return 0 ; } -static gboolean sco_set (int sock,uint16_t mtu,GError **err) +static gboolean sco_set (int sock,uint16_t mtu,uint16_t voice,GError **err) {struct sco_options sco_opt; +struct bt_voice bt_voice;socklen_t len;if (!mtu)
@@ -745,6 +747,13 @@ static gboolean sco_set(int sock, uint16_t mtu, GError **err)return FALSE; } + bt_voice.setting = voice; +if (setsockopt (sock,SOL_BLUETOOTH ,BT_VOICE , &bt_voice, +sizeof (bt_voice)) <0 ) { +ERROR_FAILED (err,"setsockopt(BT_VOICE)" , errno); +return FALSE; + } +return TRUE; }
@@ -832,6 +841,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,case BT_IO_OPT_PRIORITY : opts->priority =va_arg (args, int);break ; +case BT_IO_OPT_VOICE : + opts->voice =va_arg (args, int); +break ;default :g_set_error (err,BT_IO_ERROR ,EINVAL ,"Unknown option %d" , opt);
@@ -1310,7 +1322,7 @@ gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...)case BT_IO_RFCOMM :return rfcomm_set (sock, opts.sec_level, opts.master, err);case BT_IO_SCO : -return sco_set (sock, opts.mtu, err); +return sco_set (sock, opts.mtu, opts.voice, err);default :g_set_error (err,BT_IO_ERROR ,EINVAL ,"Unknown BtIO type %d" , type);
@@ -1377,7 +1389,7 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, }if (sco_bind (sock, &opts->src, err) <0 ) goto failed; -if (!sco_set (sock, opts->mtu, err)) +if (!sco_set (sock, opts->mtu, opts->voice, err)) goto failed;break ;default :
btio/btio.h +1 -0
@@ -55,6 +55,7 @@ typedef enum {BT_IO_OPT_MODE ,BT_IO_OPT_FLUSHABLE ,BT_IO_OPT_PRIORITY , +BT_IO_OPT_VOICE , } BtIOOption; typedef enum {
Signature · 1 line
1.7.9.5
Re: [RFC v2 2/6] btio: Add option for SCO voice setting
Hi Frédéric,
Quoted 9 lines · Frédéric Dalleau
btio/btio.c +2
-1-static gboolean sco_set (int sock,uint16_t mtu,GError **err) +static gboolean sco_set (int sock,uint16_t mtu,uint16_t voice,GError **err) {struct sco_options sco_opt; +struct bt_voice bt_voice;socklen_t len;if (!mtu)
btio/btio.c static gboolean sco_set(int sock, uint16_t mtu, GError **err) · line 756
Quoted 10 lines
btio/btio.c +7
-0@@ -745,6 +747,13 @@ static gboolean sco_set(int sock, uint16_t mtu, GError **err)return FALSE; } + bt_voice.setting = voice; +if (setsockopt (sock,SOL_BLUETOOTH ,BT_VOICE , &bt_voice, +sizeof (bt_voice)) <0 ) { +ERROR_FAILED (err,"setsockopt(BT_VOICE)" , errno); +return FALSE; + } +
Why are you calling setsockopt even when a value was not explicitly passed to BtIO? There's an MTU check "if (!mtu)" so surely there should also be a check for "if (!voice)", right?
Johan
RFC v2 3/6 btiotest: Add option for SCO voice setting
In reply to Frédéric Dalleau--- tools/btiotest.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
tools/btiotest.c +14 -5
@@ -445,7 +445,7 @@ static void rfcomm_listen(const char *src, uint8_t ch, gboolean defer,g_io_channel_unref (rc_srv); } -static void sco_connect (const char *src,const char *dst,int disconn) +static void sco_connect (const char *src,const char *dst,int disconn,int voice) {struct io_data *data;GError *err =NULL ;
@@ -460,12 +460,14 @@ static void sco_connect(const char *src, const char *dst, int disconn) &err,BT_IO_OPT_SOURCE , src,BT_IO_OPT_DEST , dst, +BT_IO_OPT_VOICE , voice, BT_IO_OPT_INVALID); else data->io = bt_io_connect(connect_cb, data, (GDestroyNotify ) io_data_unref, &err,BT_IO_OPT_DEST , dst, +BT_IO_OPT_VOICE , voice,BT_IO_OPT_INVALID );if (!data->io) {
@@ -476,7 +478,7 @@ static void sco_connect(const char *src, const char *dst, int disconn) }static void sco_listen (const char *src,gboolean defer,int reject, -int disconn,int accept) +int disconn,int accept,int voice) {struct io_data *data;BtIOConnect conn;
@@ -501,11 +503,14 @@ static void sco_listen(const char *src, gboolean defer, int reject, (GDestroyNotify ) io_data_unref, &err,BT_IO_OPT_SOURCE , src, +BT_IO_OPT_VOICE , voice, BT_IO_OPT_INVALID); else sco_srv =bt_io_listen (conn, cfm, data, (GDestroyNotify ) io_data_unref, - &err,BT_IO_OPT_INVALID ); + &err, +BT_IO_OPT_VOICE , voice, +BT_IO_OPT_INVALID );if (!sco_srv) {printf ("Listening failed: %s\n" , err->message);
@@ -520,6 +525,7 @@ static int opt_channel = -1;static int opt_psm =0 ;static gboolean opt_sco = FALSE;static gboolean opt_defer = FALSE; +static gint opt_voice =0 ;static char *opt_dev =NULL ;static int opt_reject =-1 ;static int opt_disconn =-1 ;
@@ -546,6 +552,9 @@ static GOptionEntry options[] = { "Use SCO" }, {"defer" ,'d' ,0 ,G_OPTION_ARG_NONE , &opt_defer, "Use DEFER_SETUP for incoming connections" }, + { "voice", 'V', 0, G_OPTION_ARG_INT, &opt_voice, +"Voice setting " + "(0x0060 CVSD, 0x0003 Transparent)" }, { "sec-level", 'S', 0, G_OPTION_ARG_INT, &opt_sec, "Security level" }, { "update-sec-level", 'U', 0, G_OPTION_ARG_INT, &opt_update_sec,
@@ -611,10 +620,10 @@ int main(int argc, char *argv[])if (opt_sco) {if (argc >1 ) -sco_connect (opt_dev, argv[1 ], opt_disconn); +sco_connect (opt_dev, argv[1 ], opt_disconn, opt_voice);else sco_listen (opt_dev, opt_defer, opt_reject, - opt_disconn, opt_accept); + opt_disconn, opt_accept, opt_voice); }signal (SIGTERM , sig_term);
Signature · 1 line
1.7.9.5
RFC v2 4/6 scotest: Add option for SCO voice setting
In reply to Frédéric Dalleau--- tools/btiotest.c | 3 ++- tools/scotest.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-)
tools/btiotest.c +2 -1
@@ -445,7 +445,8 @@ static void rfcomm_listen(const char *src, uint8_t ch, gboolean defer,g_io_channel_unref (rc_srv); } -static void sco_connect (const char *src,const char *dst,int disconn,int voice) +static void sco_connect (const char *src,const char *dst,int disconn, +int voice) {struct io_data *data;GError *err =NULL ;
tools/scotest.c +37 -3
@@ -58,6 +58,7 @@ static long data_size = 672;static bdaddr_t bdaddr;static int defer_setup =0 ; +static int voice =0 ;static float tv2fl (struct timeval tv) {
@@ -68,6 +69,7 @@ static int do_connect(char *svr) {struct sockaddr_sco addr;struct sco_conninfo conn; +struct bt_voice opts;socklen_t optlen;int sk;
@@ -90,6 +92,15 @@ static int do_connect(char *svr) goto error; } +/* SCO voice setting */ +memset (&opts,0 ,sizeof (opts)); + opts.setting = voice; +if (setsockopt (sk,SOL_BLUETOOTH ,BT_VOICE , &opts,sizeof (opts)) <0 ) { +syslog (LOG_ERR ,"Can't set socket options: %s (%d)" , +strerror (errno), errno); + goto error; + } +/* Connect to remote device */ memset (&addr,0 ,sizeof (addr)); addr.sco_family =AF_BLUETOOTH ;
@@ -229,8 +240,16 @@ error:static void dump_mode (int sk) { +struct bt_voice opts;int len; +/* SCO voice setting */ +memset (&opts,0 ,sizeof (opts)); + opts.setting = voice; +if (setsockopt (sk,SOL_BLUETOOTH ,BT_VOICE , &opts,sizeof (opts)) <0 ) +syslog (LOG_ERR ,"Can't set socket options: %s (%d)" , +strerror (errno), errno); +if (defer_setup) { len =read (sk, buf,sizeof (buf));if (len <0 )
@@ -248,9 +267,17 @@ static void dump_mode(int sk)static void recv_mode (int sk) {struct timeval tv_beg,tv_end,tv_diff; +struct bt_voice opts;long total;int len; +/* SCO voice setting */ +memset (&opts,0 ,sizeof (opts)); + opts.setting = voice; +if (setsockopt (sk,SOL_BLUETOOTH ,BT_VOICE , &opts,sizeof (opts)) <0 ) +syslog (LOG_ERR ,"Can't set socket options: %s (%d)" , +strerror (errno), errno); +if (defer_setup) { len =read (sk, buf,sizeof (buf));if (len <0 )
@@ -271,7 +298,9 @@ static void recv_mode(int sk)if (r <0 )syslog (LOG_ERR ,"Read failed: %s (%d)" ,strerror (errno), errno); -return ; +if (errno !=ENOTCONN ) +return ; + r =0 ; } total += r; }
@@ -381,7 +410,8 @@ static void usage(void)"\t-n connect and be silent (client)\n" "Options:\n" "\t[-b bytes]\n" - "\t[-W seconds] enable deferred setup\n"); +"\t[-W seconds] enable deferred setup\n" + "\t[-V voice] select SCO voice setting (0x0060 cvsd, 0x0003 transparent)\n"); }int main (int argc ,char *argv[])
@@ -389,7 +419,7 @@ int main(int argc ,char *argv[])struct sigaction sa;int opt, sk, mode =RECV ; -while ((opt =getopt (argc, argv,"rdscmnb:W:" )) !=EOF ) { +while ((opt =getopt (argc, argv,"rdscmnb:W:V:" )) !=EOF ) {switch (opt) {case 'r' : mode =RECV ;
@@ -423,6 +453,10 @@ int main(int argc ,char *argv[]) defer_setup =atoi (optarg);break ; +case 'V' : + voice =atoi (optarg); +break ; +default :usage ();exit (1 );
Signature · 1 line
1.7.9.5
RFC v2 5/6 sco-tester: Initial sco tester implementation
In reply to Frédéric Dalleau--- Makefile.tools | 12 +- emulator/btdev.c | 32 ++++ tools/sco-tester.c | 541 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 584 insertions(+), 1 deletion(-) create mode 100644 tools/sco-tester.c
Makefile.tools +11 -1
@@ -28,7 +28,7 @@ endif if EXPERIMENTAL noinst_PROGRAMS += emulator/btvirt emulator/b1ee \ tools/mgmt-tester tools/gap-tester \ - tools/l2cap-tester + tools/l2cap-tester tools/sco-tester emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ monitor/mainloop.h monitor/mainloop.c \
@@ -65,6 +65,16 @@ tools_gap_tester_SOURCES = $(gdbus_sources) \ src/shared/tester.h src/shared/tester.c tools_gap_tester_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ + +tools_sco_tester_SOURCES = tools/sco-tester.c monitor/bt.h \ + emulator/btdev.h emulator/btdev.c \ + emulator/bthost.h emulator/bthost.c \ + src/shared/util.h src/shared/util.c \ + src/shared/mgmt.h src/shared/mgmt.c \ + src/shared/hciemu.h src/shared/hciemu.c \ + src/shared/tester.h src/shared/tester.c +tools_sco_tester_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@ + endif if TOOLS
emulator/btdev.c +32 -0
@@ -660,6 +660,29 @@ static void conn_complete(struct btdev *btdev,send_event (btdev,BT_HCI_EVT_CONN_COMPLETE , &cc,sizeof (cc)); } + +static void sync_conn_complete (struct btdev *btdev,uint16_t voice_setting, +uint8_t status) +{ +struct bt_hci_evt_sync_conn_complete cc; + +if (!btdev->conn) +return ; + + cc.status = status; +memcpy (cc.bdaddr, btdev->conn->bdaddr,6 ); + + cc.handle =cpu_to_le16 (status ==BT_HCI_ERR_SUCCESS ?257 :0 ); + cc.link_type =0x02 ; + cc.tx_interval =0x000c ; + cc.retrans_window =0x06 ; + cc.rx_pkt_len =60 ; + cc.tx_pkt_len =60 ; + cc.air_mode = (voice_setting ==0x0060 ) ?0x02 :0x03 ; + +send_event (btdev,BT_HCI_EVT_SYNC_CONN_COMPLETE , &cc,sizeof (cc)); +} +static void conn_request (struct btdev *btdev,const uint8_t *bdaddr) {struct btdev *remote =find_btdev_by_bdaddr (bdaddr);
@@ -840,6 +863,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,const struct bt_hci_cmd_set_event_mask_page2 *semp2;const struct bt_hci_cmd_le_set_event_mask *lsem;const struct bt_hci_cmd_le_set_adv_data *lsad; +const struct bt_hci_cmd_setup_sync_conn *ssc;struct bt_hci_rsp_read_default_link_policy rdlp;struct bt_hci_rsp_read_stored_link_key rslk;struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1492,6 +1516,14 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,cmd_complete (btdev, opcode, &status,sizeof (status));break ; +case BT_HCI_CMD_SETUP_SYNC_CONN : + ssc = data; + status =BT_HCI_ERR_SUCCESS ; +cmd_status (btdev,BT_HCI_ERR_SUCCESS , opcode); +sync_conn_complete (btdev, ssc->voice_setting, +BT_HCI_ERR_SUCCESS ); +break ; +default : goto unsupported; }
tools/sco-tester.c new file +541 -0
541 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [RFC v2 5/6] sco-tester: Initial sco tester implementation
Hi Frederic,
Quoted 6 lines · Frédéric Dalleau
--- Makefile.tools | 12 +- emulator/btdev.c | 32 ++++ tools/sco-tester.c | 541 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 584 insertions(+), 1 deletion(-) create mode 100644 tools/sco-tester.c
Could you please split the emulator update to a separate patch that comes before the first sco-tester patch?
Johan
RFC v2 6/6 sco-tester: Test BT_VOICE option with 1.1 adapter
In reply to Frédéric Dalleau--- emulator/btdev.c | 25 +++++++++++++++++++ emulator/btdev.h | 1 + src/shared/hciemu.c | 8 +++++++ src/shared/hciemu.h | 1 + tools/sco-tester.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 1 deletion(-)
emulator/btdev.c +25 -0
@@ -450,6 +450,11 @@ const uint8_t *btdev_get_bdaddr(struct btdev *btdev)return btdev->bdaddr; } +uint8_t *btdev_get_features (struct btdev *btdev) +{ +return btdev->features; +} +void btdev_set_command_handler (struct btdev *btdev,btdev_command_func handler,void *user_data) {
@@ -683,6 +688,22 @@ static void sync_conn_complete(struct btdev *btdev, uint16_t voice_setting,send_event (btdev,BT_HCI_EVT_SYNC_CONN_COMPLETE , &cc,sizeof (cc)); } +static void sco_conn_complete (struct btdev *btdev,uint8_t status) +{ +struct bt_hci_evt_conn_complete cc; + +if (!btdev->conn) +return ; + + cc.status = status; +memcpy (cc.bdaddr, btdev->conn->bdaddr,6 ); + cc.handle =cpu_to_le16 (status ==BT_HCI_ERR_SUCCESS ?257 :0 ); + cc.link_type =0x00 ; + cc.encr_mode =0x00 ; + +send_event (btdev,BT_HCI_EVT_CONN_COMPLETE , &cc,sizeof (cc)); +} +static void conn_request (struct btdev *btdev,const uint8_t *bdaddr) {struct btdev *remote =find_btdev_by_bdaddr (bdaddr);
@@ -1524,6 +1545,10 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode, BT_HCI_ERR_SUCCESS);break ; +case BT_HCI_CMD_ADD_SCO_CONN : +sco_conn_complete (btdev,BT_HCI_ERR_SUCCESS ); +break ; +default : goto unsupported; }
emulator/btdev.h +1 -0
@@ -66,6 +66,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id);void btdev_destroy (struct btdev *btdev);const uint8_t *btdev_get_bdaddr (struct btdev *btdev); +uint8_t *btdev_get_features (struct btdev *btdev);void btdev_set_command_handler (struct btdev *btdev,btdev_command_func handler,void *user_data);
src/shared/hciemu.c +8 -0
@@ -353,6 +353,14 @@ const char *hciemu_get_address(struct hciemu *hciemu)return hciemu->bdaddr_str; } +uint8_t *hciemu_get_features (struct hciemu *hciemu) +{ +if (!hciemu || !hciemu->master_dev) +return NULL ; + +return btdev_get_features (hciemu->master_dev); +} +const uint8_t *hciemu_get_master_bdaddr (struct hciemu *hciemu) {if (!hciemu || !hciemu->master_dev)
src/shared/hciemu.h +1 -0
@@ -40,6 +40,7 @@ void hciemu_unref(struct hciemu *hciemu);struct bthost *hciemu_client_get_host (struct hciemu *hciemu);const char *hciemu_get_address (struct hciemu *hciemu); +uint8_t *hciemu_get_features (struct hciemu *hciemu);const uint8_t *hciemu_get_master_bdaddr (struct hciemu *hciemu);const uint8_t *hciemu_get_client_bdaddr (struct hciemu *hciemu);
tools/sco-tester.c +65 -1
106 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [RFC v2 6/6] sco-tester: Test BT_VOICE option with 1.1 adapter
Hi Frederic,
Quoted 7 lines · Frédéric Dalleau
--- emulator/btdev.c | 25 +++++++++++++++++++ emulator/btdev.h | 1 + src/shared/hciemu.c | 8 +++++++ src/shared/hciemu.h | 1 + tools/sco-tester.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 1 deletion(-)
Here also, please split the emulator and hciemu changes to separate patches before the sco-tester patch.
Johan
Re: [RFC v2 6/6] sco-tester: Test BT_VOICE option with 1.1 adapter
Hi Frederic,
Quoted 11 lines · Johan Hedberg
Hi Frederic,
Quoted 7 lines · Frédéric Dalleau
--- emulator/btdev.c | 25 +++++++++++++++++++ emulator/btdev.h | 1 + src/shared/hciemu.c | 8 +++++++ src/shared/hciemu.h | 1 + tools/sco-tester.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 1 deletion(-)
Quoted 2 lines
Here also, please split the emulator and hciemu changes to separate patches before the sco-tester patch.
Since you never came back with these fixes and we need to get this feature progressing I went ahead and did the necessary changes myself. The patches are now upstream.
Johan