struct bt_keys *bt_keys_get_type(int type, const bt_addr_le_t *addr) { struct bt_keys *keys; BT_DBG("type %d %s", type, bt_addr_le_str(addr)); keys = bt_keys_find(type, addr); if (keys) { return keys; } keys = bt_keys_get_addr(addr); if (!keys) { return NULL; } bt_keys_add_type(keys, type); return keys; }
static int start_security(struct bt_conn *conn) { #if defined(CONFIG_BLUETOOTH_BREDR) if (conn->type == BT_CONN_TYPE_BR) { if (atomic_test_bit(conn->flags, BT_CONN_BR_PAIRING)) { return -EBUSY; } if (conn->required_sec_level > BT_SECURITY_HIGH) { return -ENOTSUP; } if (bt_conn_get_io_capa() == BT_IO_NO_INPUT_OUTPUT && conn->required_sec_level > BT_SECURITY_MEDIUM) { return -EINVAL; } return conn_auth(conn); } #endif /* CONFIG_BLUETOOTH_BREDR */ switch (conn->role) { #if defined(CONFIG_BLUETOOTH_CENTRAL) && defined(CONFIG_BLUETOOTH_SMP) case BT_HCI_ROLE_MASTER: { if (!conn->keys) { conn->keys = bt_keys_find(BT_KEYS_LTK_P256, &conn->le.dst); if (!conn->keys) { conn->keys = bt_keys_find(BT_KEYS_LTK, &conn->le.dst); } } if (!conn->keys || !(conn->keys->keys & (BT_KEYS_LTK | BT_KEYS_LTK_P256))) { return bt_smp_send_pairing_req(conn); } if (conn->required_sec_level > BT_SECURITY_MEDIUM && !atomic_test_bit(&conn->keys->flags, BT_KEYS_AUTHENTICATED)) { return bt_smp_send_pairing_req(conn); } if (conn->required_sec_level > BT_SECURITY_HIGH && !atomic_test_bit(&conn->keys->flags, BT_KEYS_AUTHENTICATED) && !(conn->keys->keys & BT_KEYS_LTK_P256)) { return bt_smp_send_pairing_req(conn); } /* LE SC LTK and legacy master LTK are stored in same place */ return bt_conn_le_start_encryption(conn, conn->keys->ltk.rand, conn->keys->ltk.ediv, conn->keys->ltk.val, conn->keys->enc_size); } #endif /* CONFIG_BLUETOOTH_CENTRAL && CONFIG_BLUETOOTH_SMP */ #if defined(CONFIG_BLUETOOTH_PERIPHERAL) && defined(CONFIG_BLUETOOTH_SMP) case BT_HCI_ROLE_SLAVE: return bt_smp_send_security_req(conn); #endif /* CONFIG_BLUETOOTH_PERIPHERAL && CONFIG_BLUETOOTH_SMP */ default: return -EINVAL; } }