Bluetooth: Use HCI request for LE connection

This patch adds a new helper for initiating LE conneciton which uses
the HCI request framework. This patch also changes the hci_connect_le()
so it uses the new helper instead of the old hci_le_create_connection().

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

Since we now use hci_initiate_le_connection() helper for creating new
LE connections, we can safely remove hci_le_create_connection().

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Remove hci_cs_le_create_conn event handler

This patch removes the hci_cs_le_create_conn event handler since this
handling is now done in create_le_connection_complete() callback in
hci_conn.c.

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

This patch organizes hci_connect_le() logic and adds extra comments
to improve code's readability.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Refactor LE Connection Complete HCI event handler

This patch does some code refactorig in LE Connection Complete HCI
event handler. It basically adds a switch statement to separate new
master connection code from new slave connection code.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Locking in hci_le_conn_complete_evt

This patch moves hci_dev_lock and hci_dev_unlock calls to where they
are really required, reducing the critical region in hci_le_conn_
complete_evt function. hdev->lock is required only in hci_conn_del
and hci_conn_add call to protect concurrent add and remove operations
in hci_conn_hash list.

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

This patch adds helpers to trigger and untrigger the background
scanning. As long as the number of triggers are greater than zero,
we keep the background scanning running. Once the number of triggers
reaches zero, it is stopped.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Add auto_connect list

This patch adds to hdev the auto_connect list. This list holds the
LE device address of remote device the kernel should automatically
connect to in case the device is in range.

This patch also adds helper functions to manipulate the auto_
connect list. Some of those functions are used in upcomming
patches.

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

This patch implements the LE auto connection procedure.

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>