Bluetooth: Add dummy handler for LE SC keypress notification

Since we don not actively try to clear the keypress notification bit we
might get these PDUs. To avoid failing the pairing process add a simple
dummy handler for these for now.

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 input
from the user 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 user response we check these flags and proceed with
the pairing as appropriate.

The flag is used more than just waiting for the passkey (e.g. numeric
comparison too) as in subsequent patches that will be necessary to
control the flow of the DHKey Check exchange.

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: 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: Always STK for encrypting during LE SC pairing

The updated LE SC spec requires us to use the STK for encrypting during
pairing. This patch does the necessary changes as well as adds checks to
the DHKey Check exchange so that we don't trigger encryption until we've
received the remote DHKey Check value.

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