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

Commit 46476a51 authored by Chris Manton's avatar Chris Manton Committed by Gerrit Code Review
Browse files

Merge changes Ib81960bb,I1d84f463,Id475e310,I4ba9755c,Ib6f7b4ba, ...

* changes:
  Introduce main_shim_test
  Add main/test::shim mocks
  Add gd/neighbor::inquiry mock
  Add SCO HACK for shim acl mock
  Add gd/hci::controller mock
  gd_acl: Directly access acl manager for SCO hack
  Put stack vars in proper scope
  Return proper type stack/acl/btm_pm::BTM_SetPowerMode
  Explicitly specify status type include/hardware/ble_scanner.h
  Add stack init indirection for activity_attribution
  Use proper tBTM_STATUS types
  Use tBTM_STATUS in stack/l2cap/::
  gd_shim: Log more info about acl queue state
  Add bta_sys post to main alternative method
  Remove unused field srvc_id
  Template prep for bta hardening
  Use btm_status in stack/rfcomm/::
  Use proper types tBLE_SCAN_MODE
  User proper types tBTM_STATUS
  Canonicalize tBTM_APPL_INFO::bta_security
  Streamline bta_av_link_role_ok
  Use canonical include paths
  Add hci code conversion stack/include/hci_error_code
  Remove unused bta/include/bta_api::#defs
  Remove unused API BTM_GetPeerSCA
  Remove unused API BTM_RequestPeerSCA
  Remove unused API BTM_IsPhy2mSupported
  Properly conform tACL_CONN field names
  Add stack/include::BT_HDR rigid struct
  Use proper types tSMP_STATUS
  Properly type stack/smp::tSMP_EVT
  Remove useless extern keyword for definitions
  Remove unused stack/gatt/gatt_int::#defs
  Re-include bta/ag/bta_ag_sdp.cc
parents 75dcbe16 e6a57a2b
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -23,24 +23,18 @@
 *
 ******************************************************************************/

#include <cstring>

#include <base/bind.h>
#include <base/location.h>

#include "bt_target.h"  // Legacy stack config
#include "bt_trace.h"   // Legacy trace logging

#include "bt_common.h"
#include "bta_ag_api.h"
#include "bta_ag_int.h"
#include "bta_api.h"
#include "bta_sys.h"
#include "btif_config.h"
#include "btm_api.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "sdp_api.h"
#include "stack/btm/btm_sec.h"
#include "stack/include/btu.h"
#include "bta/ag/bta_ag_int.h"
#include "btif/include/btif_config.h"
#include "stack/include/btm_api.h"
#include "stack/include/btu.h"  // do_in_main_thread
#include "stack/include/port_api.h"
#include "utl.h"
#include "types/bluetooth/uuid.h"

using bluetooth::Uuid;

+28 −19
Original line number Diff line number Diff line
@@ -1010,31 +1010,40 @@ bool bta_av_switch_if_needed(tBTA_AV_SCB* p_scb) {
 ******************************************************************************/
bool bta_av_link_role_ok(tBTA_AV_SCB* p_scb, uint8_t bits) {
  uint8_t role;
  bool is_ok = true;
  if (BTM_GetRole(p_scb->PeerAddress(), &role) != BTM_SUCCESS) {
    LOG_WARN("Unable to find link role for device:%s",
             PRIVATE_ADDRESS(p_scb->PeerAddress()));
    return true;
  }

  if (BTM_GetRole(p_scb->PeerAddress(), &role) == BTM_SUCCESS) {
  if (role != HCI_ROLE_CENTRAL && (A2DP_BitsSet(bta_av_cb.conn_audio) > bits)) {
    LOG_INFO(
        "%s: peer %s bta_handle:0x%x role:%d conn_audio:0x%x bits:%d "
        "features:0x%x",
        __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl, role,
        bta_av_cb.conn_audio, bits, bta_av_cb.features);
    if (HCI_ROLE_CENTRAL != role &&
        (A2DP_BitsSet(bta_av_cb.conn_audio) > bits)) {
      tBTM_STATUS status = BTM_SwitchRoleToCentral(p_scb->PeerAddress());
      if (status != BTM_CMD_STARTED) {
        "Switch link role to central peer:%s bta_handle:0x%x current_role:%s"
        " conn_audio:0x%x bits:%d features:0x%x",
        PRIVATE_ADDRESS(p_scb->PeerAddress()), p_scb->hndl,
        RoleText(role).c_str(), bta_av_cb.conn_audio, bits, bta_av_cb.features);
    const tBTM_STATUS status = BTM_SwitchRoleToCentral(p_scb->PeerAddress());
    switch (status) {
      case BTM_CMD_STARTED:
        break;
      case BTM_MODE_UNSUPPORTED:
      case BTM_DEV_RESTRICT_LISTED:
        // Role switch can never happen, but indicate to caller
        // a result such that a timer will not start to repeatedly
        // try something not possible.
        LOG_ERROR("Link can never role switch to central device:%s",
                  PRIVATE_ADDRESS(p_scb->PeerAddress()));
        break;
      default:
        /* can not switch role on SCB - start the timer on SCB */
        LOG_ERROR(
            "%s: peer %s BTM_SwitchRoleToCentral(HCI_ROLE_CENTRAL) error: %d",
            __func__, p_scb->PeerAddress().ToString().c_str(), status);
      }
      if (status != BTM_MODE_UNSUPPORTED && status != BTM_DEV_RESTRICT_LISTED) {
        is_ok = false;
        p_scb->wait |= BTA_AV_WAIT_ROLE_SW_RES_START;
        LOG_ERROR("Unable to switch role to central device:%s error:%s",
                  PRIVATE_ADDRESS(p_scb->PeerAddress()),
                  btm_status_text(status).c_str());
        return false;
    }
  }
  }

  return is_ok;
  return true;
}

/*******************************************************************************
+17 −18
Original line number Diff line number Diff line
@@ -228,13 +228,14 @@ const uint16_t bta_service_id_to_uuid_lkup_tbl[BTA_MAX_SERVICE_ID] = {
};

/* bta security callback */
const tBTM_APPL_INFO bta_security = {&bta_dm_pin_cback,
                                     &bta_dm_new_link_key_cback,
                                     &bta_dm_authentication_complete_cback,
                                     &bta_dm_bond_cancel_complete_cback,
                                     &bta_dm_sp_cback,
                                     &bta_dm_ble_smp_cback,
                                     &bta_dm_ble_id_key_cback};
const tBTM_APPL_INFO bta_security = {
    .p_pin_callback = &bta_dm_pin_cback,
    .p_link_key_callback = &bta_dm_new_link_key_cback,
    .p_auth_complete_callback = &bta_dm_authentication_complete_cback,
    .p_bond_cancel_cmpl_callback = &bta_dm_bond_cancel_complete_cback,
    .p_sp_callback = &bta_dm_sp_cback,
    .p_le_callback = &bta_dm_ble_smp_cback,
    .p_le_key_callback = &bta_dm_ble_id_key_cback};

#define MAX_DISC_RAW_DATA_BUF (4096)
uint8_t g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];
@@ -1055,20 +1056,17 @@ void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data) {
 *
 ******************************************************************************/
void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
  if ((p_data->sdp_event.sdp_result == SDP_SUCCESS) ||
      (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH) ||
      (p_data->sdp_event.sdp_result == SDP_DB_FULL)) {
    APPL_TRACE_DEBUG("sdp_result::0x%x", p_data->sdp_event.sdp_result);
    tSDP_DISC_REC* p_sdp_rec = NULL;
  tBTA_DM_MSG* p_msg;
    bool scn_found = false;
  uint16_t service = 0xFFFF;
    tSDP_PROTOCOL_ELEM pe;

    std::vector<Uuid> uuid_list;

  if ((p_data->sdp_event.sdp_result == SDP_SUCCESS) ||
      (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH) ||
      (p_data->sdp_event.sdp_result == SDP_DB_FULL)) {
    APPL_TRACE_DEBUG("sdp_result::0x%x", p_data->sdp_event.sdp_result);
    do {
      p_sdp_rec = NULL;
      uint16_t service = 0xffff;
      if (bta_dm_search_cb.service_index == (BTA_USER_SERVICE_ID + 1)) {
        if (p_sdp_rec && SDP_FindProtocolListElemInRec(
                             p_sdp_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
@@ -1175,7 +1173,7 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
            &bta_dm_service_search_remname_cback);
      }

      p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG));
      tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG));
      p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
      p_msg->disc_result.result.disc_res.result = BTA_SUCCESS;
      p_msg->disc_result.result.disc_res.num_uuids = uuid_list.size();
@@ -1211,6 +1209,7 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {

      // Piggy back the SCN over result field
      if (scn_found) {
        // TODO This is an enum, not a value.  Please fix
        p_msg->disc_result.result.disc_res.result =
            (3 + bta_dm_search_cb.peer_scn);
        p_msg->disc_result.result.disc_res.services |= BTA_USER_SERVICE_MASK;
@@ -1240,7 +1239,7 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
      BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
    }

    p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG));
    tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG));
    p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
    p_msg->disc_result.result.disc_res.result = BTA_FAILURE;
    p_msg->disc_result.result.disc_res.services =
+0 −1
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ typedef struct {
  uint8_t t_type;
  uint8_t param;
  uint8_t rpt_id;
  uint8_t srvc_id;
  uint16_t data;
  BT_HDR* p_data;
} tBTA_HH_CMD_DATA;
+0 −9
Original line number Diff line number Diff line
@@ -336,15 +336,6 @@ typedef struct {
  tBTM_AUTH_REQ rmt_io_caps;  /* IO Capabilities of remote device */
} tBTA_DM_SP_CFM_REQ;

enum {
  BTA_SP_KEY_STARTED, /* passkey entry started */
  BTA_SP_KEY_ENTERED, /* passkey digit entered */
  BTA_SP_KEY_ERASED,  /* passkey digit erased */
  BTA_SP_KEY_CLEARED, /* passkey cleared */
  BTA_SP_KEY_COMPLT   /* passkey entry completed */
};
typedef uint8_t tBTA_SP_KEY_TYPE;

/* Structure associated with BTA_DM_SP_KEY_NOTIF_EVT */
typedef struct {
  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
Loading