Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/bluetooth/tester/src/bttester.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,17 @@ struct l2cap_read_supported_commands_rp {
uint8_t data[0];
} __packed;

#define L2CAP_CONNECT_OPT_ECFC 0x01
#define L2CAP_CONNECT_OPT_HOLD_CREDIT 0x02

#define L2CAP_CONNECT 0x02
struct l2cap_connect_cmd {
uint8_t address_type;
uint8_t address[6];
uint16_t psm;
uint16_t mtu;
uint8_t num;
uint8_t ecfc;
uint8_t options;
} __packed;
struct l2cap_connect_rp {
uint8_t num;
Expand Down
18 changes: 14 additions & 4 deletions tests/bluetooth/tester/src/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static struct channel {
uint8_t chan_id; /* Internal number that identifies L2CAP channel. */
struct bt_l2cap_le_chan le;
bool in_use;
bool hold_credit;
struct net_buf *pending_credit;
} channels[CHANNELS];

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

if (!chan->pending_credit) {
if (chan->hold_credit && !chan->pending_credit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion that this might be better named as "user_confirm". Since that is how returning EINPROGRESS is documented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep chan option same as in BTP spec (and not zephyr's implementation detail)

/* no need for extra ref, as when returning EINPROGRESS user
* becomes owner of the netbuf
*/
Expand Down Expand Up @@ -195,9 +196,10 @@ static void connect(uint8_t *data, uint16_t len)
uint16_t mtu = sys_le16_to_cpu(cmd->mtu);
uint8_t buf[sizeof(*rp) + CHANNELS];
uint8_t i = 0;
bool ecfc = cmd->options & L2CAP_CONNECT_OPT_ECFC;
int err;

if (cmd->num > CHANNELS || mtu > DATA_MTU_INITIAL) {
if (cmd->num == 0 || cmd->num > CHANNELS || mtu > DATA_MTU_INITIAL) {
goto fail;
}

Expand All @@ -217,20 +219,24 @@ static void connect(uint8_t *data, uint16_t len)
chan->le.rx.mtu = mtu;
rp->chan_id[i] = chan->chan_id;
allocated_channels[i] = &chan->le.chan;

chan->hold_credit = cmd->options & L2CAP_CONNECT_OPT_HOLD_CREDIT;
}

if (cmd->num == 1 && cmd->ecfc == 0) {
if (cmd->num == 1 && !ecfc) {
err = bt_l2cap_chan_connect(conn, &chan->le.chan, cmd->psm);
if (err < 0) {
goto fail;
}
} else if (cmd->ecfc == 1) {
} else if (ecfc) {
#if defined(CONFIG_BT_L2CAP_ECRED)
err = bt_l2cap_ecred_chan_connect(conn, allocated_channels,
cmd->psm);
if (err < 0) {
goto fail;
}
#else
goto fail;
#endif
} else {
LOG_ERR("Invalid 'num' parameter value");
Expand Down Expand Up @@ -459,6 +465,10 @@ static void listen(uint8_t *data, uint16_t len)
goto fail;
}

if (cmd->psm == 0) {
goto fail;
}

server = get_free_server();
if (!server) {
goto fail;
Expand Down