Skip to content

Commit 7037b11

Browse files
Thalleycfriedt
authored andcommitted
Bluetooth: shell: Update ISO shell to new API
Update the ISO shell commands to use the new ISO API. Signed-off-by: Emil Gydesen <[email protected]>
1 parent c47dae8 commit 7037b11

File tree

1 file changed

+66
-47
lines changed
  • subsys/bluetooth/shell

1 file changed

+66
-47
lines changed

subsys/bluetooth/shell/iso.c

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/*
77
* Copyright (c) 2020 Intel Corporation
8+
* Copyright (c) 2021 Nordic Semiconductor ASA
89
*
910
* SPDX-License-Identifier: Apache-2.0
1011
*/
@@ -51,8 +52,6 @@ static struct bt_iso_chan_ops iso_ops = {
5152

5253
#define DEFAULT_IO_QOS \
5354
{ \
54-
.interval = 10000u, \
55-
.latency = 10u, \
5655
.sdu = 40u, \
5756
.phy = BT_GAP_LE_PHY_2M, \
5857
.rtn = 2u, \
@@ -62,17 +61,20 @@ static struct bt_iso_chan_io_qos iso_tx_qos = DEFAULT_IO_QOS;
6261
static struct bt_iso_chan_io_qos iso_rx_qos = DEFAULT_IO_QOS;
6362

6463
static struct bt_iso_chan_qos iso_qos = {
65-
.sca = BT_GAP_SCA_UNKNOWN,
6664
.tx = &iso_tx_qos,
6765
.rx = &iso_rx_qos,
6866
};
6967

68+
#if defined(CONFIG_BT_ISO_UNICAST)
69+
#define CIS_ISO_CHAN_COUNT 1
70+
7071
struct bt_iso_chan iso_chan = {
7172
.ops = &iso_ops,
7273
.qos = &iso_qos,
7374
};
7475

75-
#if defined(CONFIG_BT_ISO_UNICAST)
76+
static struct bt_iso_cig *cig;
77+
7678
NET_BUF_POOL_FIXED_DEFINE(tx_pool, 1, DATA_MTU, NULL);
7779

7880
static int iso_accept(struct bt_conn *conn, struct bt_iso_chan **chan)
@@ -130,23 +132,17 @@ static int cmd_listen(const struct shell *shell, size_t argc, char *argv[])
130132
return err;
131133
}
132134

133-
static int cmd_bind(const struct shell *shell, size_t argc, char *argv[])
135+
static int cmd_cig_create(const struct shell *sh, size_t argc, char *argv[])
134136
{
135-
struct bt_conn *conns[1];
136-
struct bt_iso_chan *chans[1];
137137
int err;
138+
struct bt_iso_cig_create_param param;
139+
static struct bt_iso_chan *chans[CIS_ISO_CHAN_COUNT];
138140

139-
if (!default_conn) {
140-
shell_error(shell, "Not connected");
141-
return 0;
142-
}
143-
144-
if (iso_chan.conn) {
145-
shell_error(shell, "Already bound");
146-
return 0;
141+
if (cig != NULL) {
142+
shell_error(sh, "Already created");
143+
return -ENOEXEC;
147144
}
148145

149-
conns[0] = default_conn;
150146
chans[0] = &iso_chan;
151147

152148
if (argc > 1) {
@@ -163,31 +159,27 @@ static int cmd_bind(const struct shell *shell, size_t argc, char *argv[])
163159
}
164160

165161
if (argc > 2) {
166-
if (chans[0]->qos->tx) {
167-
chans[0]->qos->tx->interval = strtol(argv[2], NULL, 0);
168-
}
169-
170-
if (chans[0]->qos->rx) {
171-
chans[0]->qos->rx->interval = strtol(argv[2], NULL, 0);
172-
}
162+
param.interval = strtol(argv[2], NULL, 0);
163+
} else {
164+
param.interval = 10000;
173165
}
174166

175167
if (argc > 3) {
176-
chans[0]->qos->packing = strtol(argv[3], NULL, 0);
168+
param.packing = strtol(argv[3], NULL, 0);
169+
} else {
170+
param.packing = 0;
177171
}
178172

179173
if (argc > 4) {
180-
chans[0]->qos->framing = strtol(argv[4], NULL, 0);
174+
param.framing = strtol(argv[4], NULL, 0);
175+
} else {
176+
param.framing = 0;
181177
}
182178

183179
if (argc > 5) {
184-
if (chans[0]->qos->tx) {
185-
chans[0]->qos->tx->latency = strtol(argv[5], NULL, 0);
186-
}
187-
188-
if (chans[0]->qos->rx) {
189-
chans[0]->qos->rx->latency = strtol(argv[5], NULL, 0);
190-
}
180+
param.latency = strtol(argv[5], NULL, 0);
181+
} else {
182+
param.latency = 10;
191183
}
192184

193185
if (argc > 6) {
@@ -220,36 +212,62 @@ static int cmd_bind(const struct shell *shell, size_t argc, char *argv[])
220212
}
221213
}
222214

223-
err = bt_iso_chan_bind(conns, 1, chans);
215+
param.sca = BT_GAP_SCA_UNKNOWN;
216+
param.cis_channels = chans;
217+
param.num_cis = ARRAY_SIZE(chans);
218+
219+
err = bt_iso_cig_create(&param, &cig);
224220
if (err) {
225-
shell_error(shell, "Unable to bind (err %d)", err);
221+
shell_error(sh, "Unable to create CIG (err %d)", err);
226222
return 0;
227223
}
228224

229-
shell_print(shell, "ISO Channel bound");
225+
shell_print(sh, "CIG created");
230226

231227
return 0;
232228
}
233229

234-
static int cmd_connect(const struct shell *shell, size_t argc, char *argv[])
230+
static int cmd_cig_term(const struct shell *sh, size_t argc, char *argv[])
235231
{
236-
struct bt_iso_chan *chans[1];
237232
int err;
238233

239-
if (!iso_chan.conn) {
240-
shell_error(shell, "Not bound");
234+
if (cig == NULL) {
235+
shell_error(sh, "CIG not created");
236+
return -ENOEXEC;
237+
}
238+
239+
err = bt_iso_cig_terminate(cig);
240+
if (err) {
241+
shell_error(sh, "Unable to terminate CIG (err %d)", err);
241242
return 0;
242243
}
243244

244-
chans[0] = &iso_chan;
245+
shell_print(sh, "CIG terminated");
246+
cig = NULL;
247+
248+
return 0;
249+
}
250+
251+
static int cmd_connect(const struct shell *sh, size_t argc, char *argv[])
252+
{
253+
struct bt_iso_connect_param connect_param = {
254+
.conn = default_conn,
255+
.iso = &iso_chan
256+
};
257+
int err;
258+
259+
if (iso_chan.conn == NULL) {
260+
shell_error(sh, "ISO channel not initialized in a CIG");
261+
return 0;
262+
}
245263

246-
err = bt_iso_chan_connect(chans, 1);
264+
err = bt_iso_chan_connect(&connect_param, 1);
247265
if (err) {
248-
shell_error(shell, "Unable to connect (err %d)", err);
266+
shell_error(sh, "Unable to connect (err %d)", err);
249267
return 0;
250268
}
251269

252-
shell_print(shell, "ISO Connect pending...");
270+
shell_print(sh, "ISO Connect pending...");
253271

254272
return 0;
255273
}
@@ -384,12 +402,12 @@ static int cmd_big_create(const struct shell *shell, size_t argc, char *argv[])
384402

385403
/* TODO: Allow setting QOS from shell */
386404
bis_iso_qos.tx = &iso_tx_qos;
387-
bis_iso_qos.tx->interval = 10000; /* us */
388-
bis_iso_qos.tx->latency = 20; /* ms */
389405
bis_iso_qos.tx->phy = BT_GAP_LE_PHY_2M; /* 2 MBit */
390406
bis_iso_qos.tx->rtn = 2;
391407
bis_iso_qos.tx->sdu = CONFIG_BT_ISO_TX_MTU;
392408

409+
param.interval = 10000; /* us */
410+
param.latency = 20; /* ms */
393411
param.bis_channels = bis_channels;
394412
param.num_bis = BIS_ISO_CHAN_COUNT;
395413
param.encryption = false;
@@ -498,8 +516,9 @@ static int cmd_big_term(const struct shell *shell, size_t argc, char *argv[])
498516

499517
SHELL_STATIC_SUBCMD_SET_CREATE(iso_cmds,
500518
#if defined(CONFIG_BT_ISO_UNICAST)
501-
SHELL_CMD_ARG(bind, NULL, "[dir=tx,rx,txrx] [interval] [packing] [framing] "
502-
"[latency] [sdu] [phy] [rtn]", cmd_bind, 1, 8),
519+
SHELL_CMD_ARG(cig_create, NULL, "[dir=tx,rx,txrx] [interval] [packing] [framing] "
520+
"[latency] [sdu] [phy] [rtn]", cmd_cig_create, 1, 8),
521+
SHELL_CMD_ARG(cig_term, NULL, "Terminate the CIG", cmd_cig_term, 1, 0),
503522
SHELL_CMD_ARG(connect, NULL, "Connect ISO Channel", cmd_connect, 1, 0),
504523
SHELL_CMD_ARG(listen, NULL, "<dir=tx,rx,txrx> [security level]", cmd_listen, 2, 1),
505524
SHELL_CMD_ARG(send, NULL, "Send to ISO Channel [count]",

0 commit comments

Comments
 (0)