Bluetooth: Add connection security level tracking

Change-Id: Ib2a84f964e5b189969127774ae982539ba38ad87
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-08-05 16:18:05 +02:00 committed by Anas Nashif
commit 9de0ef392f
3 changed files with 12 additions and 6 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);
}