WIP: Bluetooth: LE auto connection procedure

This patch implements the LE auto connection procedure.

After hci_dev_do_close() call, we are not supposed to send any HCI
command to the controller. Since now __hci_clear_auto_connect() may
send a HCI command, we need to call __hci_clear_auto_connect() before
calling hci_dev_do_close(). For that reason, this patch also moves the
__hci_clear_auto_connect() call up in hci_unregister_dev().

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 stop 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 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>