Skip to content

Linux 5.18.2 bluetooth fixes #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions net/bluetooth/hci_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,20 +1664,19 @@ static int hci_le_add_accept_list_sync(struct hci_dev *hdev,
struct hci_cp_le_add_to_accept_list cp;
int err;

/* During suspend, only wakeable devices can be in acceptlist */
if (hdev->suspended &&
!test_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, params->flags))
return 0;

/* Select filter policy to accept all advertising */
if (*num_entries >= hdev->le_accept_list_size)
return -ENOSPC;

/* Accept list can not be used with RPAs */
if (!use_ll_privacy(hdev) &&
hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
hci_find_irk_by_addr(hdev, &params->addr, params->addr_type))
return -EINVAL;
}

/* During suspend, only wakeable devices can be in acceptlist */
if (hdev->suspended &&
!test_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, params->flags))
return 0;

/* Attempt to program the device in the resolving list first to avoid
* having to rollback in case it fails since the resolving list is
Expand Down Expand Up @@ -4881,10 +4880,28 @@ static int hci_update_event_filter_sync(struct hci_dev *hdev)
return 0;
}

/* This function disables scan (BR and LE) and mark it as paused */
static int hci_pause_scan_sync(struct hci_dev *hdev)
{
if (hdev->scanning_paused)
return 0;

/* Disable page scan if enabled */
if (test_bit(HCI_PSCAN, &hdev->flags))
hci_write_scan_enable_sync(hdev, SCAN_DISABLED);

hci_scan_disable_sync(hdev);

hdev->scanning_paused = true;

return 0;
}

/* This function performs the HCI suspend procedures in the follow order:
*
* Pause discovery (active scanning/inquiry)
* Pause Directed Advertising/Advertising
* Pause Scanning (passive scanning in case discovery was not active)
* Disconnect all connections
* Set suspend_status to BT_SUSPEND_DISCONNECT if hdev cannot wakeup
* otherwise:
Expand All @@ -4910,15 +4927,11 @@ int hci_suspend_sync(struct hci_dev *hdev)
/* Pause other advertisements */
hci_pause_advertising_sync(hdev);

/* Disable page scan if enabled */
if (test_bit(HCI_PSCAN, &hdev->flags))
hci_write_scan_enable_sync(hdev, SCAN_DISABLED);

/* Suspend monitor filters */
hci_suspend_monitor_sync(hdev);

/* Prevent disconnects from causing scanning to be re-enabled */
hdev->scanning_paused = true;
hci_pause_scan_sync(hdev);

/* Soft disconnect everything (power off) */
err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF);
Expand Down Expand Up @@ -4989,6 +5002,22 @@ static void hci_resume_monitor_sync(struct hci_dev *hdev)
}
}

/* This function resume scan and reset paused flag */
static int hci_resume_scan_sync(struct hci_dev *hdev)
{
if (!hdev->scanning_paused)
return 0;

hci_update_scan_sync(hdev);

/* Reset passive scanning to normal */
hci_update_passive_scan_sync(hdev);

hdev->scanning_paused = false;

return 0;
}

/* This function performs the HCI suspend procedures in the follow order:
*
* Restore event mask
Expand All @@ -5011,10 +5040,9 @@ int hci_resume_sync(struct hci_dev *hdev)

/* Clear any event filters and restore scan state */
hci_clear_event_filter_sync(hdev);
hci_update_scan_sync(hdev);

/* Reset passive scanning to normal */
hci_update_passive_scan_sync(hdev);
/* Resume scanning */
hci_resume_scan_sync(hdev);

/* Resume monitor filters */
hci_resume_monitor_sync(hdev);
Expand Down
18 changes: 18 additions & 0 deletions net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4529,6 +4529,23 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
le_addr_type(cp->addr.type));
if (params) {
DECLARE_BITMAP(flags, __HCI_CONN_NUM_FLAGS);

bitmap_from_u64(flags, current_flags);

/* Devices using RPAs can only be programmed in the
* acceptlist LL Privacy has been enable otherwise they
* cannot mark HCI_CONN_FLAG_REMOTE_WAKEUP.
*/
if (test_bit(HCI_CONN_FLAG_REMOTE_WAKEUP, flags) &&
!use_ll_privacy(hdev) &&
hci_find_irk_by_addr(hdev, &params->addr,
params->addr_type)) {
bt_dev_warn(hdev,
"Cannot set wakeable for RPA");
goto unlock;
}

bitmap_from_u64(params->flags, current_flags);
status = MGMT_STATUS_SUCCESS;

Expand All @@ -4545,6 +4562,7 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
}
}

unlock:
hci_dev_unlock(hdev);

done:
Expand Down