Skip to content

Commit cf75ad8

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: hci_sync: Convert MGMT_SET_POWERED
This make use of hci_cmd_sync_queue when MGMT_SET_POWERED is used so all commands are run within hdev->cmd_sync_work instead of hdev->power_on_work and hdev->power_off_work. In addition to that the power on sequence now takes into account if local IRK needs to be programmed in the resolving list. Tested with: tools/mgmt-tester -s "Set powered" Test Summary ------------ Set powered on - Success Passed Set powered on - Invalid parameters 1 Passed Set powered on - Invalid parameters 2 Passed Set powered on - Invalid parameters 3 Passed Set powered on - Invalid index Passed Set powered on - Privacy and Advertising Passed Set powered off - Success Passed Set powered off - Class of Device Passed Set powered off - Invalid parameters 1 Passed Set powered off - Invalid parameters 2 Passed Set powered off - Invalid parameters 3 Passed Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0 Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 5bee2fd commit cf75ad8

File tree

5 files changed

+685
-98
lines changed

5 files changed

+685
-98
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ int hci_disable_advertising_sync(struct hci_dev *hdev);
6666

6767
int hci_update_passive_scan_sync(struct hci_dev *hdev);
6868
int hci_update_passive_scan(struct hci_dev *hdev);
69+
70+
int hci_dev_open_sync(struct hci_dev *hdev);
71+
int hci_dev_close_sync(struct hci_dev *hdev);
72+
73+
int hci_powered_update_sync(struct hci_dev *hdev);
74+
int hci_set_powered_sync(struct hci_dev *hdev, u8 val);

net/bluetooth/hci_core.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,14 +1315,13 @@ static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev)
13151315
bacpy(&hdev->public_addr, &ba);
13161316
}
13171317

1318-
static int hci_dev_do_open(struct hci_dev *hdev)
1318+
/* TODO: Move this function into hci_sync.c */
1319+
int hci_dev_open_sync(struct hci_dev *hdev)
13191320
{
13201321
int ret = 0;
13211322

13221323
BT_DBG("%s %p", hdev->name, hdev);
13231324

1324-
hci_req_sync_lock(hdev);
1325-
13261325
if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
13271326
ret = -ENODEV;
13281327
goto done;
@@ -1489,8 +1488,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
14891488
!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
14901489
hci_dev_test_flag(hdev, HCI_MGMT) &&
14911490
hdev->dev_type == HCI_PRIMARY) {
1492-
ret = __hci_req_hci_power_on(hdev);
1493-
mgmt_power_on(hdev, ret);
1491+
ret = hci_powered_update_sync(hdev);
14941492
}
14951493
} else {
14961494
/* Init failed, cleanup */
@@ -1522,6 +1520,19 @@ static int hci_dev_do_open(struct hci_dev *hdev)
15221520
}
15231521

15241522
done:
1523+
return ret;
1524+
}
1525+
1526+
static int hci_dev_do_open(struct hci_dev *hdev)
1527+
{
1528+
int ret = 0;
1529+
1530+
BT_DBG("%s %p", hdev->name, hdev);
1531+
1532+
hci_req_sync_lock(hdev);
1533+
1534+
ret = hci_dev_open_sync(hdev);
1535+
15251536
hci_req_sync_unlock(hdev);
15261537
return ret;
15271538
}
@@ -1600,7 +1611,8 @@ static void hci_pend_le_actions_clear(struct hci_dev *hdev)
16001611
BT_DBG("All LE pending actions cleared");
16011612
}
16021613

1603-
int hci_dev_do_close(struct hci_dev *hdev)
1614+
/* TODO: Move this function into hci_sync.c */
1615+
int hci_dev_close_sync(struct hci_dev *hdev)
16041616
{
16051617
bool auto_off;
16061618
int err = 0;
@@ -1611,7 +1623,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
16111623
cancel_delayed_work(&hdev->ncmd_timer);
16121624

16131625
hci_request_cancel_all(hdev);
1614-
hci_req_sync_lock(hdev);
16151626

16161627
if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
16171628
!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
@@ -1623,7 +1634,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
16231634

16241635
if (!test_and_clear_bit(HCI_UP, &hdev->flags)) {
16251636
cancel_delayed_work_sync(&hdev->cmd_timer);
1626-
hci_req_sync_unlock(hdev);
16271637
return err;
16281638
}
16291639

@@ -1729,9 +1739,22 @@ int hci_dev_do_close(struct hci_dev *hdev)
17291739
bacpy(&hdev->random_addr, BDADDR_ANY);
17301740
hci_codec_list_clear(&hdev->local_codecs);
17311741

1742+
hci_dev_put(hdev);
1743+
return err;
1744+
}
1745+
1746+
int hci_dev_do_close(struct hci_dev *hdev)
1747+
{
1748+
int err;
1749+
1750+
BT_DBG("%s %p", hdev->name, hdev);
1751+
1752+
hci_req_sync_lock(hdev);
1753+
1754+
err = hci_dev_close_sync(hdev);
1755+
17321756
hci_req_sync_unlock(hdev);
17331757

1734-
hci_dev_put(hdev);
17351758
return err;
17361759
}
17371760

@@ -2133,9 +2156,7 @@ static void hci_power_on(struct work_struct *work)
21332156
hci_dev_test_flag(hdev, HCI_MGMT) &&
21342157
hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) {
21352158
cancel_delayed_work(&hdev->power_off);
2136-
hci_req_sync_lock(hdev);
2137-
err = __hci_req_hci_power_on(hdev);
2138-
hci_req_sync_unlock(hdev);
2159+
err = hci_powered_update_sync(hdev);
21392160
mgmt_power_on(hdev, err);
21402161
return;
21412162
}

net/bluetooth/hci_request.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,8 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
17941794

17951795
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
17961796

1797-
if (own_addr_type == ADDR_LE_DEV_RANDOM &&
1797+
if ((own_addr_type == ADDR_LE_DEV_RANDOM ||
1798+
own_addr_type == ADDR_LE_DEV_RANDOM_RESOLVED) &&
17981799
bacmp(&random_addr, BDADDR_ANY)) {
17991800
struct hci_cp_le_set_adv_set_rand_addr cp;
18001801

0 commit comments

Comments
 (0)