Skip to content

Commit 2943d8e

Browse files
dwinkler2holtmann
authored andcommitted
Bluetooth: Resume advertising after LE connection
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 <[email protected]> Reviewed-by: Abhishek Pandit-Subedi <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent f7e0e8b commit 2943d8e

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

net/bluetooth/hci_conn.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@ static void create_le_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode)
758758

759759
conn = hci_lookup_le_connect(hdev);
760760

761+
if (hdev->adv_instance_cnt)
762+
hci_req_resume_adv_instances(hdev);
763+
761764
if (!status) {
762765
hci_connect_le_scan_cleanup(conn);
763766
goto done;
@@ -1067,10 +1070,11 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
10671070
* connections most controllers will refuse to connect if
10681071
* advertising is enabled, and for slave role connections we
10691072
* anyway have to disable it in order to start directed
1070-
* advertising.
1073+
* advertising. Any registered advertisements will be
1074+
* re-enabled after the connection attempt is finished.
10711075
*/
10721076
if (hci_dev_test_flag(hdev, HCI_LE_ADV))
1073-
__hci_req_disable_advertising(&req);
1077+
__hci_req_pause_adv_instances(&req);
10741078

10751079
/* If requested to connect as slave use directed advertising */
10761080
if (conn->role == HCI_ROLE_SLAVE) {
@@ -1118,6 +1122,10 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
11181122
err = hci_req_run(&req, create_le_conn_complete);
11191123
if (err) {
11201124
hci_conn_del(conn);
1125+
1126+
if (hdev->adv_instance_cnt)
1127+
hci_req_resume_adv_instances(hdev);
1128+
11211129
return ERR_PTR(err);
11221130
}
11231131

net/bluetooth/hci_request.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,9 @@ static void cancel_adv_timeout(struct hci_dev *hdev)
11231123
}
11241124

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

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

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

@@ -1161,6 +1161,17 @@ static void hci_resume_adv_instances(struct hci_request *req)
11611161
}
11621162
}
11631163

1164+
/* This function requires the caller holds hdev->lock */
1165+
int hci_req_resume_adv_instances(struct hci_dev *hdev)
1166+
{
1167+
struct hci_request req;
1168+
1169+
hci_req_init(&req, hdev);
1170+
__hci_req_resume_adv_instances(&req);
1171+
1172+
return hci_req_run(&req, NULL);
1173+
}
1174+
11641175
static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode)
11651176
{
11661177
bt_dev_dbg(hdev, "Request complete opcode=0x%x, status=0x%x", opcode,
@@ -1214,7 +1225,7 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next)
12141225

12151226
/* Pause other advertisements */
12161227
if (hdev->adv_instance_cnt)
1217-
hci_suspend_adv_instances(&req);
1228+
__hci_req_pause_adv_instances(&req);
12181229

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

12801291
/* Resume other advertisements */
12811292
if (hdev->adv_instance_cnt)
1282-
hci_resume_adv_instances(&req);
1293+
__hci_req_resume_adv_instances(&req);
12831294

12841295
/* Unpause discovery */
12851296
hdev->discovery_paused = false;

net/bluetooth/hci_request.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void hci_req_add_le_passive_scan(struct hci_request *req);
7171
void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next);
7272

7373
void hci_req_disable_address_resolution(struct hci_dev *hdev);
74+
void __hci_req_pause_adv_instances(struct hci_request *req);
75+
int hci_req_resume_adv_instances(struct hci_dev *hdev);
7476
void hci_req_reenable_advertising(struct hci_dev *hdev);
7577
void __hci_req_enable_advertising(struct hci_request *req);
7678
void __hci_req_disable_advertising(struct hci_request *req);

0 commit comments

Comments
 (0)