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

Commit 3a718352 authored by Myles Watson's avatar Myles Watson
Browse files

Use std::array for DEV_CLASS

Bug: 314889276
Test: mma -j32
Flag: EXEMPT, no logical change
Change-Id: I45b423fbc0b93bb3ae341c53e2e3af9aa10edea1
parent bc7c32f4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1482,7 +1482,7 @@ static void bta_dm_inq_results_cb(tBTM_INQ_RESULTS* p_inq, const uint8_t* p_eir,
  // Pass the original address to GattService#onScanResult
  result.inq_res.original_bda = p_inq->original_bda;

  memcpy(result.inq_res.dev_class, p_inq->dev_class, DEV_CLASS_LEN);
  result.inq_res.dev_class = p_inq->dev_class;
  BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class);
  result.inq_res.is_limited =
      (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false;
+0 −7
Original line number Diff line number Diff line
@@ -41,13 +41,6 @@
 *  Constants and data types
 ****************************************************************************/

#define BTA_COPY_DEVICE_CLASS(coddst, codsrc)          \
  {                                                    \
    ((uint8_t*)(coddst))[0] = ((uint8_t*)(codsrc))[0]; \
    ((uint8_t*)(coddst))[1] = ((uint8_t*)(codsrc))[1]; \
    ((uint8_t*)(coddst))[2] = ((uint8_t*)(codsrc))[2]; \
  }

#define BTA_DM_MSG_LEN 50

#define BTA_DM_NUM_PEER_DEVICE 7
+12 −12
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include "internal_include/bt_target.h"
#include "osi/include/compat.h"  // strlcpy
#include "osi/include/osi.h"     // UNUSED_ATTR
#include "stack/include/bt_dev_class.h"
#include "stack/include/btm_ble_sec_api_types.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_sec_api.h"
@@ -127,16 +128,16 @@ void bta_dm_sec_enable(tBTA_DM_SEC_CBACK* p_sec_cback) {
 *                  required information stored in the NVRAM.
 ******************************************************************************/
void bta_dm_add_device(std::unique_ptr<tBTA_DM_API_ADD_DEVICE> msg) {
  uint8_t* p_dc = NULL;
  DEV_CLASS dc = kDevClassEmpty;
  LinkKey* p_lc = NULL;

  /* If not all zeros, the device class has been specified */
  if (msg->dc_known) p_dc = (uint8_t*)msg->dc;
  if (msg->dc_known) dc = msg->dc;

  if (msg->link_key_known) p_lc = &msg->link_key;

  auto add_result = get_btm_client_interface().security.BTM_SecAddDevice(
      msg->bd_addr, p_dc, msg->bd_name, nullptr, p_lc, msg->key_type,
      msg->bd_addr, dc, msg->bd_name, nullptr, p_lc, msg->key_type,
      msg->pin_length);
  if (!add_result) {
    LOG(ERROR) << "BTA_DM: Error adding device "
@@ -242,7 +243,7 @@ static void bta_dm_pinname_cback(const tBTM_REMOTE_DEV_NAME* p_data) {
  if (BTA_DM_SP_CFM_REQ_EVT == event) {
    /* Retrieved saved device class and bd_addr */
    sec_event.cfm_req.bd_addr = bta_dm_sec_cb.pin_bd_addr;
    BTA_COPY_DEVICE_CLASS(sec_event.cfm_req.dev_class, bta_dm_sec_cb.pin_dev_class);
    sec_event.cfm_req.dev_class = bta_dm_sec_cb.pin_dev_class;

    if (p_result && p_result->status == BTM_SUCCESS) {
      bytes_to_copy =
@@ -267,7 +268,7 @@ static void bta_dm_pinname_cback(const tBTM_REMOTE_DEV_NAME* p_data) {
  } else {
    /* Retrieved saved device class and bd_addr */
    sec_event.pin_req.bd_addr = bta_dm_sec_cb.pin_bd_addr;
    BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, bta_dm_sec_cb.pin_dev_class);
    sec_event.pin_req.dev_class = bta_dm_sec_cb.pin_dev_class;

    if (p_result && p_result->status == BTM_SUCCESS) {
      bytes_to_copy = (p_result->length < BD_NAME_LEN) ? p_result->length
@@ -304,7 +305,7 @@ static uint8_t bta_dm_pin_cback(const RawAddress& bd_addr, DEV_CLASS dev_class,
  if (bd_name[0] == 0) {
    bta_dm_sec_cb.pin_evt = BTA_DM_PIN_REQ_EVT;
    bta_dm_sec_cb.pin_bd_addr = bd_addr;
    BTA_COPY_DEVICE_CLASS(bta_dm_sec_cb.pin_dev_class, dev_class);
    bta_dm_sec_cb.pin_dev_class = dev_class;
    if ((get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
            bd_addr, bta_dm_pinname_cback, BT_TRANSPORT_BR_EDR)) ==
        BTM_CMD_STARTED)
@@ -315,10 +316,11 @@ static uint8_t bta_dm_pin_cback(const RawAddress& bd_addr, DEV_CLASS dev_class,

  tBTA_DM_SEC sec_event = {.pin_req = {
                               .bd_addr = bd_addr,
                               .dev_class = dev_class,
                               .bd_name = "",
                               .min_16_digit = min_16_digit,
                           }};
  BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, dev_class);
  strlcpy((char*)sec_event.pin_req.bd_name, (char*)bd_name, BD_NAME_LEN + 1);
  sec_event.pin_req.min_16_digit = min_16_digit;

  bta_dm_sec_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event);
  return BTM_CMD_STARTED;
@@ -528,8 +530,7 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
        if (p_data->key_notif.bd_name[0] == 0) {
          bta_dm_sec_cb.pin_evt = pin_evt;
          bta_dm_sec_cb.pin_bd_addr = p_data->key_notif.bd_addr;
          BTA_COPY_DEVICE_CLASS(bta_dm_sec_cb.pin_dev_class,
                                p_data->key_notif.dev_class);
          bta_dm_sec_cb.pin_dev_class = p_data->key_notif.dev_class;
          if ((get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
                  p_data->key_notif.bd_addr, bta_dm_pinname_cback,
                  BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED)
@@ -538,8 +539,7 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
              " bta_dm_sp_cback() -> Failed to start Remote Name Request  ");
        } else {
          sec_event.key_notif.bd_addr = p_data->key_notif.bd_addr;
          BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class,
                                p_data->key_notif.dev_class);
          sec_event.key_notif.dev_class = p_data->key_notif.dev_class;
          strlcpy((char*)sec_event.key_notif.bd_name,
                  (char*)p_data->key_notif.bd_name, BD_NAME_LEN + 1);
          sec_event.key_notif.bd_name[BD_NAME_LEN] = 0;
+2 −2
Original line number Diff line number Diff line
@@ -147,9 +147,9 @@ void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
  msg->link_key = link_key;

  /* Load device class if specified */
  if (dev_class) {
  if (dev_class != kDevClassEmpty) {
    msg->dc_known = true;
    memcpy(msg->dc, dev_class, DEV_CLASS_LEN);
    msg->dc = dev_class;
  }

  memset(msg->bd_name, 0, BD_NAME_LEN + 1);
+6 −6
Original line number Diff line number Diff line
@@ -158,15 +158,14 @@ uint8_t utl_itoa(uint16_t i, char* p_s) {
 *
 ******************************************************************************/
bool utl_set_device_class(tBTA_UTL_COD* p_cod, uint8_t cmd) {
  uint8_t* dev;
  uint16_t service;
  uint8_t minor, major;
  DEV_CLASS dev_class;
  DEV_CLASS old_class;

  dev = BTM_ReadDeviceClass();
  BTM_COD_SERVICE_CLASS(service, dev);
  BTM_COD_MINOR_CLASS(minor, dev);
  BTM_COD_MAJOR_CLASS(major, dev);
  old_class = BTM_ReadDeviceClass();
  BTM_COD_SERVICE_CLASS(service, old_class);
  BTM_COD_MINOR_CLASS(minor, old_class);
  BTM_COD_MAJOR_CLASS(major, old_class);

  switch (cmd) {
    case BTA_UTL_SET_COD_MAJOR_MINOR:
@@ -203,6 +202,7 @@ bool utl_set_device_class(tBTA_UTL_COD* p_cod, uint8_t cmd) {
  }

  /* convert the fields into the device class type */
  DEV_CLASS dev_class;
  FIELDS_TO_COD(dev_class, minor, major, service);

  if (BTM_SetDeviceClass(dev_class) == BTM_SUCCESS) return true;
Loading