Skip to content

Commit f056a65

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: hci_sync: Convert MGMT_OP_SET_CONNECTABLE to use cmd_sync
This makes MGMT_OP_SET_CONNEABLE use hci_cmd_sync_queue instead of use a dedicated connetable_update work. Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 2bd1b23 commit f056a65

File tree

5 files changed

+52
-62
lines changed

5 files changed

+52
-62
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ struct hci_dev {
495495
struct work_struct discov_update;
496496
struct work_struct bg_scan_update;
497497
struct work_struct scan_update;
498-
struct work_struct connectable_update;
499498
struct delayed_work le_scan_disable;
500499
struct delayed_work le_scan_restart;
501500

@@ -1826,7 +1825,6 @@ void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
18261825
u16 max_interval, u16 latency, u16 timeout);
18271826
void mgmt_smp_complete(struct hci_conn *conn, bool complete);
18281827
bool mgmt_get_connectable(struct hci_dev *hdev);
1829-
void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status);
18301828
u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
18311829
void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
18321830
u8 instance);

include/net/bluetooth/hci_sync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ int hci_set_powered_sync(struct hci_dev *hdev, u8 val);
9393
int hci_update_discoverable_sync(struct hci_dev *hdev);
9494
int hci_update_discoverable(struct hci_dev *hdev);
9595

96+
int hci_update_connectable_sync(struct hci_dev *hdev);
97+
9698
int hci_start_discovery_sync(struct hci_dev *hdev);
9799
int hci_stop_discovery_sync(struct hci_dev *hdev);
98100

net/bluetooth/hci_request.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,47 +1987,6 @@ static void scan_update_work(struct work_struct *work)
19871987
hci_req_sync(hdev, update_scan, 0, HCI_CMD_TIMEOUT, NULL);
19881988
}
19891989

1990-
static int connectable_update(struct hci_request *req, unsigned long opt)
1991-
{
1992-
struct hci_dev *hdev = req->hdev;
1993-
1994-
hci_dev_lock(hdev);
1995-
1996-
__hci_req_update_scan(req);
1997-
1998-
/* If BR/EDR is not enabled and we disable advertising as a
1999-
* by-product of disabling connectable, we need to update the
2000-
* advertising flags.
2001-
*/
2002-
if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
2003-
__hci_req_update_adv_data(req, hdev->cur_adv_instance);
2004-
2005-
/* Update the advertising parameters if necessary */
2006-
if (hci_dev_test_flag(hdev, HCI_ADVERTISING) ||
2007-
!list_empty(&hdev->adv_instances)) {
2008-
if (ext_adv_capable(hdev))
2009-
__hci_req_start_ext_adv(req, hdev->cur_adv_instance);
2010-
else
2011-
__hci_req_enable_advertising(req);
2012-
}
2013-
2014-
__hci_update_background_scan(req);
2015-
2016-
hci_dev_unlock(hdev);
2017-
2018-
return 0;
2019-
}
2020-
2021-
static void connectable_update_work(struct work_struct *work)
2022-
{
2023-
struct hci_dev *hdev = container_of(work, struct hci_dev,
2024-
connectable_update);
2025-
u8 status;
2026-
2027-
hci_req_sync(hdev, connectable_update, 0, HCI_CMD_TIMEOUT, &status);
2028-
mgmt_set_connectable_complete(hdev, status);
2029-
}
2030-
20311990
static u8 get_service_classes(struct hci_dev *hdev)
20321991
{
20331992
struct bt_uuid *uuid;
@@ -2841,7 +2800,6 @@ void hci_request_setup(struct hci_dev *hdev)
28412800
INIT_WORK(&hdev->discov_update, discov_update);
28422801
INIT_WORK(&hdev->bg_scan_update, bg_scan_update);
28432802
INIT_WORK(&hdev->scan_update, scan_update_work);
2844-
INIT_WORK(&hdev->connectable_update, connectable_update_work);
28452803
INIT_DELAYED_WORK(&hdev->discov_off, discov_off);
28462804
INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
28472805
INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work);
@@ -2856,7 +2814,6 @@ void hci_request_cancel_all(struct hci_dev *hdev)
28562814
cancel_work_sync(&hdev->discov_update);
28572815
cancel_work_sync(&hdev->bg_scan_update);
28582816
cancel_work_sync(&hdev->scan_update);
2859-
cancel_work_sync(&hdev->connectable_update);
28602817
cancel_delayed_work_sync(&hdev->discov_off);
28612818
cancel_delayed_work_sync(&hdev->le_scan_disable);
28622819
cancel_delayed_work_sync(&hdev->le_scan_restart);

net/bluetooth/hci_sync.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,6 +4480,37 @@ int hci_update_discoverable(struct hci_dev *hdev)
44804480
return 0;
44814481
}
44824482

4483+
int hci_update_connectable_sync(struct hci_dev *hdev)
4484+
{
4485+
int err;
4486+
4487+
err = hci_update_scan_sync(hdev);
4488+
if (err)
4489+
return err;
4490+
4491+
/* If BR/EDR is not enabled and we disable advertising as a
4492+
* by-product of disabling connectable, we need to update the
4493+
* advertising flags.
4494+
*/
4495+
if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
4496+
err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance);
4497+
4498+
/* Update the advertising parameters if necessary */
4499+
if (hci_dev_test_flag(hdev, HCI_ADVERTISING) ||
4500+
!list_empty(&hdev->adv_instances)) {
4501+
if (ext_adv_capable(hdev))
4502+
err = hci_start_ext_adv_sync(hdev,
4503+
hdev->cur_adv_instance);
4504+
else
4505+
err = hci_enable_advertising_sync(hdev);
4506+
4507+
if (err)
4508+
return err;
4509+
}
4510+
4511+
return hci_update_passive_scan_sync(hdev);
4512+
}
4513+
44834514
static int hci_inquiry_sync(struct hci_dev *hdev, u8 length)
44844515
{
44854516
const u8 giac[3] = { 0x33, 0x8b, 0x9e };

net/bluetooth/mgmt.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,31 +1537,26 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
15371537
return err;
15381538
}
15391539

1540-
void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status)
1540+
static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data,
1541+
int err)
15411542
{
1542-
struct mgmt_pending_cmd *cmd;
1543+
struct mgmt_pending_cmd *cmd = data;
15431544

1544-
bt_dev_dbg(hdev, "status 0x%02x", status);
1545+
bt_dev_dbg(hdev, "err %d", err);
15451546

15461547
hci_dev_lock(hdev);
15471548

1548-
cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev);
1549-
if (!cmd)
1550-
goto unlock;
1551-
1552-
if (status) {
1553-
u8 mgmt_err = mgmt_status(status);
1549+
if (err) {
1550+
u8 mgmt_err = mgmt_status(err);
15541551
mgmt_cmd_status(cmd->sk, cmd->index, cmd->opcode, mgmt_err);
1555-
goto remove_cmd;
1552+
goto done;
15561553
}
15571554

15581555
send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev);
15591556
new_settings(hdev, cmd->sk);
15601557

1561-
remove_cmd:
1562-
mgmt_pending_remove(cmd);
1563-
1564-
unlock:
1558+
done:
1559+
mgmt_pending_free(cmd);
15651560
hci_dev_unlock(hdev);
15661561
}
15671562

@@ -1594,6 +1589,13 @@ static int set_connectable_update_settings(struct hci_dev *hdev,
15941589
return 0;
15951590
}
15961591

1592+
static int set_connectable_sync(struct hci_dev *hdev, void *data)
1593+
{
1594+
BT_DBG("%s", hdev->name);
1595+
1596+
return hci_update_connectable_sync(hdev);
1597+
}
1598+
15971599
static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
15981600
u16 len)
15991601
{
@@ -1626,7 +1628,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
16261628
goto failed;
16271629
}
16281630

1629-
cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len);
1631+
cmd = mgmt_pending_new(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len);
16301632
if (!cmd) {
16311633
err = -ENOMEM;
16321634
goto failed;
@@ -1643,8 +1645,8 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
16431645
hci_dev_clear_flag(hdev, HCI_CONNECTABLE);
16441646
}
16451647

1646-
queue_work(hdev->req_workqueue, &hdev->connectable_update);
1647-
err = 0;
1648+
err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd,
1649+
mgmt_set_connectable_complete);
16481650

16491651
failed:
16501652
hci_dev_unlock(hdev);

0 commit comments

Comments
 (0)