Bluetooth: Fix not setting keys for connection as master

If no keys are set for connection look-up it done. If keys are already
present there is no need for another look-up.

Change-Id: I0518772c4c9d8458b4b79aa7cb34a049324fb552
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-11-04 15:14:06 +01:00 committed by Anas Nashif
commit 47e3db235d

View file

@ -150,22 +150,23 @@ static int start_security(struct bt_conn *conn)
#if defined(CONFIG_BLUETOOTH_CENTRAL) #if defined(CONFIG_BLUETOOTH_CENTRAL)
case BT_HCI_ROLE_MASTER: case BT_HCI_ROLE_MASTER:
{ {
struct bt_keys *keys; if (!conn->keys) {
conn->keys = bt_keys_find(BT_KEYS_LTK, &conn->le.dst);
}
keys = bt_keys_find(BT_KEYS_LTK, &conn->le.dst); if (!conn->keys || !(conn->keys->keys & BT_KEYS_LTK)) {
if (!keys) {
return bt_smp_send_pairing_req(conn); return bt_smp_send_pairing_req(conn);
} }
if (conn->required_sec_level > BT_SECURITY_MEDIUM && if (conn->required_sec_level > BT_SECURITY_MEDIUM &&
keys->type != BT_KEYS_AUTHENTICATED) { conn->keys->type != BT_KEYS_AUTHENTICATED) {
return bt_smp_send_pairing_req(conn); return bt_smp_send_pairing_req(conn);
} }
return bt_conn_le_start_encryption(conn, keys->ltk.rand, return bt_conn_le_start_encryption(conn, conn->keys->ltk.rand,
keys->ltk.ediv, conn->keys->ltk.ediv,
keys->ltk.val, conn->keys->ltk.val,
keys->enc_size); conn->keys->enc_size);
} }
#endif /* CONFIG_BLUETOOTH_CENTRAL */ #endif /* CONFIG_BLUETOOTH_CENTRAL */
#if defined(CONFIG_BLUETOOTH_PERIPHERAL) #if defined(CONFIG_BLUETOOTH_PERIPHERAL)