Bluetooth: Add connection security level tracking
Change-Id: Ib2a84f964e5b189969127774ae982539ba38ad87 Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
parent
faec70c367
commit
9de0ef392f
3 changed files with 12 additions and 6 deletions
|
@ -293,6 +293,8 @@ struct bt_conn *bt_conn_add(const bt_addr_le_t *peer, uint8_t role)
|
|||
atomic_set(&conn->ref, 1);
|
||||
conn->role = role;
|
||||
bt_addr_le_copy(&conn->dst, peer);
|
||||
conn->sec_level = BT_SECURITY_LOW;
|
||||
conn->required_sec_level = BT_SECURITY_LOW;
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
@ -478,18 +480,16 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec)
|
|||
}
|
||||
|
||||
/* nothing to do */
|
||||
if (sec == BT_SECURITY_LOW) {
|
||||
if (conn->sec_level >= sec || conn->required_sec_level >= sec) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* for now we only support JustWorks */
|
||||
if (sec > BT_SECURITY_MEDIUM) {
|
||||
/* for now we only support legacy pairing */
|
||||
if (sec > BT_SECURITY_HIGH) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (conn->encrypt) {
|
||||
return 0;
|
||||
}
|
||||
conn->required_sec_level = sec;
|
||||
|
||||
if (conn->role == BT_HCI_ROLE_SLAVE) {
|
||||
return bt_smp_send_security_req(conn);
|
||||
|
|
|
@ -62,6 +62,8 @@ struct bt_conn {
|
|||
bt_addr_le_t dst;
|
||||
|
||||
uint8_t encrypt;
|
||||
bt_security_t sec_level;
|
||||
bt_security_t required_sec_level;
|
||||
|
||||
uint16_t rx_len;
|
||||
struct bt_buf *rx;
|
||||
|
|
|
@ -359,6 +359,10 @@ static void hci_encrypt_change(struct bt_buf *buf)
|
|||
|
||||
conn->encrypt = evt->encrypt;
|
||||
|
||||
if (conn->encrypt) {
|
||||
conn->sec_level = BT_SECURITY_MEDIUM;
|
||||
}
|
||||
|
||||
bt_l2cap_encrypt_change(conn);
|
||||
bt_conn_put(conn);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue