Skip to content

Commit

Permalink
Bluetooth: hci_sync: Convert MGMT_SET_POWERED
Browse files Browse the repository at this point in the history
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 <luiz.von.dentz@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Vudentz authored and holtmann committed Oct 29, 2021
1 parent 5bee2fd commit cf75ad8
Show file tree
Hide file tree
Showing 5 changed files with 685 additions and 98 deletions.
6 changes: 6 additions & 0 deletions include/net/bluetooth/hci_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ int hci_disable_advertising_sync(struct hci_dev *hdev);

int hci_update_passive_scan_sync(struct hci_dev *hdev);
int hci_update_passive_scan(struct hci_dev *hdev);

int hci_dev_open_sync(struct hci_dev *hdev);
int hci_dev_close_sync(struct hci_dev *hdev);

int hci_powered_update_sync(struct hci_dev *hdev);
int hci_set_powered_sync(struct hci_dev *hdev, u8 val);
45 changes: 33 additions & 12 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,14 +1315,13 @@ static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev)
bacpy(&hdev->public_addr, &ba);
}

static int hci_dev_do_open(struct hci_dev *hdev)
/* TODO: Move this function into hci_sync.c */
int hci_dev_open_sync(struct hci_dev *hdev)
{
int ret = 0;

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

hci_req_sync_lock(hdev);

if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
ret = -ENODEV;
goto done;
Expand Down Expand Up @@ -1489,8 +1488,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
hci_dev_test_flag(hdev, HCI_MGMT) &&
hdev->dev_type == HCI_PRIMARY) {
ret = __hci_req_hci_power_on(hdev);
mgmt_power_on(hdev, ret);
ret = hci_powered_update_sync(hdev);
}
} else {
/* Init failed, cleanup */
Expand Down Expand Up @@ -1522,6 +1520,19 @@ static int hci_dev_do_open(struct hci_dev *hdev)
}

done:
return ret;
}

static int hci_dev_do_open(struct hci_dev *hdev)
{
int ret = 0;

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

hci_req_sync_lock(hdev);

ret = hci_dev_open_sync(hdev);

hci_req_sync_unlock(hdev);
return ret;
}
Expand Down Expand Up @@ -1600,7 +1611,8 @@ static void hci_pend_le_actions_clear(struct hci_dev *hdev)
BT_DBG("All LE pending actions cleared");
}

int hci_dev_do_close(struct hci_dev *hdev)
/* TODO: Move this function into hci_sync.c */
int hci_dev_close_sync(struct hci_dev *hdev)
{
bool auto_off;
int err = 0;
Expand All @@ -1611,7 +1623,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
cancel_delayed_work(&hdev->ncmd_timer);

hci_request_cancel_all(hdev);
hci_req_sync_lock(hdev);

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

if (!test_and_clear_bit(HCI_UP, &hdev->flags)) {
cancel_delayed_work_sync(&hdev->cmd_timer);
hci_req_sync_unlock(hdev);
return err;
}

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

hci_dev_put(hdev);
return err;
}

int hci_dev_do_close(struct hci_dev *hdev)
{
int err;

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

hci_req_sync_lock(hdev);

err = hci_dev_close_sync(hdev);

hci_req_sync_unlock(hdev);

hci_dev_put(hdev);
return err;
}

Expand Down Expand Up @@ -2133,9 +2156,7 @@ static void hci_power_on(struct work_struct *work)
hci_dev_test_flag(hdev, HCI_MGMT) &&
hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) {
cancel_delayed_work(&hdev->power_off);
hci_req_sync_lock(hdev);
err = __hci_req_hci_power_on(hdev);
hci_req_sync_unlock(hdev);
err = hci_powered_update_sync(hdev);
mgmt_power_on(hdev, err);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/hci_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,8 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)

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

if (own_addr_type == ADDR_LE_DEV_RANDOM &&
if ((own_addr_type == ADDR_LE_DEV_RANDOM ||
own_addr_type == ADDR_LE_DEV_RANDOM_RESOLVED) &&
bacmp(&random_addr, BDADDR_ANY)) {
struct hci_cp_le_set_adv_set_rand_addr cp;

Expand Down
Loading

0 comments on commit cf75ad8

Please sign in to comment.