Bluetooth: Fix not reseting required sec level on error

If pairing failed before encryption was enabled or if enabling
encryption failed (eg due to remote device missing LTK) required
security level should be reset.

Otherwise it is not possible to re-try with setting security level.

Error reporting to application is still missing though.

Change-Id: I085e3ee116bd04304a4c4563cc40f9d40262447e
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-10-13 16:17:42 +02:00 committed by Anas Nashif
commit 08415ff1d7
2 changed files with 14 additions and 4 deletions

View file

@ -735,16 +735,20 @@ static void hci_encrypt_change(struct bt_buf *buf)
BT_DBG("status %u handle %u encrypt 0x%02x\n", evt->status, handle,
evt->encrypt);
if (evt->status) {
return;
}
conn = bt_conn_lookup_handle(handle);
if (!conn) {
BT_ERR("Unable to look up conn with handle %u\n", handle);
return;
}
if (evt->status) {
/* TODO report error */
/* reset required security level in case of error */
conn->required_sec_level = conn->sec_level;
bt_conn_put(conn);
return;
}
conn->encrypt = evt->encrypt;
update_sec_level(conn);

View file

@ -413,6 +413,12 @@ static void smp_reset(struct bt_conn *conn)
atomic_set(&smp->allowed_cmds, 0);
atomic_set(&smp->flags, 0);
if (conn->required_sec_level != conn->sec_level) {
/* TODO report error */
/* reset required security level in case of error */
conn->required_sec_level = conn->sec_level;
}
switch(conn->role) {
#if defined(CONFIG_BLUETOOTH_CENTRAL)
case BT_HCI_ROLE_MASTER: