Commit d1967ff8 authored by Marcel Holtmann's avatar Marcel Holtmann Committed by Johan Hedberg

Bluetooth: Update class of device on discoverable timeout

When the discoverable timeout triggers and limited discoverable mode
was used, then the class of device needs to be updated to remove
the limited discoverable bit.

To keep the class of device logic in a central place, expose a new
function mgmt_discoverable_timeout that can be called from the
timeout callback. In case the class of device value needs updating,
it will add the HCI command to the transaction.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent efdcf8e3
...@@ -1072,6 +1072,7 @@ void mgmt_index_added(struct hci_dev *hdev); ...@@ -1072,6 +1072,7 @@ void mgmt_index_added(struct hci_dev *hdev);
void mgmt_index_removed(struct hci_dev *hdev); void mgmt_index_removed(struct hci_dev *hdev);
void mgmt_set_powered_failed(struct hci_dev *hdev, int err); void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
int mgmt_powered(struct hci_dev *hdev, u8 powered); int mgmt_powered(struct hci_dev *hdev, u8 powered);
void mgmt_discoverable_timeout(struct hci_dev *hdev);
void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
void mgmt_connectable(struct hci_dev *hdev, u8 connectable); void mgmt_connectable(struct hci_dev *hdev, u8 connectable);
void mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); void mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
......
...@@ -1705,29 +1705,12 @@ static void hci_power_off(struct work_struct *work) ...@@ -1705,29 +1705,12 @@ static void hci_power_off(struct work_struct *work)
static void hci_discov_off(struct work_struct *work) static void hci_discov_off(struct work_struct *work)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct hci_request req;
u8 scan = SCAN_PAGE;
hdev = container_of(work, struct hci_dev, discov_off.work); hdev = container_of(work, struct hci_dev, discov_off.work);
BT_DBG("%s", hdev->name); BT_DBG("%s", hdev->name);
hci_dev_lock(hdev); mgmt_discoverable_timeout(hdev);
hci_req_init(&req, hdev);
hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, sizeof(scan), &scan);
hci_req_run(&req, NULL);
/* When discoverable timeout triggers, then just make sure
* the limited discoverable flag is cleared. Even in the case
* of a timeout triggered from general discoverable, it is
* safe to unconditionally clear the flag.
*/
clear_bit(HCI_LIMITED_DISCOVERABLE, &hdev->dev_flags);
hdev->discov_timeout = 0;
hci_dev_unlock(hdev);
} }
int hci_uuids_clear(struct hci_dev *hdev) int hci_uuids_clear(struct hci_dev *hdev)
......
...@@ -4288,6 +4288,30 @@ void mgmt_set_powered_failed(struct hci_dev *hdev, int err) ...@@ -4288,6 +4288,30 @@ void mgmt_set_powered_failed(struct hci_dev *hdev, int err)
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
} }
void mgmt_discoverable_timeout(struct hci_dev *hdev)
{
struct hci_request req;
u8 scan = SCAN_PAGE;
hci_dev_lock(hdev);
/* When discoverable timeout triggers, then just make sure
* the limited discoverable flag is cleared. Even in the case
* of a timeout triggered from general discoverable, it is
* safe to unconditionally clear the flag.
*/
clear_bit(HCI_LIMITED_DISCOVERABLE, &hdev->dev_flags);
hci_req_init(&req, hdev);
hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, sizeof(scan), &scan);
update_class(&req);
hci_req_run(&req, NULL);
hdev->discov_timeout = 0;
hci_dev_unlock(hdev);
}
void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable) void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable)
{ {
bool changed; bool changed;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment