Bluetooth: Auto connection procedure

This patch adds support for the LE auto connection procedure.

Two function are introduced to handle auto connections:

__hci_set_auto_connect(): This functions is used to set a given address
as a auto connect address.

__hci_reset_auto_connect(): This function clears hdev->auto_connect
list and removes all background scan triggers.

When an address is set as an auto connect address the background scanning
is triggered.

When we connect to an auto connect device, the background scanning
is untriggered.

If a connection with an auto connect device is terminated we trigger
the background scanning.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Add command to load LE auto connect addresses

This patch adds a new Mgmt command to enable userspace inform the
kernel the remote devices he wants the kernel automaticaly establish
a connection once the device is in range.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Create start_background_scan helper

This patch creates the start_background_scan() function so it can
be reused in the next patch.

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

Some LE controllers don't support scanning and initiating a connection
at the same time. So, for those controllers, we should temporarily
stop the background scanning and start it again once the connection
attempt is finished (successfully or not).

So this patch introduces the hci_check_background_scan() which checks
if the background scanning should be started.

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: Fix background trigger/untrigger functions

This patch fixes to hci_trigger_background_scan() and hci_untrigger_
background_scan() so they can be called concurrently with the device
discovery procedure.

In hci_trigger_background_scan(), if it is the first trigger, we are
supposed to start the background scanning. However, if device discovery
is running, we should not send any HCI command. The background scanning
will be started once the discovery procedure is finished.

In hci_untrigger_background_scan(), if it is the last trigger, we are
supposed to stop the background scanning. However, if discovery is
running, it means the background is stopped so we don't need to send
any HCI command.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Fix hci_initiate_le_connection()

When a LE device we want automatically connect to is found during the
device discovery procedure, we initiate the connection. Since some LE
controllers don't support scanning and initiating state combination,
the scanning will be disabled and, therefore, we should set the
discovery state to DISCOVERY_STOPPED

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Background scan and controller reset

If the controller is reset, the connections are dropped and no
Disconnection Complete Event will be sent to host. This way, no
background scan will be triggered once a auto connect device is
disconnected.

To fix this issue, before reseting the controller, we trigger the
background scan for each auto connect device we are connected to.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Background scan and adapter power on

Once the adapter is powered on, we should start the background scan
if we have triggers registered. This way, we keep the auto connection
procedure running after a power off and power on sequence.

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