Bluetooth: Refactor l2cap_send_disconn_req

l2cap_send_disconn_req takes 3 parameters of which conn might be
derived from chan. Make this conversion inside l2cap_send_disconn_req.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Bluetooth: AMP: Mark controller radio powered down after HCIDEVDOWN

After getting HCIDEVDOWN controller did not mark itself as 0x00 which
means: "The Controller radio is available but is currently physically
powered down". The result was even if the hdev was down we return
in controller list value 0x01 "status 0x01 (Bluetooth only)".

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Bluetooth: Add HCI command to set advertising parameters

Add command to set advertising parameters before enable it.

Signed-off-by: Jefferson Delfes <jefferson.delfes@openbossa.org>
Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Set advertising parameters on LE setup

To enable broadcasting we need to set up the advertising parameters. As these
parameters are constant (only observer is using until now), they are set on LE
setup.

This patch makes the advertising non-connectable as default. To make connectable
advertising using 'hciconfig leadv' command, you must change these parameters
first.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Add set controller data MGMT command

Set controller data allows user to set broadcast advertising data. The available
data types are 'service data' and 'manufacturer specific data'.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Add unset controller data MGMT command

Unset controller data allows user to remove some data previously set to be
broadcasted via set controller data MGMT command.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Add set broadcaster MGMT command

This command will enable or disable broadcaster mode. Data can be added
with set_controller_data command.

If LE_ENABLED is set, the HCI_OP_LE_SET_ADV_ENABLE command will be sent.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Advertise controller data in broadcaster mode

In broadcaster mode, the adapter must advertise the data set by user in
set_controller_data.

According to the spec, the flags field must be ommited if its value is zero.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Stop to acquire hdev lock inside hci_update_ad

In order to enable broadcaster mode even in power off state, hci_update_ad
must be called in mgmt_powered function, that already has the lock.

Removing the locking logic from inside this function is not a big deal as
most of the functions that already call hci_update_ad also have the lock.

The function was renamed to __hci_update_ad to follow the convention.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Enable on-the-fly update of broadcast data

The broadcast data can be updated with no need to re-enable broadcaster
mode.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Enable support for broadcaster mode when powered off.

We have to enable advertising in mgmt_powered if broadcaster mode is on.

We also need to update the advertising data in mgmt_powered if brodcaster
mode is on.

As the advertising data is already being updated on mgmt_powered function,
we don't need to update it also in hci_dev_open.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Refactor le scan helpers to enable observer support

It was added a parameter called 'reason' to le scan helpers (hci_do_le_scan and
hci_cancel_le_scan). Distinguishing the reason to enbale/disable le scan will be
important when both discovery and observer are implemented.

'reason' was also added do hdev structure (hdev.le_scan_req_reason) in order
to make hci_cc_le_set_scan_enable to behave correctly.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Add set observer MGMT command

This command will enable or disable observer mode.

If LE_ENABLED is set the HCI_OP_LE_SET_SCAN_PARAMS and HCI_OP_LE_SET_SCAN_ENABLE
commands will be sent. Observer will perform a passive scan with no timeout.

If discovery is required when observer is enabled, le scan is restarted in
active mode.

If observer is enabled when discovery finishes, passive le scan
is enabled.

If observer mode is required when discovery is on going, the le scan mode does
not change until the end of discovery process.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Bluetooth: Enable support for observer mode when powered off.

We have to enable le scan in mgmt_powered if observer mode is on.

Signed-off-by: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>