summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2020-09-28 15:59:51 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-07-22 13:31:44 -0700
commitb1b575cf1720521bfe7ae58f6d2276d07add326b (patch)
tree3a000651e4d8acbda325e91614d9880e6aab0f02 /tools
parent8dc5b5e1ba6b500ee2126bde11601d152cc5d973 (diff)
downloadbluez-b1b575cf1720521bfe7ae58f6d2276d07add326b.tar.gz
btio: Add support for ISO sockets
This adds support to create objects that map to ISO sockets.
Diffstat (limited to 'tools')
-rw-r--r--tools/btiotest.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/tools/btiotest.c b/tools/btiotest.c
index 70d74ffbe..193e1395b 100644
--- a/tools/btiotest.c
+++ b/tools/btiotest.c
@@ -29,6 +29,25 @@
#define DEFAULT_ACCEPT_TIMEOUT 2
static int opt_update_sec = 0;
+#define DEFAULT_IO_QOS \
+{ \
+ .interval = 10000, \
+ .latency = 10, \
+ .sdu = 40, \
+ .phy = 0x02, \
+ .rtn = 2, \
+}
+
+struct bt_iso_qos qos = {
+ .cig = BT_ISO_QOS_CIG_UNSET,
+ .cis = BT_ISO_QOS_CIG_UNSET,
+ .sca = 0x07,
+ .packing = 0x00,
+ .framing = 0x00,
+ .in = DEFAULT_IO_QOS,
+ .out = DEFAULT_IO_QOS,
+};
+
struct io_data {
guint ref;
GIOChannel *io;
@@ -36,6 +55,7 @@ struct io_data {
int disconn;
int accept;
int voice;
+ struct bt_iso_qos *qos;
};
static void io_data_unref(struct io_data *data)
@@ -67,6 +87,7 @@ static struct io_data *io_data_new(GIOChannel *io, int reject, int disconn,
data->reject = reject;
data->disconn = disconn;
data->accept = accept;
+ data->qos = &qos;
return io_data_ref(data);
}
@@ -530,9 +551,88 @@ static void sco_listen(const char *src, gboolean defer, int reject,
g_io_channel_unref(sco_srv);
}
+static void iso_connect(const char *src, const char *dst, int disconn)
+{
+ struct io_data *data;
+ GError *err = NULL;
+
+ printf("Connecting ISO to %s\n", dst);
+
+ data = io_data_new(NULL, -1, disconn, -1);
+
+ if (src)
+ data->io = bt_io_connect(connect_cb, data,
+ (GDestroyNotify) io_data_unref,
+ &err,
+ BT_IO_OPT_SOURCE, src,
+ BT_IO_OPT_DEST, dst,
+ BT_IO_OPT_MODE, BT_IO_MODE_ISO,
+ BT_IO_OPT_QOS, data->qos,
+ 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_MODE, BT_IO_MODE_ISO,
+ BT_IO_OPT_QOS, data->qos,
+ BT_IO_OPT_INVALID);
+
+ if (!data->io) {
+ printf("Connecting to %s failed: %s\n", dst, err->message);
+ g_error_free(err);
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void iso_listen(const char *src, gboolean defer, int reject,
+ int disconn, int accept)
+{
+ struct io_data *data;
+ BtIOConnect conn;
+ BtIOConfirm cfm;
+ GIOChannel *iso_srv;
+ GError *err = NULL;
+
+ printf("Listening for ISO connections\n");
+
+ if (defer) {
+ conn = NULL;
+ cfm = confirm_cb;
+ } else {
+ conn = connect_cb;
+ cfm = NULL;
+ }
+
+ data = io_data_new(NULL, reject, disconn, accept);
+
+ if (src)
+ iso_srv = bt_io_listen(conn, cfm, data,
+ (GDestroyNotify) io_data_unref,
+ &err,
+ BT_IO_OPT_SOURCE, src,
+ BT_IO_OPT_MODE, BT_IO_MODE_ISO,
+ BT_IO_OPT_INVALID);
+ else
+ iso_srv = bt_io_listen(conn, cfm, data,
+ (GDestroyNotify) io_data_unref,
+ &err,
+ BT_IO_OPT_MODE, BT_IO_MODE_ISO,
+ BT_IO_OPT_INVALID);
+
+ if (!iso_srv) {
+ printf("Listening failed: %s\n", err->message);
+ g_error_free(err);
+ exit(EXIT_FAILURE);
+ }
+
+ g_io_channel_unref(iso_srv);
+}
+
static int opt_channel = -1;
static int opt_psm = 0;
static gboolean opt_sco = FALSE;
+static gboolean opt_iso = FALSE;
static gboolean opt_defer = FALSE;
static gint opt_voice = 0;
static char *opt_dev = NULL;
@@ -559,6 +659,8 @@ static GOptionEntry options[] = {
"(0 BR/EDR 1 LE Public 2 LE Random" },
{ "sco", 's', 0, G_OPTION_ARG_NONE, &opt_sco,
"Use SCO" },
+ { "iso", 'o', 0, G_OPTION_ARG_NONE, &opt_iso,
+ "Use ISO" },
{ "defer", 'd', 0, G_OPTION_ARG_NONE, &opt_defer,
"Use DEFER_SETUP for incoming connections" },
{ "voice", 'V', 0, G_OPTION_ARG_INT, &opt_voice,
@@ -637,6 +739,14 @@ int main(int argc, char *argv[])
opt_disconn, opt_accept, opt_voice);
}
+ if (opt_iso) {
+ if (argc > 1)
+ iso_connect(opt_dev, argv[1], opt_disconn);
+ else
+ iso_listen(opt_dev, opt_defer, opt_reject,
+ opt_disconn, opt_accept);
+ }
+
signal(SIGTERM, sig_term);
signal(SIGINT, sig_term);