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

Commit 5bce07dd authored by Michael Sun's avatar Michael Sun Committed by Gerrit Code Review
Browse files

Merge changes I4cb5ee1a,I9d63cb04,I46433e9a,I16f60aaf,Iac4f2fea

* changes:
  floss: metrics: Port Allowlist from BlueZ
  floss: metrics: gather and emit remote device info metrics
  Change BTIF_STORAGE_GET_(ADAPTER|REMOTE)_PROP macro to function
  floss: Pass peer's VID:PID to btif
  floss: Add Appearance field to bt_property list
parents 75b4be64 517ea220
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@
#include "stack/include/bt_types.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btu.h"  // do_in_main_thread
#include "stack/include/srvc_api.h"  // DIS_ReadDISInfo
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

@@ -1198,6 +1199,21 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
        }
      } while (p_sdp_rec);
    }

#if TARGET_FLOSS
    tSDP_DI_GET_RECORD di_record;
    if (SDP_GetDiRecord(1, &di_record, bta_dm_search_cb.p_sdp_db) ==
        SDP_SUCCESS) {
      tBTA_DM_SEARCH result;
      result.did_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
      result.did_res.vendor_id_src = di_record.rec.vendor_id_source;
      result.did_res.vendor_id = di_record.rec.vendor;
      result.did_res.product_id = di_record.rec.product;
      result.did_res.version = di_record.rec.version;
      bta_dm_search_cb.p_search_cback(BTA_DM_DID_RES_EVT, &result);
    }
#endif

    /* if there are more services to search for */
    if (bta_dm_search_cb.services_to_search) {
      /* Free up the p_sdp_db before checking the next one */
@@ -1293,6 +1309,26 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
  }
}

/** Callback of peer's DIS reply. This is only called for floss */
#if TARGET_FLOSS
static void bta_dm_read_dis_cmpl(const RawAddress& addr,
                                 tDIS_VALUE* p_dis_value) {
  if (!p_dis_value) {
    LOG_WARN("read DIS failed");
  } else {
    tBTA_DM_SEARCH result;
    result.did_res.bd_addr = addr;
    result.did_res.vendor_id_src = p_dis_value->pnp_id.vendor_id_src;
    result.did_res.vendor_id = p_dis_value->pnp_id.vendor_id;
    result.did_res.product_id = p_dis_value->pnp_id.product_id;
    result.did_res.version = p_dis_value->pnp_id.product_version;
    bta_dm_search_cb.p_search_cback(BTA_DM_DID_RES_EVT, &result);
  }

  bta_dm_execute_queued_request();
}
#endif

/*******************************************************************************
 *
 * Function         bta_dm_search_cmpl
@@ -1347,6 +1383,13 @@ void bta_dm_search_cmpl() {

  bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);

#if TARGET_FLOSS
  if (DIS_ReadDISInfo(bta_dm_search_cb.peer_bdaddr, bta_dm_read_dis_cmpl,
                      DIS_ATTR_PNP_ID_BIT)) {
    return;
  }
#endif

  bta_dm_execute_queued_request();
}

+11 −0
Original line number Diff line number Diff line
@@ -423,6 +423,7 @@ typedef void(tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data);
  3 /* Discovery result for BLE GATT based servoce on a peer device. */
#define BTA_DM_DISC_CMPL_EVT 4          /* Discovery complete. */
#define BTA_DM_SEARCH_CANCEL_CMPL_EVT 6 /* Search cancelled */
#define BTA_DM_DID_RES_EVT 7            /* Vendor/Product ID search result */

typedef uint8_t tBTA_DM_SEARCH_EVT;

@@ -477,6 +478,15 @@ typedef struct {
      services; /* GATT based Services UUID found on peer device. */
} tBTA_DM_DISC_BLE_RES;

/* Structure associated with tBTA_DM_DID_RES */
typedef struct {
  RawAddress bd_addr; /* BD address peer device. */
  uint8_t vendor_id_src;
  uint16_t vendor_id;
  uint16_t product_id;
  uint16_t version;
} tBTA_DM_DID_RES;

/* Union of all search callback structures */
typedef union {
  tBTA_DM_INQ_RES inq_res;   /* Inquiry result for a peer device. */
@@ -484,6 +494,7 @@ typedef union {
  tBTA_DM_DISC_RES disc_res; /* Discovery result for a peer device. */
  tBTA_DM_DISC_BLE_RES
      disc_ble_res;             /* discovery result for GATT based service */
  tBTA_DM_DID_RES did_res;      /* Vendor and Product ID of peer device */
} tBTA_DM_SEARCH;

/* Search callback */
+66 −1
Original line number Diff line number Diff line
@@ -395,6 +395,39 @@ static bool check_eir_remote_name(tBTA_DM_SEARCH* p_search_data,
  return false;
}

/*******************************************************************************
 *
 * Function         check_eir_appearance
 *
 * Description      Check if appearance is in the EIR data
 *
 * Returns          true if appearance found
 *                  Populate p_appearance, if provided and appearance found
 *
 ******************************************************************************/
static bool check_eir_appearance(tBTA_DM_SEARCH* p_search_data,
                                 uint16_t* p_appearance) {
  const uint8_t* p_eir_appearance = NULL;
  uint8_t appearance_len = 0;

  /* Check EIR for remote name and services */
  if (p_search_data->inq_res.p_eir) {
    p_eir_appearance = AdvertiseDataParser::GetFieldByType(
        p_search_data->inq_res.p_eir, p_search_data->inq_res.eir_len,
        HCI_EIR_APPEARANCE_TYPE, &appearance_len);

    if (p_eir_appearance) {
      if (p_appearance) {
        *p_appearance = *((uint16_t*)p_eir_appearance);
      }

      return true;
    }
  }

  return false;
}

/*******************************************************************************
 *
 * Function         check_cached_remote_name
@@ -1234,7 +1267,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
      }

      {
        bt_property_t properties[7];
        bt_property_t properties[8];
        bt_device_type_t dev_type;
        uint32_t num_properties = 0;
        bt_status_t status;
@@ -1334,6 +1367,15 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
#endif
        }

        // Floss needs appearance for metrics purposes
        uint16_t appearance = 0;
        if (check_eir_appearance(p_search_data, &appearance)) {
          BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                                     BT_PROPERTY_APPEARANCE, sizeof(appearance),
                                     &appearance);
          num_properties++;
        }

        status =
            btif_storage_add_remote_device(&bdaddr, num_properties, properties);
        ASSERTC(status == BT_STATUS_SUCCESS,
@@ -1588,6 +1630,29 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
                                         num_properties, prop);
    } break;

    case BTA_DM_DID_RES_EVT: {
      bt_property_t prop_did;
      RawAddress& bd_addr = p_data->did_res.bd_addr;
      bt_vendor_product_info_t vp_info;

      vp_info.vendor_id_src = p_data->did_res.vendor_id_src;
      vp_info.vendor_id = p_data->did_res.vendor_id;
      vp_info.product_id = p_data->did_res.product_id;
      vp_info.version = p_data->did_res.version;

      prop_did.type = BT_PROPERTY_VENDOR_PRODUCT_INFO;
      prop_did.val = &vp_info;
      prop_did.len = sizeof(vp_info);

      bt_status_t ret =
          btif_storage_set_remote_device_property(&bd_addr, &prop_did);
      ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);

      /* Send the event to the BTIF */
      invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr, 1,
                                         &prop_did);
    } break;

    default: { ASSERTC(0, "unhandled search services event", event); } break;
  }
}
+115 −39
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ using bluetooth::groups::DeviceGroups;
#define BTIF_STORAGE_PATH_REMOTE_DEVCLASS "DevClass"
#define BTIF_STORAGE_PATH_REMOTE_DEVTYPE "DevType"
#define BTIF_STORAGE_PATH_REMOTE_NAME "Name"
#define BTIF_STORAGE_PATH_REMOTE_APPEARANCE "Appearance"

//#define BTIF_STORAGE_PATH_REMOTE_LINKKEYS "remote_linkkeys"
#define BTIF_STORAGE_PATH_REMOTE_ALIASE "Aliase"
@@ -101,27 +102,14 @@ using bluetooth::groups::DeviceGroups;
#define BTIF_STORAGE_CSIS_SET_INFO_BIN "CsisSetInfoBin"
#define BTIF_STORAGE_LEAUDIO_AUTOCONNECT "LeAudioAutoconnect"

#define BTIF_STORAGE_PATH_VENDOR_ID_SOURCE "VendorIdSource"
#define BTIF_STORAGE_PATH_VENDOR_ID "VendorId"
#define BTIF_STORAGE_PATH_PRODUCT_ID "ProductId"
#define BTIF_STORAGE_PATH_VERSION "ProductVersion"

/* This is a local property to add a device found */
#define BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP 0xFF

// TODO: This macro should be converted to a function
#define BTIF_STORAGE_GET_ADAPTER_PROP(s, t, v, l, p) \
  do {                                               \
    (p).type = (t);                                  \
    (p).val = (v);                                   \
    (p).len = (l);                                   \
    (s) = btif_storage_get_adapter_property(&(p));   \
  } while (0)

// TODO: This macro should be converted to a function
#define BTIF_STORAGE_GET_REMOTE_PROP(b, t, v, l, p)     \
  do {                                                  \
    (p).type = (t);                                     \
    (p).val = (v);                                      \
    (p).len = (l);                                      \
    btif_storage_get_remote_device_property((b), &(p)); \
  } while (0)

#define STORAGE_BDADDR_STRING_SZ (18) /* 00:11:22:33:44:55 */
#define STORAGE_UUID_STRING_SIZE \
  (36 + 1) /* 00001200-0000-1000-8000-00805f9b34fb; */
@@ -281,6 +269,21 @@ static int prop2cfg(const RawAddress* remote_bd_addr, bt_property_t* prop) {
      btif_config_set_int(bdstr, BT_CONFIG_KEY_REMOTE_VER_SUBVER,
                          info->sub_ver);
    } break;
    case BT_PROPERTY_APPEARANCE: {
      int val = *(uint16_t*)prop->val;
      btif_config_set_int(bdstr, BTIF_STORAGE_PATH_REMOTE_APPEARANCE, val);
    } break;
    case BT_PROPERTY_VENDOR_PRODUCT_INFO: {
      bt_vendor_product_info_t* info = (bt_vendor_product_info_t*)prop->val;
      if (!info) return false;

      btif_config_set_int(bdstr, BTIF_STORAGE_PATH_VENDOR_ID_SOURCE,
                          info->vendor_id_src);
      btif_config_set_int(bdstr, BTIF_STORAGE_PATH_VENDOR_ID, info->vendor_id);
      btif_config_set_int(bdstr, BTIF_STORAGE_PATH_PRODUCT_ID,
                          info->product_id);
      btif_config_set_int(bdstr, BTIF_STORAGE_PATH_VERSION, info->version);
    } break;

    default:
      BTIF_TRACE_ERROR("Unknown prop type:%d", prop->type);
@@ -407,6 +410,40 @@ static int cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) {
      }
    } break;

    case BT_PROPERTY_APPEARANCE: {
      int val;

      if (prop->len >= (int)sizeof(uint16_t)) {
        ret = btif_config_get_int(bdstr, BTIF_STORAGE_PATH_REMOTE_APPEARANCE,
                                  &val);
        *(uint16_t*)prop->val = (uint16_t)val;
      }
    } break;

    case BT_PROPERTY_VENDOR_PRODUCT_INFO: {
      bt_vendor_product_info_t* info = (bt_vendor_product_info_t*)prop->val;
      int val;

      if (prop->len >= (int)sizeof(bt_vendor_product_info_t)) {
        ret = btif_config_get_int(bdstr, BTIF_STORAGE_PATH_VENDOR_ID_SOURCE,
                                  &val);
        info->vendor_id_src = (uint8_t)val;

        if (ret) {
          ret = btif_config_get_int(bdstr, BTIF_STORAGE_PATH_VENDOR_ID, &val);
          info->vendor_id = (uint16_t)val;
        }
        if (ret) {
          ret = btif_config_get_int(bdstr, BTIF_STORAGE_PATH_PRODUCT_ID, &val);
          info->product_id = (uint16_t)val;
        }
        if (ret) {
          ret = btif_config_get_int(bdstr, BTIF_STORAGE_PATH_VERSION, &val);
          info->version = (uint16_t)val;
        }
      }
    } break;

    default:
      BTIF_TRACE_ERROR("Unknow prop type:%d", prop->type);
      return false;
@@ -625,6 +662,15 @@ uint8_t btif_storage_get_local_io_caps_ble() {
                                          BTM_LOCAL_IO_CAPS_BLE);
}

/** Helper function for fetching a bt_property of the adapter. */
bt_status_t btif_storage_get_adapter_prop(bt_property_type_t type, void* buf,
                                          int size, bt_property_t* property) {
  property->type = type;
  property->val = buf;
  property->len = size;
  return btif_storage_get_adapter_property(property);
}

/*******************************************************************************
 *
 * Function         btif_storage_get_adapter_property
@@ -755,6 +801,16 @@ bt_status_t btif_storage_set_adapter_property(bt_property_t* property) {
  return prop2cfg(NULL, property) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}

/** Helper function for fetching a bt_property of a remote device. */
bt_status_t btif_storage_get_remote_prop(RawAddress* remote_addr,
                                         bt_property_type_t type, void* buf,
                                         int size, bt_property_t* property) {
  property->type = type;
  property->val = buf;
  property->len = size;
  return btif_storage_get_remote_device_property(remote_addr, property);
}

/*******************************************************************************
 *
 * Function         btif_storage_get_remote_device_property
@@ -1021,7 +1077,7 @@ bt_status_t btif_storage_load_bonded_devices(void) {
  uint32_t i = 0;
  bt_property_t adapter_props[6];
  uint32_t num_props = 0;
  bt_property_t remote_properties[8];
  bt_property_t remote_properties[9];
  RawAddress addr;
  bt_bdname_t name, alias;
  bt_scan_mode_t mode;
@@ -1039,8 +1095,8 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    memset(adapter_props, 0, sizeof(adapter_props));

    /* address */
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_BDADDR, &addr,
                                  sizeof(addr), adapter_props[num_props]);
    status = btif_storage_get_adapter_prop(
        BT_PROPERTY_BDADDR, &addr, sizeof(addr), &adapter_props[num_props]);
    // Add BT_PROPERTY_BDADDR property into list only when successful.
    // Otherwise, skip this property entry.
    if (status == BT_STATUS_SUCCESS) {
@@ -1048,8 +1104,8 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    }

    /* BD_NAME */
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_BDNAME, &name,
                                  sizeof(name), adapter_props[num_props]);
    btif_storage_get_adapter_prop(BT_PROPERTY_BDNAME, &name, sizeof(name),
                                  &adapter_props[num_props]);
    num_props++;

    /* SCAN_MODE */
@@ -1064,9 +1120,9 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    num_props++;

    /* DISC_TIMEOUT */
    BTIF_STORAGE_GET_ADAPTER_PROP(
        status, BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT, &disc_timeout,
        sizeof(disc_timeout), adapter_props[num_props]);
    btif_storage_get_adapter_prop(BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT,
                                  &disc_timeout, sizeof(disc_timeout),
                                  &adapter_props[num_props]);
    num_props++;

    /* BONDED_DEVICES */
@@ -1082,9 +1138,9 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    num_props++;

    /* LOCAL UUIDs */
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_UUIDS, local_uuids,
    btif_storage_get_adapter_prop(BT_PROPERTY_UUIDS, local_uuids,
                                  sizeof(local_uuids),
                                  adapter_props[num_props]);
                                  &adapter_props[num_props]);
    num_props++;

    btif_adapter_properties_evt(BT_STATUS_SUCCESS, num_props, adapter_props);
@@ -1108,30 +1164,50 @@ bt_status_t btif_storage_load_bonded_devices(void) {
      num_props = 0;
      p_remote_addr = &bonded_devices.devices[i];
      memset(remote_properties, 0, sizeof(remote_properties));
      BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_BDNAME, &name,
                                   sizeof(name), remote_properties[num_props]);
      btif_storage_get_remote_prop(p_remote_addr, BT_PROPERTY_BDNAME, &name,
                                   sizeof(name), &remote_properties[num_props]);
      num_props++;

      BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr,
                                   BT_PROPERTY_REMOTE_FRIENDLY_NAME, &alias,
                                   sizeof(alias), remote_properties[num_props]);
      btif_storage_get_remote_prop(
          p_remote_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME, &alias,
          sizeof(alias), &remote_properties[num_props]);
      num_props++;

      BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_CLASS_OF_DEVICE,
      btif_storage_get_remote_prop(p_remote_addr, BT_PROPERTY_CLASS_OF_DEVICE,
                                   &cod, sizeof(cod),
                                   remote_properties[num_props]);
                                   &remote_properties[num_props]);
      num_props++;

      BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_TYPE_OF_DEVICE,
      btif_storage_get_remote_prop(p_remote_addr, BT_PROPERTY_TYPE_OF_DEVICE,
                                   &devtype, sizeof(devtype),
                                   remote_properties[num_props]);
                                   &remote_properties[num_props]);
      num_props++;

      BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_UUIDS,
      btif_storage_get_remote_prop(p_remote_addr, BT_PROPERTY_UUIDS,
                                   remote_uuids, sizeof(remote_uuids),
                                   remote_properties[num_props]);
                                   &remote_properties[num_props]);
      num_props++;

      // Floss needs appearance for metrics purposes
      uint16_t appearance = 0;
      if (btif_storage_get_remote_prop(p_remote_addr, BT_PROPERTY_APPEARANCE,
                                       &appearance, sizeof(appearance),
                                       &remote_properties[num_props]) ==
          BT_STATUS_SUCCESS) {
        num_props++;
      }

#if TARGET_FLOSS
      // Floss needs VID:PID for metrics purposes
      bt_vendor_product_info_t vp_info;
      if (btif_storage_get_remote_prop(
              p_remote_addr, BT_PROPERTY_VENDOR_PRODUCT_INFO, &vp_info,
              sizeof(vp_info),
              &remote_properties[num_props]) == BT_STATUS_SUCCESS) {
        num_props++;
      }
#endif

      btif_remote_properties_evt(BT_STATUS_SUCCESS, p_remote_addr, num_props,
                                 remote_properties);
    }
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
source_set("BluetoothMetricsSources_chromeos") {
  sources = [
    "chromeos/metrics.cc",
    "chromeos/metrics_allowlist.cc",
    "chromeos/metrics_event.cc",
  ]

Loading