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:
parent
70271435dd
commit
ec5603da8d
2 changed files with 22 additions and 6 deletions
|
@ -82,6 +82,9 @@ typedef enum bt_l2cap_chan_status {
|
||||||
*/
|
*/
|
||||||
BT_L2CAP_STATUS_SHUTDOWN,
|
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 */
|
/* Total number of status - must be at the end of the enum */
|
||||||
BT_L2CAP_NUM_STATUS,
|
BT_L2CAP_NUM_STATUS,
|
||||||
} __packed bt_l2cap_chan_status_t;
|
} __packed bt_l2cap_chan_status_t;
|
||||||
|
|
|
@ -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)
|
static void l2cap_le_encrypt_change(struct bt_l2cap_chan *chan, u8_t status)
|
||||||
{
|
{
|
||||||
/* Skip channels already connected or there is an ongoing request */
|
/* Skip channels that are not pending waiting for encryption */
|
||||||
if (chan->state != BT_L2CAP_CONNECT ||
|
if (!atomic_test_and_clear_bit(chan->status,
|
||||||
k_work_pending(&chan->rtx_work.work) ||
|
BT_L2CAP_STATUS_ENCRYPT_PENDING)) {
|
||||||
k_delayed_work_remaining_get(&chan->rtx_work)) {
|
|
||||||
return;
|
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)
|
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) {
|
switch (err) {
|
||||||
case BT_L2CAP_LE_ERR_ENCRYPTION:
|
case BT_L2CAP_LE_ERR_ENCRYPTION:
|
||||||
if (chan->chan.required_sec_level >= BT_SECURITY_L2) {
|
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 -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bt_conn_set_security(chan->chan.conn,
|
ret = bt_conn_set_security(chan->chan.conn,
|
||||||
chan->chan.required_sec_level);
|
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,
|
static void le_ecred_conn_rsp(struct bt_l2cap *l2cap, u8_t ident,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue