Bluetooth: Introduce hdev->pend_le_conn list

This patch introduces the hdev->pend_le_conn list which holds the
device addresses the kernel should autonomously connect. It also
introduces some helper functions to manipulate the list.

The list and helper functions will be used by the next patch which
implements the LE auto connection infrastructure.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Introduce LE auto connection infrastructure

This patch introduces the LE auto connection infrastructure.
This infrastructure will be used to implement the auto_connect
options from hci_conn_params.

The auto connection mechanism works as follows: When the first
device address is inserted into hdev->pend_le_conns list, we
start the background scanning. Once the target device is found
in range, the kernel creates the connection. If connection is
established successfully, the device address is removed from
hdev->pend_le_conns list. Finally, when the last device
address is removed, the background scanning is stopped.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Re-enable background scan in case of error

Since we temporarily stop the background scanning during connection
establishment, we should re-enable it in case something goes wrong
during establishment. So this patch adds a __hci_update_background_
scan() call in create_le_conn_complete() and hci_le_conn_complete_
evt() error flow.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Temporarily stop background scanning on discovery

If the user send a mgmt start discovery command while the background
scanning is running, we should temporarily stop it. Once the discovery
finishes, we start the background scanning again.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Move pend_le_conn helpers up in file

The helper __pend_le_conns_clear() will be used in hci_dev_do_close()
to remove all pending LE connections when the device is close. So to
avoid forward declaration, this patch moves the helper, as well as its
related helpers, up in the hci_core.c file.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Auto connection and power on

When hdev is closed (e.g. Mgmt power off command, RFKILL or controller
is reset), the ongoing active connections are silently dropped by the
controller (no Disconnection Complete Event is sent to host). For that
reason, the devices that require HCI_AUTO_CONN_ALWAYS are not added to
hdev->pend_le_conns list and they won't auto connect.

So to fix this issue, during hdev closing, we remove all pending LE
connections. After adapter is powered on, we add a pending LE connection
for each HCI_AUTO_CONN_ALWAYS address.

This way, the auto connection mechanism works propely after a power
off and power on sequence as well as RFKILL block/unblock.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bleutooth: Add support for auto connect options

This patch adds support for the HCI_AUTO_CONN_ALWAYS and HCI_AUTO_
CONN_LINK_LOSS options from struct hci_conn_params.

The HCI_AUTO_CONN_ALWAYS option configures the kernel to always re-
establish the connection, no matter the reason the connection was
terminated. This feature is required by some LE profiles such as
HID over GATT, Health Thermometer and Blood Pressure. These profiles
require the host autonomously connect to the device as soon as it
enters in connectable mode (start advertising) so the device is able
to delivery a notification or indication.

The BT_AUTO_CONN_LINK_LOSS option configures the kernel to re-
establish the connection in case the connection was terminated due
to a link loss. This feature is required by the majority of LE
profiles such as Proximity, Find Me, Cycling Speed and Cadence and
Time.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
WIP: Bluetooth: Add le_auto_conn file on debugfs

This patch adds to debugfs the le_auto_conn file. Reading this file
we get a list a all auto connect devices. The file format is the
following:
<address> <address type> <auto_connect>

Writting on this file will add a new address to LE auto connect
list.

This file is created only if LE is enabled.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>