ongoing work
Bluetooth: Remove unused hci_find_ltk function

Now that LTKs are always looked up based on bdaddr (with EDiv/Rand
checks done after a successful lookup) the hci_find_ltk function is not
needed anymore. This patch removes the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Rename hci_find_ltk_by_addr to hci_find_ltk

Now that hci_find_ltk_by_addr is the only LTK lookup function there's no
need to keep the long name anymore. This patch shortens the function
name to simply hci_find_ltk.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Fix setting correct EDiv value with SC

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Track authentication method in SMP context

For Secure Connections we'll select the authentication method as soon as
we receive the public key, but only use it later (both when actually
triggering the method as well as when determining the quality of the
resulting LTK). Store the method therefore in the SMP context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Add selection of the SC authentication method

This patch adds code to select the authentication method for Secure
Connections based on the local and remote capabilities. A new
DSP_PASSKEY method is also added for displaying the passkey - something
that is not part of legacy SMP pairing.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Detect SMP SC debug keys

We need to be able to detect if the remote side used a debug key for the
pairing. This patch adds the debug key defines and sets a flag to
indicate that a debug key was used.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Set correct LTK type and authentication for SC

After generating the LTK we should set the correct type (normal SC or
debug) and authentication information for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Add support for SC just-works pairing

If the just-works method was chosen we shouldn't send anything to user
space but simply proceed with sending the DHKey Check PDU. This patch
adds the necessary code for it.
Bluetooth: Fix BR/EDR Link Key type when derived through LE SC

We need to set the correct Link Key type based on the properties of the
LE SC pairing that it was derived from. If debug keys were used the type
should be a debug key, and the authenticated vs unauthenticated
information should be set on what kind of security level was reached.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Add passkey entry support for LE SC

The passkey entry mechanism involves either both sides requesting the
user for a passkey, or one side requesting the passkey while the other
one displays it. The behavior as far as SMP PDUs are concerned are
considerably different from numeric comparison and therefore requires
several new functions to handle it.

In essence passkey entry involves both sides gradually committing to
each bit of the passkey which involves 20 rounds of pairing confirm and
pairing random PDUS being sent in both directions.

This patch adds a new smp->passkey_round variable to track the current
round of the passkey commitment and reuses the variables already present
in struct hci_conn for the passkey and entered key count.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Add support for waiting for passkey request

When our side is the acceptor of a passkey entry based SC pairing and
the remote side performs passkey notification instead of passkey entry,
we will receive the first pairing confirm PDU before we know what the
passkey is.

This patch adds a new SMP flag to indicate that we are waiting for the
passkey and reuses the existing CFM_PENDING flag to indicate that we've
received a pairing confirm PDU but not yet reacted to it. Once we
finally receive the passkey we check these flags and proceed with the
pairing as appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Fix missing check for remote LE SC public key

The pairing confirm & random PDUs should be sent only after a successful
public key exchange. There is already a flag for it and we should
indicate failure if we receive the Pairing Confirm before we have
received the remote public key.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Wait for remote LE SC Public Key when not initiator

According to the LE SC spec the Initiating device sends its key first
and the non-initiating device responds with its key after.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Add debug logs for local LE SC public/private key pair

This is useful for debugging purposes when trying to fix issues either
with the local or the remote ECDH implementation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Fix byte order of msg passed to aes_cmac

The aes_cmac function expects the message to be in big-endian byte
order. This patch fixes the ordering before passing to the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Add debug logs for remote LE SC public key

Seeing the key in the logs can be handy for debugging issues in the
local or remote crypto implementation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Fix DHKey Check sending order for slave role

According to the LE SC specification the initiating device sends its
DHKey check first and the non-initiating devices sends its DHKey check
as a response to this.
Bluetooth: Fix letting the remote do too many passkey rounds

There should be at most 20 passkey entry rounds, and if the remote tries
to do more we should just ignore the PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Fix pairing with LE SC STK if LTK is not generated

If the key distribution/generation bits indicate that LTK is not to be
generated we should use the STK as the encryption key. This patch adds a
new type for it and ensures the right actions are taken.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>