Skip to content

Commit 81ad6fd

Browse files
jhedbergholtmann
authored andcommitted
Bluetooth: Remove unnecessary stop_scan_complete function
The stop_scan_complete function was used as an intermediate step before doing the actual connection creation. Since we're using hci_request there's no reason to have this extra function around, i.e. we can simply put both HCI commands into the same request. The single task that the intermediate function had, i.e. indicating discovery as stopped is now taken care of by a new HCI_LE_SCAN_INTERRUPTED flag which allows us to do the discovery state update when the stop scan command completes. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 317ac8c commit 81ad6fd

3 files changed

Lines changed: 16 additions & 43 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ enum {
140140
HCI_FAST_CONNECTABLE,
141141
HCI_BREDR_ENABLED,
142142
HCI_6LOWPAN_ENABLED,
143+
HCI_LE_SCAN_INTERRUPTED,
143144
};
144145

145146
/* A mask for the flags that are supposed to remain when a reset happens

‎net/bluetooth/hci_conn.c‎

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -605,44 +605,6 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
605605
conn->state = BT_CONNECT;
606606
}
607607

608-
static void stop_scan_complete(struct hci_dev *hdev, u8 status)
609-
{
610-
struct hci_request req;
611-
struct hci_conn *conn;
612-
int err;
613-
614-
conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
615-
if (!conn)
616-
return;
617-
618-
if (status) {
619-
BT_DBG("HCI request failed to stop scanning: status 0x%2.2x",
620-
status);
621-
622-
hci_dev_lock(hdev);
623-
hci_le_conn_failed(conn, status);
624-
hci_dev_unlock(hdev);
625-
return;
626-
}
627-
628-
/* Since we may have prematurely stopped discovery procedure, we should
629-
* update discovery state.
630-
*/
631-
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
632-
633-
hci_req_init(&req, hdev);
634-
635-
hci_req_add_le_create_conn(&req, conn);
636-
637-
err = hci_req_run(&req, create_le_conn_complete);
638-
if (err) {
639-
hci_dev_lock(hdev);
640-
hci_le_conn_failed(conn, HCI_ERROR_MEMORY_EXCEEDED);
641-
hci_dev_unlock(hdev);
642-
return;
643-
}
644-
}
645-
646608
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
647609
u8 dst_type, u8 sec_level, u8 auth_type)
648610
{
@@ -721,16 +683,19 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
721683
hci_req_init(&req, hdev);
722684

723685
/* If controller is scanning, we stop it since some controllers are
724-
* not able to scan and connect at the same time.
686+
* not able to scan and connect at the same time. Also set the
687+
* HCI_LE_SCAN_INTERRUPTED flag so that the command complete
688+
* handler for scan disabling knows to set the correct discovery
689+
* state.
725690
*/
726691
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
727692
hci_req_add_le_scan_disable(&req);
728-
err = hci_req_run(&req, stop_scan_complete);
729-
} else {
730-
hci_req_add_le_create_conn(&req, conn);
731-
err = hci_req_run(&req, create_le_conn_complete);
693+
set_bit(HCI_LE_SCAN_INTERRUPTED, &hdev->dev_flags);
732694
}
733695

696+
hci_req_add_le_create_conn(&req, conn);
697+
698+
err = hci_req_run(&req, create_le_conn_complete);
734699
if (err) {
735700
hci_conn_del(conn);
736701
return ERR_PTR(err);

‎net/bluetooth/hci_event.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,13 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
10241024
cancel_delayed_work(&hdev->le_scan_disable);
10251025

10261026
clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
1027+
/* The HCI_LE_SCAN_INTERRUPTED flag indicates that we
1028+
* interrupted scanning due to a connect request. Mark
1029+
* therefore discovery as stopped.
1030+
*/
1031+
if (test_and_clear_bit(HCI_LE_SCAN_INTERRUPTED,
1032+
&hdev->dev_flags))
1033+
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
10271034
break;
10281035

10291036
default:

0 commit comments

Comments
 (0)