Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d4c318c authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Refactor allow_wake_by_hid for classic

Currently, allow_wake_by_hid tries to configure set event filter to
allow all classic devices that are HID major class to attempt connection
and wake us from suspend. This is insufficient to keep us from being
woken by unbonded devices (which we don't want).

The refactor does the following:
* Gets a list of classic hid devices (where DevClass matches either
  keyboard or pointing device).
* Program event filter using BD_ADDR instead of Class of Device
  filtering. Only bonded devices will be able to reconnect until we
  clear the Event Filter on resume.

Bug: 269835025
Tag: #floss
Test: Manual suspend test + autotest
Change-Id: I392bd63a8ebe0e8b7d53524dd24777b599ca8e41
parent 8b8b70f5
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -4389,13 +4389,14 @@ void bta_dm_set_event_filter_connection_setup_all_devices() {
 *
 *
 * Description     Allow the device to be woken by HID devices
 * Description     Allow the device to be woken by HID devices
 *
 *
 * Parameters      std::vector of (Address, Address Type)
 * Parameters      std::vector of Classic Address and LE (Address, Address Type)
 *
 *
 *******************************************************************************/
 *******************************************************************************/
void bta_dm_allow_wake_by_hid(
void bta_dm_allow_wake_by_hid(
    std::vector<RawAddress> classic_hid_devices,
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices) {
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices) {
  // Autoplumbed
  bluetooth::shim::BTM_AllowWakeByHid(std::move(classic_hid_devices),
  bluetooth::shim::BTM_AllowWakeByHid(le_hid_devices);
                                      std::move(le_hid_devices));
}
}


/*******************************************************************************
/*******************************************************************************
+4 −2
Original line number Original line Diff line number Diff line
@@ -734,10 +734,12 @@ void BTA_DmSetEventFilterConnectionSetupAllDevices() {
}
}


void BTA_DmAllowWakeByHid(
void BTA_DmAllowWakeByHid(
    std::vector<RawAddress> classic_hid_devices,
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices) {
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices) {
  APPL_TRACE_API("BTA_DmAllowWakeByHid");
  APPL_TRACE_API("BTA_DmAllowWakeByHid");
  do_in_main_thread(FROM_HERE,
  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_allow_wake_by_hid,
                    base::Bind(bta_dm_allow_wake_by_hid, le_hid_devices));
                                          std::move(classic_hid_devices),
                                          std::move(le_hid_devices)));
}
}


void BTA_DmRestoreFilterAcceptList() {
void BTA_DmRestoreFilterAcceptList() {
+1 −0
Original line number Original line Diff line number Diff line
@@ -583,6 +583,7 @@ extern void bta_dm_disconnect_all_acls(void);
extern void bta_dm_le_rand(LeRandCallback cb);
extern void bta_dm_le_rand(LeRandCallback cb);
extern void bta_dm_set_event_filter_connection_setup_all_devices();
extern void bta_dm_set_event_filter_connection_setup_all_devices();
extern void bta_dm_allow_wake_by_hid(
extern void bta_dm_allow_wake_by_hid(
    std::vector<RawAddress> classic_hid_devices,
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices);
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices);
extern void bta_dm_restore_filter_accept_list();
extern void bta_dm_restore_filter_accept_list();
extern void bta_dm_set_default_event_mask_except(uint64_t mask,
extern void bta_dm_set_default_event_mask_except(uint64_t mask,
+1 −0
Original line number Original line Diff line number Diff line
@@ -1312,6 +1312,7 @@ extern void BTA_DmSetEventFilterConnectionSetupAllDevices();
 *
 *
 *******************************************************************************/
 *******************************************************************************/
extern void BTA_DmAllowWakeByHid(
extern void BTA_DmAllowWakeByHid(
    std::vector<RawAddress> classic_hid_devices,
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices);
    std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices);


/*******************************************************************************
/*******************************************************************************
+21 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,25 @@
#include "btif_uid.h"
#include "btif_uid.h"
#include "types/raw_address.h"
#include "types/raw_address.h"


/*******************************************************************************
 *  Constants & Macros
 ******************************************************************************/
#define COD_MASK 0x07FF
#define COD_UNCLASSIFIED ((0x1F) << 8)
/* Focus on Major and minor device class*/
#define COD_DEVICE_MASK 0x1FFC
#define COD_HID_KEYBOARD 0x0540
#define COD_HID_POINTING 0x0580
#define COD_HID_COMBO 0x05C0
#define COD_HID_MAJOR 0x0500
#define COD_HID_MASK 0x0700
#define COD_AV_HEADSETS 0x0404
#define COD_AV_HANDSFREE 0x0408
#define COD_AV_HEADPHONES 0x0418
#define COD_AV_PORTABLE_AUDIO 0x041C
#define COD_AV_HIFI_AUDIO 0x0428
#define COD_CLASS_LE_AUDIO (1 << 14)

/*******************************************************************************
/*******************************************************************************
 *  Functions
 *  Functions
 ******************************************************************************/
 ******************************************************************************/
@@ -83,7 +102,8 @@ void btif_dm_disconnect_all_acls();
void btif_dm_le_rand(LeRandCallback callback);
void btif_dm_le_rand(LeRandCallback callback);
void btif_dm_set_event_filter_connection_setup_all_devices();
void btif_dm_set_event_filter_connection_setup_all_devices();
void btif_dm_allow_wake_by_hid(
void btif_dm_allow_wake_by_hid(
    std::vector<std::pair<RawAddress, uint8_t>> addrs);
    std::vector<RawAddress> classic_addrs,
    std::vector<std::pair<RawAddress, uint8_t>> le_addrs);
void btif_dm_restore_filter_accept_list();
void btif_dm_restore_filter_accept_list();
void btif_dm_set_default_event_mask_except(uint64_t mask, uint64_t le_mask);
void btif_dm_set_default_event_mask_except(uint64_t mask, uint64_t le_mask);
void btif_dm_set_event_filter_inquiry_result_all_devices();
void btif_dm_set_event_filter_inquiry_result_all_devices();
Loading