Skip to content

Commit d7c1804

Browse files
committed
apps/bttester: mark L2CAP channel as used in connect
This will prevent returning same channel every time in `get_free_channel()`.
1 parent de56c3a commit d7c1804

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

apps/bttester/src/l2cap.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ static void connect(uint8_t *data, uint16_t len)
398398
ble_addr_t *addr = (void *) data;
399399
uint16_t mtu = htole16(cmd->mtu);
400400
int rc;
401-
int i;
401+
int i, j;
402402

403403
SYS_LOG_DBG("connect: type: %d addr: %s", addr->type, bt_hex(addr->val, 6));
404404

@@ -420,6 +420,8 @@ static void connect(uint8_t *data, uint16_t len)
420420
SYS_LOG_ERR("No free channels");
421421
goto fail;
422422
}
423+
/* temporarily mark channel as used to select next one */
424+
chan->state = 1;
423425

424426
rp->chan_ids[i] = chan->chan_id;
425427

@@ -430,6 +432,15 @@ static void connect(uint8_t *data, uint16_t len)
430432
}
431433
}
432434

435+
/* mark selected channels as unused again */
436+
for (i = 0; i < cmd->num; i++) {
437+
for (j = 0; j < CHANNELS; j++) {
438+
if (rp->chan_ids[i] == channels[j].chan_id) {
439+
channels[j].state = 0;
440+
}
441+
}
442+
}
443+
433444
if (cmd->num == 1) {
434445
rc = ble_l2cap_connect(desc.conn_handle, htole16(cmd->psm),
435446
mtu, sdu_rx[0],

0 commit comments

Comments
 (0)