Bluetooth: L2CAP: Release channel when connect request fails
Release the l2cap channel when sending the l2cap connect request fails. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
5f00ee1e88
commit
521034c63d
1 changed files with 26 additions and 8 deletions
|
@ -509,6 +509,8 @@ static int l2cap_ecred_conn_req(struct bt_l2cap_chan **chan, int channels)
|
|||
|
||||
static void l2cap_le_encrypt_change(struct bt_l2cap_chan *chan, uint8_t status)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Skip channels that are not pending waiting for encryption */
|
||||
if (!atomic_test_and_clear_bit(chan->status,
|
||||
BT_L2CAP_STATUS_ENCRYPT_PENDING)) {
|
||||
|
@ -516,9 +518,7 @@ static void l2cap_le_encrypt_change(struct bt_l2cap_chan *chan, uint8_t status)
|
|||
}
|
||||
|
||||
if (status) {
|
||||
bt_l2cap_chan_remove(chan->conn, chan);
|
||||
bt_l2cap_chan_del(chan);
|
||||
return;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (chan->ident) {
|
||||
|
@ -536,7 +536,15 @@ static void l2cap_le_encrypt_change(struct bt_l2cap_chan *chan, uint8_t status)
|
|||
}
|
||||
|
||||
/* Retry to connect */
|
||||
l2cap_le_conn_req(BT_L2CAP_LE_CHAN(chan));
|
||||
err = l2cap_le_conn_req(BT_L2CAP_LE_CHAN(chan));
|
||||
if (err) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return;
|
||||
fail:
|
||||
bt_l2cap_chan_remove(chan->conn, chan);
|
||||
bt_l2cap_chan_del(chan);
|
||||
}
|
||||
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
||||
|
||||
|
@ -2345,6 +2353,8 @@ void bt_l2cap_init(void)
|
|||
static int l2cap_le_connect(struct bt_conn *conn, struct bt_l2cap_le_chan *ch,
|
||||
uint16_t psm)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (psm < L2CAP_LE_PSM_FIXED_START || psm > L2CAP_LE_PSM_DYN_END) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -2359,11 +2369,9 @@ static int l2cap_le_connect(struct bt_conn *conn, struct bt_l2cap_le_chan *ch,
|
|||
ch->chan.psm = psm;
|
||||
|
||||
if (conn->sec_level < ch->chan.required_sec_level) {
|
||||
int err;
|
||||
|
||||
err = bt_conn_set_security(conn, ch->chan.required_sec_level);
|
||||
if (err) {
|
||||
return err;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
atomic_set_bit(ch->chan.status,
|
||||
|
@ -2372,7 +2380,17 @@ static int l2cap_le_connect(struct bt_conn *conn, struct bt_l2cap_le_chan *ch,
|
|||
return 0;
|
||||
}
|
||||
|
||||
return l2cap_le_conn_req(ch);
|
||||
err = l2cap_le_conn_req(ch);
|
||||
if (err) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
bt_l2cap_chan_remove(conn, &ch->chan);
|
||||
bt_l2cap_chan_del(&ch->chan);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int l2cap_ecred_init(struct bt_conn *conn,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue