Bluetooth: L2CAP: Add status flag to track encrypt pending

This adds a new flag to track if the L2CAP channel is pending waiting
for encryption to be changed to resume connecting.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2020-04-29 16:22:47 -07:00 committed by Johan Hedberg
commit ec5603da8d
2 changed files with 22 additions and 6 deletions

View file

@ -82,6 +82,9 @@ typedef enum bt_l2cap_chan_status {
*/
BT_L2CAP_STATUS_SHUTDOWN,
/** @brief Channel encryption pending status */
BT_L2CAP_STATUS_ENCRYPT_PENDING,
/* Total number of status - must be at the end of the enum */
BT_L2CAP_NUM_STATUS,
} __packed bt_l2cap_chan_status_t;

View file

@ -512,10 +512,9 @@ static int l2cap_ecred_conn_req(struct bt_l2cap_chan **chan, int channels)
static void l2cap_le_encrypt_change(struct bt_l2cap_chan *chan, u8_t status)
{
/* Skip channels already connected or there is an ongoing request */
if (chan->state != BT_L2CAP_CONNECT ||
k_work_pending(&chan->rtx_work.work) ||
k_delayed_work_remaining_get(&chan->rtx_work)) {
/* Skip channels that are not pending waiting for encryption */
if (!atomic_test_and_clear_bit(chan->status,
BT_L2CAP_STATUS_ENCRYPT_PENDING)) {
return;
}
@ -1302,6 +1301,13 @@ static void le_disconn_req(struct bt_l2cap *l2cap, u8_t ident,
static int l2cap_change_security(struct bt_l2cap_le_chan *chan, u16_t err)
{
int ret;
if (atomic_test_bit(chan->chan.status,
BT_L2CAP_STATUS_ENCRYPT_PENDING)) {
return -EINPROGRESS;
}
switch (err) {
case BT_L2CAP_LE_ERR_ENCRYPTION:
if (chan->chan.required_sec_level >= BT_SECURITY_L2) {
@ -1324,8 +1330,15 @@ static int l2cap_change_security(struct bt_l2cap_le_chan *chan, u16_t err)
return -EINVAL;
}
return bt_conn_set_security(chan->chan.conn,
chan->chan.required_sec_level);
ret = bt_conn_set_security(chan->chan.conn,
chan->chan.required_sec_level);
if (ret < 0) {
return ret;
}
atomic_set_bit(chan->chan.status, BT_L2CAP_STATUS_ENCRYPT_PENDING);
return 0;
}
static void le_ecred_conn_rsp(struct bt_l2cap *l2cap, u8_t ident,