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

Commit 6652dbaf authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "Return DEV_CLASS by value" into main

parents ebe3489f 18dfb6bf
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -226,8 +226,6 @@ void BTA_dm_on_hw_off() {
}

void BTA_dm_on_hw_on() {
  DEV_CLASS dev_class;

  uint8_t key_mask = 0;
  tBTA_BLE_LOCAL_ID_KEYS id_key;

@@ -240,7 +238,7 @@ void BTA_dm_on_hw_on() {
  memset(&bta_dm_conn_srvcs, 0, sizeof(bta_dm_conn_srvcs));
  memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB));

  btif_dm_get_local_class_of_device(dev_class);
  DEV_CLASS dev_class = btif_dm_get_local_class_of_device();
  LOG_INFO("%s: Read default class of device {0x%x, 0x%x, 0x%x}", __func__,
      dev_class[0], dev_class[1], dev_class[2]);

+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ void btif_dm_proc_io_rsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap,
/**
 * Device Configuration Queries
 */
void btif_dm_get_local_class_of_device(DEV_CLASS device_class);
DEV_CLASS btif_dm_get_local_class_of_device();

/**
 * Out-of-band functions
+13 −18
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
 *
 ******************************************************************************/

#include "bt_dev_class.h"
#define LOG_TAG "bt_btif_dm"

#include "btif_dm.h"
@@ -2966,15 +2967,12 @@ void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant,
 *
 * Description      Reads the system property configured class of device
 *
 * Inputs           A pointer to a DEV_CLASS that you want filled with the
 *                  current class of device. Size is assumed to be 3.
 *
 * Returns          Nothing. device_class will contain the current class of
 *                  device. If no value is present, or the value is malformed
 *                  the default "unclassified" value will be used
 * Returns          A DEV_CLASS containing the current class of device.
 *                  If no value is present, or the value is malformed
 *                  the default kEmpty value will be used
 *
 ******************************************************************************/
void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
DEV_CLASS btif_dm_get_local_class_of_device() {
  /* A class of device is a {SERVICE_CLASS, MAJOR_CLASS, MINOR_CLASS}
   *
   * The input is expected to be a string of the following format:
@@ -2984,18 +2982,13 @@ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
   *
   * Notice there is always two commas and no spaces.
   */

  device_class[0] = 0x00;
  device_class[1] = BTM_COD_MAJOR_UNCLASSIFIED;
  device_class[2] = BTM_COD_MINOR_UNCLASSIFIED;

  char prop_cod[PROPERTY_VALUE_MAX];
  osi_property_get(PROPERTY_CLASS_OF_DEVICE, prop_cod, "");

  // If the property is empty, use the default
  if (prop_cod[0] == '\0') {
    LOG_ERROR("COD property is empty");
    return;
    return kDevClassUnclassified;
  }

  // Start reading the contents of the property string. If at any point anything
@@ -3012,7 +3005,7 @@ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
      char c = prop_cod[i++];
      if (!std::isdigit(c)) {
        LOG_ERROR("COD malformed, '%c' is a non-digit", c);
        return;
        return kDevClassUnclassified;
      }
      value += c;
    }
@@ -3020,20 +3013,20 @@ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
    // If we hit the end and it wasn't null terminated then return the default
    if (i == PROPERTY_VALUE_MAX && prop_cod[PROPERTY_VALUE_MAX - 1] != '\0') {
      LOG_ERROR("COD malformed, value was truncated");
      return;
      return kDevClassUnclassified;
    }

    // Each number in the list must be one byte, meaning 0 (0x00) -> 255 (0xFF)
    if (value.size() > 3 || value.size() == 0) {
      LOG_ERROR("COD malformed, '%s' must be between [0, 255]", value.c_str());
      return;
      return kDevClassUnclassified;
    }

    // Grab the value. If it's too large, then return the default
    uint32_t uint32_val = static_cast<uint32_t>(std::stoul(value.c_str()));
    if (uint32_val > 0xFF) {
      LOG_ERROR("COD malformed, '%s' must be between [0, 255]", value.c_str());
      return;
      return kDevClassUnclassified;
    }

    // Otherwise, it's safe to use
@@ -3043,7 +3036,7 @@ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
    if (j >= 3) {
      if (prop_cod[i] != '\0') {
        LOG_ERROR("COD malformed, more than three numbers");
        return;
        return kDevClassUnclassified;
      }
      break;
    }
@@ -3058,6 +3051,7 @@ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
  }

  // We must have read exactly 3 numbers
  DEV_CLASS device_class = kDevClassUnclassified;
  if (j == 3) {
    device_class[0] = temp_device_class[0];
    device_class[1] = temp_device_class[1];
@@ -3091,6 +3085,7 @@ void btif_dm_get_local_class_of_device(DEV_CLASS device_class) {
      "0x%x'",
      device_class[0], device_class[1], device_class[2]);
#endif
  return device_class;
}

/*******************************************************************************
+5 −4
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include "main/shim/shim.h"
#include "os/log.h"
#include "stack/btm/btm_int_types.h"
#include "stack/include/bt_dev_class.h"
#include "stack/include/btm_log_history.h"
#include "storage/device.h"
#include "storage/le_device.h"
@@ -143,8 +144,8 @@ extern void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
void btm_ble_process_adv_addr(RawAddress& raw_address,
                              tBLE_ADDR_TYPE* address_type);

extern bool btm_ble_get_appearance_as_cod(std::vector<uint8_t> const& data,
                                          DEV_CLASS dev_class);
extern DEV_CLASS btm_ble_get_appearance_as_cod(
    std::vector<uint8_t> const& data);

using bluetooth::shim::BleScannerInterfaceImpl;

@@ -809,8 +810,8 @@ void BleScannerInterfaceImpl::handle_remote_properties(
    }
  }

  DEV_CLASS dev_class;
  if (btm_ble_get_appearance_as_cod(advertising_data, dev_class)) {
  DEV_CLASS dev_class = btm_ble_get_appearance_as_cod(advertising_data);
  if (dev_class != kDevClassUnclassified) {
    btif_dm_update_ble_remote_properties(bd_addr, bdname.name, dev_class,
                                         device_type);
  }
+9 −10
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
 *
 ******************************************************************************/

#include "bt_dev_class.h"
#define LOG_TAG "bt_btm_ble"

#include <android_bluetooth_flags.h>
@@ -60,6 +59,7 @@
#include "stack/include/acl_api.h"
#include "stack/include/advertise_data_parser.h"
#include "stack/include/ble_scanner.h"
#include "stack/include/bt_dev_class.h"
#include "stack/include/bt_types.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/btm_api_types.h"
@@ -2272,8 +2272,7 @@ static DEV_CLASS btm_ble_appearance_to_cod(uint16_t appearance) {
  return dev_class;
}

bool btm_ble_get_appearance_as_cod(std::vector<uint8_t> const& data,
                                   DEV_CLASS dev_class) {
DEV_CLASS btm_ble_get_appearance_as_cod(std::vector<uint8_t> const& data) {
  /* Check to see the BLE device has the Appearance UUID in the advertising
   * data. If it does then try to convert the appearance value to a class of
   * device value Fluoride can use. Otherwise fall back to trying to infer if
@@ -2283,29 +2282,29 @@ bool btm_ble_get_appearance_as_cod(std::vector<uint8_t> const& data,
  const uint8_t* p_uuid16 = AdvertiseDataParser::GetFieldByType(
      data, BTM_BLE_AD_TYPE_APPEARANCE, &len);
  if (p_uuid16 && len == 2) {
    dev_class =
        btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] | (p_uuid16[1] << 8));
    return true;
    return btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] |
                                     (p_uuid16[1] << 8));
  }

  p_uuid16 = AdvertiseDataParser::GetFieldByType(
      data, BTM_BLE_AD_TYPE_16SRV_CMPL, &len);
  if (p_uuid16 == NULL) {
    return false;
    return kDevClassUnclassified;
  }

  for (uint8_t i = 0; i + 2 <= len; i = i + 2) {
    /* if this BLE device supports HID over LE, set HID Major in class of
     * device */
    if ((p_uuid16[i] | (p_uuid16[i + 1] << 8)) == UUID_SERVCLASS_LE_HID) {
      DEV_CLASS dev_class;
      dev_class[0] = 0;
      dev_class[1] = BTM_COD_MAJOR_PERIPHERAL;
      dev_class[2] = 0;
      return true;
      return dev_class;
    }
  }

  return false;
  return kDevClassUnclassified;
}

/**
@@ -2356,7 +2355,7 @@ void btm_ble_update_inq_result(tINQ_DB_ENT* p_i, uint8_t addr_type,
      p_cur->flag = *p_flag;
    }

    btm_ble_get_appearance_as_cod(data, p_cur->dev_class);
    p_cur->dev_class = btm_ble_get_appearance_as_cod(data);

    const uint8_t* p_rsi =
        AdvertiseDataParser::GetFieldByType(data, BTM_BLE_AD_TYPE_RSI, &len);
Loading