diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 5f8fd59799f..ccdd08598dc 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -2358,6 +2358,20 @@ 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; + } + + atomic_set_bit(ch->chan.status, + BT_L2CAP_STATUS_ENCRYPT_PENDING); + + return 0; + } + return l2cap_le_conn_req(ch); }