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

Commit 791fad22 authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge changes I88cfaef1,I45b423fb,I3167f44e,I3ec46fff into main

* changes:
  Remove dev_class_copy
  Use std::array for DEV_CLASS
  Remove types/class_of_device
  IWYU: Add includes for cstdint
parents 81710cc5 555f3080
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line 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
  // Pass the original address to GattService#onScanResult
  result.inq_res.original_bda = p_inq->original_bda;
  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);
  BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class);
  result.inq_res.is_limited =
  result.inq_res.is_limited =
      (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false;
      (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false;
+0 −7
Original line number Original line Diff line number Diff line
@@ -41,13 +41,6 @@
 *  Constants and data types
 *  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_MSG_LEN 50


#define BTA_DM_NUM_PEER_DEVICE 7
#define BTA_DM_NUM_PEER_DEVICE 7
+14 −15
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
#include "internal_include/bt_target.h"
#include "internal_include/bt_target.h"
#include "osi/include/compat.h"  // strlcpy
#include "osi/include/compat.h"  // strlcpy
#include "osi/include/osi.h"     // UNUSED_ATTR
#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_ble_sec_api_types.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_sec_api.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.
 *                  required information stored in the NVRAM.
 ******************************************************************************/
 ******************************************************************************/
void bta_dm_add_device(std::unique_ptr<tBTA_DM_API_ADD_DEVICE> msg) {
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;
  LinkKey* p_lc = NULL;


  /* If not all zeros, the device class has been specified */
  /* 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;
  if (msg->link_key_known) p_lc = &msg->link_key;


  auto add_result = get_btm_client_interface().security.BTM_SecAddDevice(
  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);
      msg->pin_length);
  if (!add_result) {
  if (!add_result) {
    LOG(ERROR) << "BTA_DM: Error adding device "
    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) {
  if (BTA_DM_SP_CFM_REQ_EVT == event) {
    /* Retrieved saved device class and bd_addr */
    /* Retrieved saved device class and bd_addr */
    sec_event.cfm_req.bd_addr = bta_dm_sec_cb.pin_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) {
    if (p_result && p_result->status == BTM_SUCCESS) {
      bytes_to_copy =
      bytes_to_copy =
@@ -267,7 +268,7 @@ static void bta_dm_pinname_cback(const tBTM_REMOTE_DEV_NAME* p_data) {
  } else {
  } else {
    /* Retrieved saved device class and bd_addr */
    /* Retrieved saved device class and bd_addr */
    sec_event.pin_req.bd_addr = bta_dm_sec_cb.pin_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) {
    if (p_result && p_result->status == BTM_SUCCESS) {
      bytes_to_copy = (p_result->length < BD_NAME_LEN) ? p_result->length
      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) {
  if (bd_name[0] == 0) {
    bta_dm_sec_cb.pin_evt = BTA_DM_PIN_REQ_EVT;
    bta_dm_sec_cb.pin_evt = BTA_DM_PIN_REQ_EVT;
    bta_dm_sec_cb.pin_bd_addr = bd_addr;
    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(
    if ((get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
            bd_addr, bta_dm_pinname_cback, BT_TRANSPORT_BR_EDR)) ==
            bd_addr, bta_dm_pinname_cback, BT_TRANSPORT_BR_EDR)) ==
        BTM_CMD_STARTED)
        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 = {
  tBTA_DM_SEC sec_event = {.pin_req = {
                               .bd_addr = bd_addr,
                               .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);
  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);
  bta_dm_sec_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event);
  return BTM_CMD_STARTED;
  return BTM_CMD_STARTED;
@@ -491,8 +493,7 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
           BTM_SP_KEY_NOTIF_EVT,
           BTM_SP_KEY_NOTIF_EVT,
           copy these values into key_notif from cfm_req */
           copy these values into key_notif from cfm_req */
        sec_event.key_notif.bd_addr = p_data->cfm_req.bd_addr;
        sec_event.key_notif.bd_addr = p_data->cfm_req.bd_addr;
        dev_class_copy(sec_event.key_notif.dev_class,
        sec_event.key_notif.dev_class = p_data->cfm_req.dev_class;
                       p_data->cfm_req.dev_class);
        bd_name_copy(sec_event.key_notif.bd_name, p_data->cfm_req.bd_name);
        bd_name_copy(sec_event.key_notif.bd_name, p_data->cfm_req.bd_name);
        /* Due to the switch case falling through below to BTM_SP_KEY_NOTIF_EVT,
        /* Due to the switch case falling through below to BTM_SP_KEY_NOTIF_EVT,
           call remote name request using values from cfm_req */
           call remote name request using values from cfm_req */
@@ -504,7 +505,7 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
          bta_dm_sec_cb.rmt_auth_req = sec_event.cfm_req.rmt_auth_req;
          bta_dm_sec_cb.rmt_auth_req = sec_event.cfm_req.rmt_auth_req;
          bta_dm_sec_cb.loc_auth_req = sec_event.cfm_req.loc_auth_req;
          bta_dm_sec_cb.loc_auth_req = sec_event.cfm_req.loc_auth_req;


          dev_class_copy(bta_dm_sec_cb.pin_dev_class, p_data->cfm_req.dev_class);
          bta_dm_sec_cb.pin_dev_class = p_data->cfm_req.dev_class;
          {
          {
            const tBTM_STATUS btm_status =
            const tBTM_STATUS btm_status =
                get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
                get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
@@ -528,8 +529,7 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
        if (p_data->key_notif.bd_name[0] == 0) {
        if (p_data->key_notif.bd_name[0] == 0) {
          bta_dm_sec_cb.pin_evt = pin_evt;
          bta_dm_sec_cb.pin_evt = pin_evt;
          bta_dm_sec_cb.pin_bd_addr = p_data->key_notif.bd_addr;
          bta_dm_sec_cb.pin_bd_addr = p_data->key_notif.bd_addr;
          BTA_COPY_DEVICE_CLASS(bta_dm_sec_cb.pin_dev_class,
          bta_dm_sec_cb.pin_dev_class = p_data->key_notif.dev_class;
                                p_data->key_notif.dev_class);
          if ((get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
          if ((get_btm_client_interface().peer.BTM_ReadRemoteDeviceName(
                  p_data->key_notif.bd_addr, bta_dm_pinname_cback,
                  p_data->key_notif.bd_addr, bta_dm_pinname_cback,
                  BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED)
                  BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED)
@@ -538,8 +538,7 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
              " bta_dm_sp_cback() -> Failed to start Remote Name Request  ");
              " bta_dm_sp_cback() -> Failed to start Remote Name Request  ");
        } else {
        } else {
          sec_event.key_notif.bd_addr = p_data->key_notif.bd_addr;
          sec_event.key_notif.bd_addr = p_data->key_notif.bd_addr;
          BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class,
          sec_event.key_notif.dev_class = p_data->key_notif.dev_class;
                                p_data->key_notif.dev_class);
          strlcpy((char*)sec_event.key_notif.bd_name,
          strlcpy((char*)sec_event.key_notif.bd_name,
                  (char*)p_data->key_notif.bd_name, BD_NAME_LEN + 1);
                  (char*)p_data->key_notif.bd_name, BD_NAME_LEN + 1);
          sec_event.key_notif.bd_name[BD_NAME_LEN] = 0;
          sec_event.key_notif.bd_name[BD_NAME_LEN] = 0;
+2 −2
Original line number Original line 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;
  msg->link_key = link_key;


  /* Load device class if specified */
  /* Load device class if specified */
  if (dev_class) {
  if (dev_class != kDevClassEmpty) {
    msg->dc_known = true;
    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);
  memset(msg->bd_name, 0, BD_NAME_LEN + 1);
+6 −6
Original line number Original line 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) {
bool utl_set_device_class(tBTA_UTL_COD* p_cod, uint8_t cmd) {
  uint8_t* dev;
  uint16_t service;
  uint16_t service;
  uint8_t minor, major;
  uint8_t minor, major;
  DEV_CLASS dev_class;
  DEV_CLASS old_class;


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


  switch (cmd) {
  switch (cmd) {
    case BTA_UTL_SET_COD_MAJOR_MINOR:
    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 */
  /* convert the fields into the device class type */
  DEV_CLASS dev_class;
  FIELDS_TO_COD(dev_class, minor, major, service);
  FIELDS_TO_COD(dev_class, minor, major, service);


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