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

Commit a1ef3d46 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Clean up BTM api"

parents 8886840d 5bff3ad7
Loading
Loading
Loading
Loading
+15 −29
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "stack/btm/btm_int_types.h"

#include "main/shim/btm.h"
#include "main/shim/controller.h"
#include "main/shim/entry.h"
#include "main/shim/shim.h"
#include "osi/include/log.h"
@@ -31,8 +32,6 @@ extern tBTM_CB btm_cb;
static constexpr size_t kMaxInquiryResultSize = 4096;
static uint8_t inquiry_result_buf[kMaxInquiryResultSize];

static int inquiry_type_ = 0;

static constexpr uint8_t kInquiryResultMode = 0;
static constexpr uint8_t kInquiryResultWithRssiMode = 1;
static constexpr uint8_t kExtendedInquiryResultMode = 2;
@@ -44,7 +43,7 @@ static constexpr uint8_t kTxPowerInformationNotPresent = 0x7f;
static constexpr uint8_t kNotPeriodicAdvertisement = 0x00;

static constexpr bool kActiveScanning = true;
static constexpr bool kPassiveScanning = true;
static constexpr bool kPassiveScanning = false;

extern void btm_process_cancel_complete(uint8_t status, uint8_t mode);
extern void btm_process_inq_complete(uint8_t status, uint8_t result_type);
@@ -59,10 +58,6 @@ extern void btm_ble_process_adv_pkt_cont(

using BtmRemoteDeviceName = tBTM_REMOTE_DEV_NAME;

bluetooth::shim::Btm::Btm() {}

bluetooth::shim::Btm::~Btm() {}

/**
 *
 */
@@ -90,12 +85,13 @@ void bluetooth::shim::Btm::OnExtendedInquiryResult(
}

void bluetooth::shim::Btm::OnInquiryComplete(uint16_t status) {
  btm_process_inq_complete(status, inquiry_type_);
  btm_process_inq_complete((status == 0) ? (BTM_SUCCESS) : (BTM_ERR_PROCESSING),
                           static_cast<uint8_t>(inquiry_mode_));
}

bool bluetooth::shim::Btm::SetInquiryFilter(uint8_t mode, uint8_t type,
                                            tBTM_INQ_FILT_COND data) {
  switch (mode) {
  switch (static_cast<int>(mode)) {
    case kInquiryModeOff:
      break;
    case kLimitedInquiryMode:
@@ -123,19 +119,16 @@ void bluetooth::shim::Btm::ClearInquiryFilter() {
  LOG_WARN(LOG_TAG, "UNIMPLEMENTED %s", __func__);
}

bool bluetooth::shim::Btm::SetStandardInquiryResultMode() {
void bluetooth::shim::Btm::SetStandardInquiryResultMode() {
  bluetooth::shim::GetInquiry()->SetStandardInquiryResultMode();
  return true;
}

bool bluetooth::shim::Btm::SetInquiryWithRssiResultMode() {
void bluetooth::shim::Btm::SetInquiryWithRssiResultMode() {
  bluetooth::shim::GetInquiry()->SetInquiryWithRssiResultMode();
  return true;
}

bool bluetooth::shim::Btm::SetExtendedInquiryResultMode() {
void bluetooth::shim::Btm::SetExtendedInquiryResultMode() {
  bluetooth::shim::GetInquiry()->SetExtendedInquiryResultMode();
  return true;
}

void bluetooth::shim::Btm::SetInterlacedInquiryScan() {
@@ -147,9 +140,7 @@ void bluetooth::shim::Btm::SetStandardInquiryScan() {
}

bool bluetooth::shim::Btm::IsInterlacedScanSupported() const {
  // TODO(cmanton) This is a controller query
  LOG_WARN(LOG_TAG, "UNIMPLEMENTED %s", __func__);
  return true;
  return controller_get_interface()->supports_interlaced_inquiry_scan();
}

/**
@@ -157,7 +148,7 @@ bool bluetooth::shim::Btm::IsInterlacedScanSupported() const {
 */
bool bluetooth::shim::Btm::StartInquiry(uint8_t mode, uint8_t duration,
                                        uint8_t max_responses) {
  switch (mode) {
  switch (static_cast<int>(mode)) {
    case kInquiryModeOff:
      LOG_DEBUG(LOG_TAG, "%s Stopping inquiry mode", __func__);
      bluetooth::shim::GetInquiry()->StopInquiry();
@@ -199,6 +190,7 @@ bool bluetooth::shim::Btm::StartInquiry(uint8_t mode, uint8_t duration,
      LOG_WARN(LOG_TAG, "%s Unknown inquiry mode:%d", __func__, mode);
      return false;
  }
  inquiry_mode_ = static_cast<int>(mode);
  return true;
}

@@ -467,24 +459,18 @@ void bluetooth::shim::Btm::StopConnectability() {
  bluetooth::shim::GetAdvertising()->StopAdvertising();
}

bool bluetooth::shim::Btm::StartActiveScanning() {
void bluetooth::shim::Btm::StartActiveScanning() {
  StartScanning(kActiveScanning);
  return true;
}

bool bluetooth::shim::Btm::StopActiveScanning() {
void bluetooth::shim::Btm::StopActiveScanning() {
  bluetooth::shim::GetScanning()->StopScanning();
  return true;
}

bool bluetooth::shim::Btm::StartObserving() {
  StartScanning(kPassiveScanning);
  return true;
}
void bluetooth::shim::Btm::StartObserving() { StartScanning(kPassiveScanning); }

bool bluetooth::shim::Btm::StopObserving() {
void bluetooth::shim::Btm::StopObserving() {
  bluetooth::shim::GetScanning()->StopScanning();
  return true;
}

void bluetooth::shim::Btm::StartScanning(bool use_active_scanning) {
+49 −43
Original line number Diff line number Diff line
@@ -23,21 +23,23 @@

#include "stack/include/btm_api_types.h"

//
// NOTE: limited and general constants for inquiry and discoverable are swapped
//

/* Discoverable modes */
static constexpr int kDiscoverableModeOff = 0;
static constexpr int kLimitedDiscoverableMode = 1;
static constexpr int kGeneralDiscoverableMode = 2;
static constexpr int kDiscoverableModeOff = 0;      // BTM_NON_DISCOVERABLE
static constexpr int kLimitedDiscoverableMode = 1;  // BTM_LIMITED_DISCOVERABLE
static constexpr int kGeneralDiscoverableMode = 2;  // BTM_GENERAL_DISCOVERABLE

/* Inquiry modes */
// NOTE: The inquiry general/limited are reversed from the discoverability
// constants
static constexpr int kInquiryModeOff = 0;
static constexpr int kGeneralInquiryMode = 1;
static constexpr int kLimitedInquiryMode = 2;
static constexpr int kInquiryModeOff = 0;      // BTM_INQUIRY_NONE
static constexpr int kGeneralInquiryMode = 1;  // BTM_GENERAL_INQUIRY
static constexpr int kLimitedInquiryMode = 2;  // BTM_LIMITED_INQUIRY

/* Connectable modes */
static constexpr int kConnectibleModeOff = 0;
static constexpr int kConnectibleModeOn = 1;
static constexpr int kConnectibleModeOff = 0;  // BTM_NON_CONNECTABLE
static constexpr int kConnectibleModeOn = 1;   // BTM_CONNECTABLE

/* Inquiry and page scan modes */
static constexpr int kStandardScanType = 0;
@@ -69,29 +71,29 @@ namespace bluetooth {
namespace shim {

using BtmStatus = enum : uint16_t {
  BTM_SUCCESS = 0,         /* 0  Command succeeded                 */
  BTM_CMD_STARTED,         /* 1  Command started OK.               */
  BTM_BUSY,                /* 2  Device busy with another command  */
  BTM_NO_RESOURCES,        /* 3  No resources to issue command     */
  BTM_MODE_UNSUPPORTED,    /* 4  Request for 1 or more unsupported modes */
  BTM_ILLEGAL_VALUE,       /* 5  Illegal parameter value           */
  BTM_WRONG_MODE,          /* 6  Device in wrong mode for request  */
  BTM_UNKNOWN_ADDR,        /* 7  Unknown remote BD address         */
  BTM_DEVICE_TIMEOUT,      /* 8  Device timeout                    */
  BTM_BAD_VALUE_RET,       /* 9  A bad value was received from HCI */
  BTM_ERR_PROCESSING,      /* 10 Generic error                     */
  BTM_NOT_AUTHORIZED,      /* 11 Authorization failed              */
  BTM_DEV_RESET,           /* 12 Device has been reset             */
  BTM_CMD_STORED,          /* 13 request is stored in control block */
  BTM_ILLEGAL_ACTION,      /* 14 state machine gets illegal command */
  BTM_DELAY_CHECK,         /* 15 delay the check on encryption */
  BTM_SCO_BAD_LENGTH,      /* 16 Bad SCO over HCI data length */
  BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set  */
  BTM_FAILED_ON_SECURITY,  /* 18 security failed                   */
  BTM_REPEATED_ATTEMPTS,   /* 19 repeated attempts for LE security requests */
  BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be
  BTM_SUCCESS = 0,              /* Command succeeded                 */
  BTM_CMD_STARTED = 1,          /* Command started OK.               */
  BTM_BUSY = 2,                 /* Device busy with another command  */
  BTM_NO_RESOURCES = 3,         /* No resources to issue command     */
  BTM_MODE_UNSUPPORTED = 4,     /* Request for 1 or more unsupported modes */
  BTM_ILLEGAL_VALUE = 5,        /* Illegal parameter value           */
  BTM_WRONG_MODE = 6,           /* Device in wrong mode for request  */
  BTM_UNKNOWN_ADDR = 7,         /* Unknown remote BD address         */
  BTM_DEVICE_TIMEOUT = 8,       /* Device timeout                    */
  BTM_BAD_VALUE_RET = 9,        /* A bad value was received from HCI */
  BTM_ERR_PROCESSING = 10,      /* Generic error                     */
  BTM_NOT_AUTHORIZED = 11,      /* Authorization failed              */
  BTM_DEV_RESET = 12,           /* Device has been reset             */
  BTM_CMD_STORED = 13,          /* request is stored in control block */
  BTM_ILLEGAL_ACTION = 14,      /* state machine gets illegal command */
  BTM_DELAY_CHECK = 15,         /* delay the check on encryption */
  BTM_SCO_BAD_LENGTH = 16,      /* Bad SCO over HCI data length */
  BTM_SUCCESS_NO_SECURITY = 17, /* security passed, no security set  */
  BTM_FAILED_ON_SECURITY = 18,  /* security failed                   */
  BTM_REPEATED_ATTEMPTS = 19,   /* repeated attempts for LE security requests */
  BTM_MODE4_LEVEL4_NOT_SUPPORTED = 20, /* Secure Connections Only Mode can't be
                                     supported */
  BTM_DEV_BLACKLISTED             /* 21 The device is Blacklisted */
  BTM_DEV_BLACKLISTED = 21,            /* The device is Blacklisted */
};

class ReadRemoteName {
@@ -126,10 +128,10 @@ class ReadRemoteName {

class Btm {
 public:
  Btm();
  ~Btm();
  Btm() = default;
  ~Btm() = default;

  // Callbacks
  // Inquiry result callbacks
  void OnInquiryResult(std::vector<const uint8_t> result);
  void OnInquiryResultWithRssi(std::vector<const uint8_t> result);
  void OnExtendedInquiryResult(std::vector<const uint8_t> result);
@@ -141,9 +143,9 @@ class Btm {
  void SetFilterInquiryOnDevice();
  void ClearInquiryFilter();

  bool SetStandardInquiryResultMode();
  bool SetInquiryWithRssiResultMode();
  bool SetExtendedInquiryResultMode();
  void SetStandardInquiryResultMode();
  void SetInquiryWithRssiResultMode();
  void SetExtendedInquiryResultMode();

  void SetInterlacedInquiryScan();
  void SetStandardInquiryScan();
@@ -163,6 +165,7 @@ class Btm {
  bool IsGeneralPeriodicInquiryActive() const;
  bool IsLimitedPeriodicInquiryActive() const;

  // Discoverability API
  void SetClassicGeneralDiscoverability(uint16_t window, uint16_t interval);
  void SetClassicLimitedDiscoverability(uint16_t window, uint16_t interval);
  void SetClassicDiscoverabilityOff();
@@ -185,23 +188,24 @@ class Btm {

  bool IsLeAclConnected(const RawAddress& raw_address) const;

  // Remote device name
  // Remote device name API
  BtmStatus ReadClassicRemoteDeviceName(const RawAddress& raw_address,
                                        tBTM_CMPL_CB* callback);
  BtmStatus ReadLeRemoteDeviceName(const RawAddress& raw_address,
                                   tBTM_CMPL_CB* callback);
  BtmStatus CancelAllReadRemoteDeviceName();

  // Le neighbor interaction API
  void StartAdvertising();
  void StopAdvertising();
  void StartConnectability();
  void StopConnectability();

  bool StartActiveScanning();
  bool StopActiveScanning();
  void StartActiveScanning();
  void StopActiveScanning();

  bool StartObserving();
  bool StopObserving();
  void StartObserving();
  void StopObserving();

  size_t GetNumberOfAdvertisingInstances() const;

@@ -212,6 +216,8 @@ class Btm {
  bool CheckClassicAclLink(const RawAddress& raw_address) { return true; }
  bool CheckLeAclLink(const RawAddress& raw_address) { return true; }
  void StartScanning(bool use_active_scanning);

  int inquiry_mode_ = 0;
};

}  // namespace shim
+8 −22
Original line number Diff line number Diff line
@@ -48,10 +48,8 @@ tBTM_STATUS bluetooth::shim::BTM_StartInquiry(tBTM_INQ_PARMS* p_inqparms,

  uint8_t classic_mode = p_inqparms->mode & 0x0f;

  if (!shim_btm.StartActiveScanning()) {
    LOG_WARN(LOG_TAG, "%s Unable to start le active scanning", __func__);
    return BTM_ERR_PROCESSING;
  }
  shim_btm.StartActiveScanning();

  if (!shim_btm.SetInquiryFilter(classic_mode, p_inqparms->filter_cond_type,
                                 p_inqparms->filter_cond)) {
    LOG_WARN(LOG_TAG, "%s Unable to set inquiry filter", __func__);
@@ -181,20 +179,14 @@ tBTM_STATUS bluetooth::shim::BTM_BleObserve(bool start, uint8_t duration_sec,

    btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb;
    btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb;
    if (!shim_btm.StartObserving()) {
      LOG_WARN(LOG_TAG, "%s Unable to start le observing", __func__);
      return BTM_ERR_PROCESSING;
    }
    shim_btm.StartObserving();
    btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE;
  } else {
    if (!(btm_cb.ble_ctr_cb.scan_activity & BTM_LE_OBSERVE_ACTIVE)) {
      LOG_WARN(LOG_TAG, "%s Observing already inactive", __func__);
    }
    btm_cb.ble_ctr_cb.scan_activity &= ~BTM_LE_OBSERVE_ACTIVE;
    if (!shim_btm.StopObserving()) {
      LOG_WARN(LOG_TAG, "%s Unable to stop le observing", __func__);
      return BTM_ERR_PROCESSING;
    }
    shim_btm.StopObserving();
    if (btm_cb.ble_ctr_cb.p_obs_cmpl_cb) {
      (btm_cb.ble_ctr_cb.p_obs_cmpl_cb)(&btm_cb.btm_inq_vars.inq_cmpl_info);
    }
@@ -226,24 +218,18 @@ tBTM_STATUS bluetooth::shim::BTM_SetPageScanType(uint16_t scan_type) {
tBTM_STATUS bluetooth::shim::BTM_SetInquiryMode(uint8_t inquiry_mode) {
  switch (inquiry_mode) {
    case kStandardInquiryResult:
      if (shim_btm.SetStandardInquiryResultMode()) {
        return BTM_SUCCESS;
      }
      shim_btm.SetStandardInquiryResultMode();
      break;
    case kInquiryResultWithRssi:
      if (shim_btm.SetInquiryWithRssiResultMode()) {
        return BTM_SUCCESS;
      }
      shim_btm.SetInquiryWithRssiResultMode();
      break;
    case kExtendedInquiryResult:
      if (shim_btm.SetExtendedInquiryResultMode()) {
        return BTM_SUCCESS;
      }
      shim_btm.SetExtendedInquiryResultMode();
      break;
    default:
      return BTM_ILLEGAL_VALUE;
  }
  return BTM_MODE_UNSUPPORTED;
  return BTM_SUCCESS;
}

uint16_t bluetooth::shim::BTM_ReadDiscoverability(uint16_t* p_window,