Skip to content

Commit 17c0132

Browse files
sjanccarlescufi
authored andcommitted
tests: bluetooth: tester: Add support for L2CAP channels options
This allows for better control over IUT behaviour by Upper Tester. PTS and TS require inconsistent behaviour in terms of how IUT should return credits. Some tests require return on explicit UT request and some require that IUT returns credits autonomously. Signed-off-by: Szymon Janc <[email protected]>
1 parent 1a11d1b commit 17c0132

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

tests/bluetooth/tester/src/bttester.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,17 @@ struct l2cap_read_supported_commands_rp {
739739
uint8_t data[0];
740740
} __packed;
741741

742+
#define L2CAP_CONNECT_OPT_ECFC 0x01
743+
#define L2CAP_CONNECT_OPT_HOLD_CREDIT 0x02
744+
742745
#define L2CAP_CONNECT 0x02
743746
struct l2cap_connect_cmd {
744747
uint8_t address_type;
745748
uint8_t address[6];
746749
uint16_t psm;
747750
uint16_t mtu;
748751
uint8_t num;
749-
uint8_t ecfc;
752+
uint8_t options;
750753
} __packed;
751754
struct l2cap_connect_rp {
752755
uint8_t num;

tests/bluetooth/tester/src/l2cap.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static struct channel {
3535
uint8_t chan_id; /* Internal number that identifies L2CAP channel. */
3636
struct bt_l2cap_le_chan le;
3737
bool in_use;
38+
bool hold_credit;
3839
struct net_buf *pending_credit;
3940
} channels[CHANNELS];
4041

@@ -60,7 +61,7 @@ static int recv_cb(struct bt_l2cap_chan *l2cap_chan, struct net_buf *buf)
6061
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_DATA_RECEIVED,
6162
CONTROLLER_INDEX, recv_cb_buf, sizeof(*ev) + buf->len);
6263

63-
if (!chan->pending_credit) {
64+
if (chan->hold_credit && !chan->pending_credit) {
6465
/* no need for extra ref, as when returning EINPROGRESS user
6566
* becomes owner of the netbuf
6667
*/
@@ -195,9 +196,10 @@ static void connect(uint8_t *data, uint16_t len)
195196
uint16_t mtu = sys_le16_to_cpu(cmd->mtu);
196197
uint8_t buf[sizeof(*rp) + CHANNELS];
197198
uint8_t i = 0;
199+
bool ecfc = cmd->options & L2CAP_CONNECT_OPT_ECFC;
198200
int err;
199201

200-
if (cmd->num > CHANNELS || mtu > DATA_MTU_INITIAL) {
202+
if (cmd->num == 0 || cmd->num > CHANNELS || mtu > DATA_MTU_INITIAL) {
201203
goto fail;
202204
}
203205

@@ -217,20 +219,24 @@ static void connect(uint8_t *data, uint16_t len)
217219
chan->le.rx.mtu = mtu;
218220
rp->chan_id[i] = chan->chan_id;
219221
allocated_channels[i] = &chan->le.chan;
222+
223+
chan->hold_credit = cmd->options & L2CAP_CONNECT_OPT_HOLD_CREDIT;
220224
}
221225

222-
if (cmd->num == 1 && cmd->ecfc == 0) {
226+
if (cmd->num == 1 && !ecfc) {
223227
err = bt_l2cap_chan_connect(conn, &chan->le.chan, cmd->psm);
224228
if (err < 0) {
225229
goto fail;
226230
}
227-
} else if (cmd->ecfc == 1) {
231+
} else if (ecfc) {
228232
#if defined(CONFIG_BT_L2CAP_ECRED)
229233
err = bt_l2cap_ecred_chan_connect(conn, allocated_channels,
230234
cmd->psm);
231235
if (err < 0) {
232236
goto fail;
233237
}
238+
#else
239+
goto fail;
234240
#endif
235241
} else {
236242
LOG_ERR("Invalid 'num' parameter value");
@@ -459,6 +465,10 @@ static void listen(uint8_t *data, uint16_t len)
459465
goto fail;
460466
}
461467

468+
if (cmd->psm == 0) {
469+
goto fail;
470+
}
471+
462472
server = get_free_server();
463473
if (!server) {
464474
goto fail;

0 commit comments

Comments
 (0)