Bluetooth: Fix HCI request for Inquiry command

Some HCI commands don't send a Command Complete Event once the
HCI command has completed and they require special handling by
the HCI request framework. HCI Inquiry command is one of those.

The HCI Inquiry command causes the controller to enter in inquiry
mode. A successful Command Status Event for this command means the
the controller is running the inquiry procedure, therefore the HCI
Inquiry command has completed.

For that reason, the HCI request framework should consider the
HCI Inquiry command has completed once the host receives the
Command Status Event, instead of the Inquiry Complete Event. The
Inquiry Complete Event means the inquiry procedure has completed
so the controller isn't in inquiry mode anymore.

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

Since the HCI request framework was properly fixed to handle HCI
Inquiry commands, the hci_req_sync call will return as soon as the
HCI Inquiry command completes (not the Inquiry procedure).

However, in hci_inquiry, we want to block the user thread until the
Inquiry procedure completes. To achieve that, we should wait unitl
the HCI_INQUIRY flag is cleared.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Change LE scanning timeout macros

Define LE scanning timeout macros in jiffies just like we do for
others timeout macros.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Add LE scan type macros

This patch adds macros for active and passive LE scan type values.
The LE_SCAN_DISABLE was also defined since it will be used in future
by LE connection routine and GAP Observer Role support.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Add macros for filter duplicates values

This patch adds macros for filter_duplicates parameter values from
HCI LE Set Scan Enable command. It also fixes le_scan_enable_req
function so it uses the LE_SCAN_FILTER_DUP_ENABLE macro instead of
a magic number.

The LE_SCAN_FILTER_DUP_DISABLE was also defined since it will be
used in future by LE connection routine and it is required to
properly support the GAP Observer Role.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Rename LE_SCANNING_* macros

This patch renames LE_SCANNING_ENABLED and LE_SCANNING_DISABLED
macros to LE_SCAN_ENABLE and LE_SCAN_DISABLE in order to keep
the same prefix others LE scan macros have. It also fixes le_scan_
enable_req function so it uses the LE_SCAN_ENABLE macro instead of
a magic number.

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

In order to use HCI request framework in start_discovery, we'll need
to call inquiry_cache_flush in mgmt.c. Therefore, this patch makes
inquiry_cache_flush non-static

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Update start_discovery to use HCI request

This patch modifies the start_discovery function so it uses the new
HCI request framework.

We build the HCI request according to the discovery type (add inquiry
and LE scan HCI commands) and run the HCI request. We also register
the start_discovery_complete request callback which handles all mgmt
command status and command complete events for this command. This way,
we move all start_discovery mgmt handling code spread in hci_event.c
to a single place in mgmt.c.

This patch also merges the LE-only and interleaved discovery type
cases since these cases are pretty much the same now.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Remove start discovery handling from hci_event.c

Since all mgmt start discovery command status and command complete
events are now handled in start_discovery_complete callback in mgmt.c,
we can remove this handling from hci_event.c.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Move discovery macros to hci_core.h

Some of the discovery macros will be used in hci_core so we need to
define them in commom place such as hci_core.h.

This patch moves discovery macros to hci_core.h and also adds the
DISCOV_ prefix to them.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Update le_scan_disable_work to use HCI request

This patch updates the le_scan_disable_work function so it uses the
HCI request framework. All discovery state handling are done in the
in le_scan_disable_work_complete callback.

This patch also changes the le_scan_disable_work behavior by adding
the HCI Inquiry command to the request in case we are running the
interleaved discovery. This way we don't need the extra logic in
hci_cc_le_set_scan_enable to start the inquiry procedure.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Update stop_discovery to use HCI request

This patch modifies the stop_discovery function so it uses the new
HCI request framework.

We build the HCI request according to the current discovery state
and run the HCI request. We also register the stop_discovery_complete
request callback which handles all mgmt command status and command
complete events for mgmt stop discovery command.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Remove stop discovery handling from hci_event.c

Since all mgmt stop discovery command status and command complete
events are now handled in stop_discovery_complete callback in mgmt.c,
we can remove this handling from hci_event.c.

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

This patch does a trivial refactoring in hci_cc_le_set_scan_enable.
Since start and stop discovery command failure are now handled in
mgmt layer, the status check became empty. So, we can move it to
outside the switch statement.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Don't send Device Found Event

We should send MGMT Device Found Event only if we are running the
Device Discovery procedure (started by the MGMT Start Discovery
Command).

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

This patch removes the LE scan helpers hci_le_scan and hci_cancel_
le_scan and all code related to it. We now use the HCI request
framework in device discovery functionality and this helper are
no longer needed.

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

This patch removes hci_do_inquiry and hci_cancel_inquiry helpers. We
now use the HCI request framework in device discovery functionality
and these helpers are no longer needed.

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

This patch removes the hci_cc_le_set_scan_param event handler. This
handler became empty since we use the HCI request framework to enable
LE scanning.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Bluetooth: Rename le_scan_disable delayed work

Since the le_scan_disable_work is basically a timer which disables
the ongoing LE scanning and start the inquiry procedure (in case of
the interleaved discovery), it makes more sense to call this function
hci_discovery_timeout.

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