Skip to content

Commit

Permalink
Bluetooth: Resume advertising after LE connection
Browse files Browse the repository at this point in the history
When an LE connection request is made, advertising is disabled and never
resumed. When a client has an active advertisement, this is disruptive.
This change adds resume logic for client-configured (non-directed)
advertisements after the connection attempt.

The patch was tested by registering an advertisement, initiating an LE
connection from a remote peer, and verifying that the advertisement is
re-activated after the connection is established. This is performed on
Hatch and Kukui Chromebooks.

Signed-off-by: Daniel Winkler <danielwinkler@google.com>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Daniel Winkler authored and Marcel Holtmann committed Nov 9, 2020
1 parent f7e0e8b commit 2943d8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
12 changes: 10 additions & 2 deletions net/bluetooth/hci_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ static void create_le_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode)

conn = hci_lookup_le_connect(hdev);

if (hdev->adv_instance_cnt)
hci_req_resume_adv_instances(hdev);

if (!status) {
hci_connect_le_scan_cleanup(conn);
goto done;
Expand Down Expand Up @@ -1067,10 +1070,11 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
* connections most controllers will refuse to connect if
* advertising is enabled, and for slave role connections we
* anyway have to disable it in order to start directed
* advertising.
* advertising. Any registered advertisements will be
* re-enabled after the connection attempt is finished.
*/
if (hci_dev_test_flag(hdev, HCI_LE_ADV))
__hci_req_disable_advertising(&req);
__hci_req_pause_adv_instances(&req);

/* If requested to connect as slave use directed advertising */
if (conn->role == HCI_ROLE_SLAVE) {
Expand Down Expand Up @@ -1118,6 +1122,10 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
err = hci_req_run(&req, create_le_conn_complete);
if (err) {
hci_conn_del(conn);

if (hdev->adv_instance_cnt)
hci_req_resume_adv_instances(hdev);

return ERR_PTR(err);
}

Expand Down
21 changes: 16 additions & 5 deletions net/bluetooth/hci_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,9 @@ static void cancel_adv_timeout(struct hci_dev *hdev)
}

/* This function requires the caller holds hdev->lock */
static void hci_suspend_adv_instances(struct hci_request *req)
void __hci_req_pause_adv_instances(struct hci_request *req)
{
bt_dev_dbg(req->hdev, "Suspending advertising instances");
bt_dev_dbg(req->hdev, "Pausing advertising instances");

/* Call to disable any advertisements active on the controller.
* This will succeed even if no advertisements are configured.
Expand All @@ -1138,7 +1138,7 @@ static void hci_suspend_adv_instances(struct hci_request *req)
}

/* This function requires the caller holds hdev->lock */
static void hci_resume_adv_instances(struct hci_request *req)
static void __hci_req_resume_adv_instances(struct hci_request *req)
{
struct adv_info *adv;

Expand All @@ -1161,6 +1161,17 @@ static void hci_resume_adv_instances(struct hci_request *req)
}
}

/* This function requires the caller holds hdev->lock */
int hci_req_resume_adv_instances(struct hci_dev *hdev)
{
struct hci_request req;

hci_req_init(&req, hdev);
__hci_req_resume_adv_instances(&req);

return hci_req_run(&req, NULL);
}

static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode)
{
bt_dev_dbg(hdev, "Request complete opcode=0x%x, status=0x%x", opcode,
Expand Down Expand Up @@ -1214,7 +1225,7 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next)

/* Pause other advertisements */
if (hdev->adv_instance_cnt)
hci_suspend_adv_instances(&req);
__hci_req_pause_adv_instances(&req);

hdev->advertising_paused = true;
hdev->advertising_old_state = old_state;
Expand Down Expand Up @@ -1279,7 +1290,7 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next)

/* Resume other advertisements */
if (hdev->adv_instance_cnt)
hci_resume_adv_instances(&req);
__hci_req_resume_adv_instances(&req);

/* Unpause discovery */
hdev->discovery_paused = false;
Expand Down
2 changes: 2 additions & 0 deletions net/bluetooth/hci_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void hci_req_add_le_passive_scan(struct hci_request *req);
void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next);

void hci_req_disable_address_resolution(struct hci_dev *hdev);
void __hci_req_pause_adv_instances(struct hci_request *req);
int hci_req_resume_adv_instances(struct hci_dev *hdev);
void hci_req_reenable_advertising(struct hci_dev *hdev);
void __hci_req_enable_advertising(struct hci_request *req);
void __hci_req_disable_advertising(struct hci_request *req);
Expand Down

0 comments on commit 2943d8e

Please sign in to comment.