Bluetooth: Use HCI_MGMT instead of HCI_LINK_KEYS flag

Use HCI_MGMT flag instead of HCI_LINK_KEYS flag. There is a problem with
HCI_LINK_KEYS flag since it is set only when link keys are loaded. Otherwise
kernel assumes that old interface is used.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Acked-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Bluetooth: Remove unneeded flag

Remove HCI_LINK_KEYS flag since using HCI_MGMT is enough for test that
user space expects the kernel managing link keys.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Acked-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Bluetooth: hidp: using strlcpy instead of strncpy, also beautify code.

For NULL terminated string, need always let it ended by zero.

Since have already called memcpy() to initialize 'ci', so need not
redundant initialization.

Better use ''if(session->hid) {} else if(session->input) {}"" instead
of ''if(session->hid) {}; if(session->input) {};''

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Bluetooth: Add missing reset_resume dev_pm_ops

Add missing reset_resume dev_pm_ops. Missing reset_resume results in the
following message after power management device test. This change sets
reset_resume to btusb_resume().

[ 2506.936134] btusb 1-1.5:1.0: no reset_resume for driver btusb?
[ 2506.936137] btusb 1-1.5:1.1: no reset_resume for driver btusb?

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Bluetooth: Make hci_le_create_connection return error

This patch changes hci_le_create_connection function so it returns
error if hci_send_cmd fails instead of void. It also does the proper
error handling in hci_connect_le in case hci_le_create_connection
fails.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Initialize hci_conn fields in hci_connect_le

This patch moves some hci_conn fields initialization from hci_le_
create_connection. It makes more sense to initialize these fields
within the function that creates the hci_conn object.

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 refactor 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: Add passive scanning helpers

This patch adds helpers to add and remove the passive scanning trigger.
As long as the number of triggers are greater than zero, we keep the
passive scanning enabled. Once the number of triggers reaches zero,
the passive scanning is disabled.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Add LE initiate connection helper

This patch introduces the initiate_le_connection local helper which
will be used create LE connection once the target device is found in
range.

This patch also moves code to handle a pending connection failure
into a helper called fail_pending and re-uses it in enable_passive_
scan_complete and initiate_le_connection_complete.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Change LE connection routine

In order to better support LE connection requirements, such as
multiple connections and re-connections, we should change the
current LE connection routine. Today, we use the direct
connection establishment procedure which has some limitations
and, therefore, requires extra connection management at user-space
in order to support LE connection requirements.

The new LE connection routine this patch introduces is based on
the general connection establishment procedure (described in Core
spec) and work as follows: The host starts scanning for LE devices,
once the device we want to connect to is in-range, it initiates a
connection. The procedure is terminated when the connection is
established or when the host terminates the procedure.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Handle hci_conn timeout in BT_CONNECT

In order to properly cancel a LE hci_conn in BT_CONNECT state we
should check if we are scanning for devices or initiating a
connection. To identify this situation this patch adds a bool flag
in struct hci_conn to indicate if the connection is initiating. So,
if connection is initiating, we send the LE Create Connection Cancel
command. Otherwise, we remove the passive scanning trigger.

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 since
this handling is now done in initiate_le_connection_complete callback
in hci_conn.c.

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

This patch removes the unused functions hci_le_create_connection and
hci_le_create_connection_cancel.

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

If we get an HCI error while enabling the passive scanning, we should
fail all pending LE connection. There is no point in keep pending LE
connections if we cannot enable the passive scanning. So, this patch
introduces the fail_all_le_pending local helper which removes the
passive scanning trigger and calls fail_pending for each pending LE
hci_conn object.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Add proper handling for initiating failure

Once multiple LE connection attempt is supported, we will have more
than one connection in BT_CONNECT state. Thus, looking up for hci_
conn objects in BT_CONNECT state won't be enough to get the hci_
conn object we want.

For that reason, this patch introduces the hci_conn_find_le_initiating
helper which finds the only one hci_conn object with the le_initiating
flag set. This way, we are able to find the LE connection which issued
the LE Create Connection HCI command.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Make fail_pending non-static

This patch makes fail_pending helper non-local and reuse it in
hci_event.c.

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

Some LE controllers don't support scanning and initiating a connection
at the same time. So, for those controllers, we should temporarily
disable the passive scanning and enable it again once the connection
is terminated (successfully or not).

So this patch introduces the hci_conn_check_passive_scanning which
checks if the passive scanning should be enabled.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Remove BT_CONNECT check in hci_connect_le

Since we now properly support multiple LE connection attempt we can
safely remove the BT_CONNECT check in hci_connect_le.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Check ongoing LE connections attempt

Since LE controllers supports only one connection attempt at a time,
we should check if there already is a connection attempt in hci_conn_
check_le_pending.

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