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

Commit fcbae955 authored by Archie Pusaka's avatar Archie Pusaka
Browse files

Fix data type when querying remote_dev type

The check of BT_PROPERTY_TYPE_OF_DEVICE property requires size of 4
bytes, but some of the read attempts only provide 1 byte of data.
This causes those read attempts to fail.

Even though the underlying data fits within 1 byte, there are a lot
of places which assume 4 bytes of data, so changing this to 1 byte
breaks those assumption and might introduce unwanted side effects.

This CL modifies those failed reads to provide exactly 4 bytes.
Additionally, this also replaces every accessors that uses enum to use
uint32_t instead, since enum size is not guaranteed to be 4 bytes.

Bug: 300418914
Tag: #floss
Test: m -j
Test: Manually, make sure we don't fail reading dev_type from storage
      by adding logs and just scan some advertisements.

Change-Id: Ie2a880813ed5e4666813e02bb6914ae52950bb09
parent 2dcade2c
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -663,7 +663,7 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
  bt_property_t properties[3];
  bt_status_t status = BT_STATUS_UNHANDLED;
  uint32_t cod;
  bt_device_type_t dev_type;
  uint32_t dev_type;

  memset(properties, 0, sizeof(properties));

@@ -707,14 +707,14 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,

  /* device type */
  bt_property_t prop_name;
  uint8_t remote_dev_type;
  uint32_t remote_dev_type;
  BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_TYPE_OF_DEVICE,
                             sizeof(uint8_t), &remote_dev_type);
                             sizeof(uint32_t), &remote_dev_type);
  if (btif_storage_get_remote_device_property(&bdaddr, &prop_name) ==
      BT_STATUS_SUCCESS) {
    dev_type = (bt_device_type_t)(remote_dev_type | device_type);
    dev_type = remote_dev_type | device_type;
  } else {
    dev_type = (bt_device_type_t)device_type;
    dev_type = device_type;
  }

  BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
@@ -1451,7 +1451,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,

      {
        bt_property_t properties[10];  // increase when properties are added
        bt_device_type_t dev_type;
        uint32_t dev_type;
        uint32_t num_properties = 0;
        bt_status_t status;
        tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
+2 −2
Original line number Diff line number Diff line
@@ -110,9 +110,9 @@ void btif_iot_update_remote_info(tBTA_DM_AUTH_CMPL* p_auth_cmpl, bool is_ble,

  // save remote dev type to iot conf file
  bt_device_type_t dev_type;
  uint8_t remote_dev_type;
  uint32_t remote_dev_type;
  BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                             BT_PROPERTY_TYPE_OF_DEVICE, sizeof(uint8_t),
                             BT_PROPERTY_TYPE_OF_DEVICE, sizeof(uint32_t),
                             &remote_dev_type);
  if (btif_storage_get_remote_device_property(&p_auth_cmpl->bd_addr,
                                              &properties[num_properties]) ==