From 5f00ee1e88e4dd2ca2f76166ae917c15a4aedfd2 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Wed, 29 Jul 2020 20:04:03 +0200 Subject: [PATCH] Bluetooth: L2CAP: Elevate security level if requested by application Elevate the security level before sending the connection request if the application has set a required security level on the channel. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/l2cap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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); }