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

Commit 33335433 authored by Zach Johnson's avatar Zach Johnson
Browse files

Remove notion of multiple hardware modules

BT is the only one

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I600b0d3db8221b88aec4b8f9f695497260e84aa0
parent 32a40f0f
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ void bta_dm_enable(tBTA_DM_SEC_CBACK* p_sec_cback) {
  }

  /* first, register our callback to SYS HW manager */
  bta_sys_hw_register(BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback);
  bta_sys_hw_register(bta_dm_sys_hw_cback);

  /* make sure security callback is saved - if no callback, do not erase the
  previous one,
@@ -275,7 +275,6 @@ void bta_dm_enable(tBTA_DM_SEC_CBACK* p_sec_cback) {
  tBTA_SYS_HW_MSG* sys_enable_event =
      (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG));
  sys_enable_event->hdr.event = BTA_SYS_API_ENABLE_EVT;
  sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;

  bta_sys_sendmsg(sys_enable_event);

@@ -366,17 +365,10 @@ static void bta_dm_sys_hw_cback(tBTA_SYS_HW_EVT status) {
    memset(&bta_dm_search_cb, 0, sizeof(bta_dm_search_cb));

    /* unregister from SYS */
    bta_sys_hw_unregister(BTA_SYS_HW_BLUETOOTH);
    bta_sys_hw_unregister();
    /* notify BTA DM is now unactive */
    bta_dm_cb.is_bta_dm_active = false;
  } else if (status == BTA_SYS_HW_ON_EVT) {
    /* FIXME: We should not unregister as the SYS shall invoke this callback on
     * a H/W error.
     * We need to revisit when this platform has more than one BLuetooth H/W
     * chip
     */
    // bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH);

    /* save security callback */
    temp_cback = bta_dm_cb.p_sec_cback;
    /* make sure the control block is properly initialized */
@@ -465,7 +457,7 @@ void bta_dm_disable() {
  L2CA_SetIdleTimeoutByBdAddr(RawAddress::kAny, 0, BT_TRANSPORT_LE);

  /* disable all active subsystems */
  bta_sys_disable(BTA_SYS_HW_BLUETOOTH);
  bta_sys_disable();

  BTM_SetDiscoverability(BTM_NON_DISCOVERABLE, 0, 0);
  BTM_SetConnectability(BTM_NON_CONNECTABLE, 0, 0);
@@ -2868,11 +2860,10 @@ static void bta_dm_disable_conn_down_timer_cback(UNUSED_ATTR void* data) {
  bta_dm_disable_pm();

  /* register our callback to SYS HW manager */
  bta_sys_hw_register(BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback);
  bta_sys_hw_register(bta_dm_sys_hw_cback);

  /* send a message to BTA SYS */
  sys_enable_event->hdr.event = BTA_SYS_API_DISABLE_EVT;
  sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;
  bta_sys_sendmsg(sys_enable_event);

  bta_dm_cb.disabling = false;
+3 −15
Original line number Diff line number Diff line
@@ -44,16 +44,6 @@ typedef bool(tBTA_SYS_EVT_HDLR)(BT_HDR* p_msg);
/* disable function type */
typedef void(tBTA_SYS_DISABLE)(void);

/* HW modules */
enum {
  BTA_SYS_HW_BLUETOOTH,
  BTA_SYS_HW_RT,

  BTA_SYS_MAX_HW_MODULES
};

typedef uint16_t tBTA_SYS_HW_MODULE;

#ifndef BTA_DM_NUM_JV_ID
#define BTA_DM_NUM_JV_ID 2
#endif
@@ -158,7 +148,6 @@ typedef struct {
/* data type to send events to BTA SYS HW manager */
typedef struct {
  BT_HDR hdr;
  tBTA_SYS_HW_MODULE hw_module;
} tBTA_SYS_HW_MSG;

typedef void (*tBTA_SYS_REGISTER)(uint8_t id, const tBTA_SYS_REG* p_reg);
@@ -225,11 +214,10 @@ extern void bta_sys_sendmsg(void* p_msg);
extern void bta_sys_sendmsg_delayed(void* p_msg, const base::TimeDelta& delay);
extern void bta_sys_start_timer(alarm_t* alarm, uint64_t interval_ms,
                                uint16_t event, uint16_t layer_specific);
extern void bta_sys_disable(tBTA_SYS_HW_MODULE module);
extern void bta_sys_disable();

extern void bta_sys_hw_register(tBTA_SYS_HW_MODULE module,
                                tBTA_SYS_HW_CBACK* cback);
extern void bta_sys_hw_unregister(tBTA_SYS_HW_MODULE module);
extern void bta_sys_hw_register(tBTA_SYS_HW_CBACK* cback);
extern void bta_sys_hw_unregister();

extern void bta_sys_rm_register(tBTA_SYS_CONN_CBACK* p_cback);
extern void bta_sys_pm_register(tBTA_SYS_CONN_CBACK* p_cback);
+2 −4
Original line number Diff line number Diff line
@@ -54,10 +54,8 @@ typedef struct {
  tBTA_SYS_REG* reg[BTA_ID_MAX]; /* registration structures */
  bool is_reg[BTA_ID_MAX];       /* registration structures */
  tBTA_SYS_HW_STATE state;
  tBTA_SYS_HW_CBACK* sys_hw_cback[BTA_SYS_MAX_HW_MODULES]; /* enable callback
                                                              for each HW
                                                              modules */
  uint32_t sys_hw_module_active; /* bitmask of all active modules */
  tBTA_SYS_HW_CBACK* sys_hw_cback;
  bool bluetooth_active;
  uint16_t sys_features;         /* Bitmask of sys features */

  tBTA_SYS_CONN_CBACK* prm_cb; /* role management callback registered by DM */
+26 −88
Original line number Diff line number Diff line
@@ -226,13 +226,11 @@ bool bta_sys_sm_execute(BT_HDR* p_msg) {
  return freebuf;
}

void bta_sys_hw_register(tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK* cback) {
  bta_sys_cb.sys_hw_cback[module] = cback;
void bta_sys_hw_register(tBTA_SYS_HW_CBACK* cback) {
  bta_sys_cb.sys_hw_cback = cback;
}

void bta_sys_hw_unregister(tBTA_SYS_HW_MODULE module) {
  bta_sys_cb.sys_hw_cback[module] = NULL;
}
void bta_sys_hw_unregister() { bta_sys_cb.sys_hw_cback = NULL; }

/*******************************************************************************
 *
@@ -276,24 +274,9 @@ void bta_sys_hw_btm_cback(tBTM_DEV_STATUS status) {
 *
 ******************************************************************************/
void bta_sys_hw_error(UNUSED_ATTR tBTA_SYS_HW_MSG* p_sys_hw_msg) {
  uint8_t module_index;

  APPL_TRACE_DEBUG("%s", __func__);

  for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES;
       module_index++) {
    if (bta_sys_cb.sys_hw_module_active & ((uint32_t)1 << module_index)) {
      switch (module_index) {
        case BTA_SYS_HW_BLUETOOTH:
          /* Send BTA_SYS_HW_ERROR_EVT to DM */
          if (bta_sys_cb.sys_hw_cback[module_index] != NULL)
            bta_sys_cb.sys_hw_cback[module_index](BTA_SYS_HW_ERROR_EVT);
          break;
        default:
          /* not yet supported */
          break;
      }
    }
  if (bta_sys_cb.bluetooth_active && bta_sys_cb.sys_hw_cback != NULL) {
    bta_sys_cb.sys_hw_cback(BTA_SYS_HW_ERROR_EVT);
  }
}

@@ -310,28 +293,22 @@ void bta_sys_hw_error(UNUSED_ATTR tBTA_SYS_HW_MSG* p_sys_hw_msg) {
 ******************************************************************************/

void bta_sys_hw_api_enable(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
  if ((!bta_sys_cb.sys_hw_module_active) &&
      (bta_sys_cb.state != BTA_SYS_HW_ON)) {
  if (!bta_sys_cb.bluetooth_active && bta_sys_cb.state != BTA_SYS_HW_ON) {
    /* register which HW module was turned on */
    bta_sys_cb.sys_hw_module_active |= ((uint32_t)1 << p_sys_hw_msg->hw_module);
    bta_sys_cb.bluetooth_active = true;

    tBTA_SYS_HW_MSG* p_msg =
        (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG));
    p_msg->hdr.event = BTA_SYS_EVT_ENABLED_EVT;
    p_msg->hw_module = p_sys_hw_msg->hw_module;

    bta_sys_sendmsg(p_msg);
  } else {
    /* register which HW module was turned on */
    bta_sys_cb.sys_hw_module_active |= ((uint32_t)1 << p_sys_hw_msg->hw_module);
    bta_sys_cb.bluetooth_active = true;

    /* HW already in use, so directly notify the caller */
    if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module] != NULL)
      bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module](BTA_SYS_HW_ON_EVT);
    if (bta_sys_cb.sys_hw_cback != NULL)
      bta_sys_cb.sys_hw_cback(BTA_SYS_HW_ON_EVT);
  }

  APPL_TRACE_EVENT("bta_sys_hw_api_enable for %d, active modules 0x%04X",
                   p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active);
}

/*******************************************************************************
@@ -346,34 +323,21 @@ void bta_sys_hw_api_enable(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
 *
 ******************************************************************************/
void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
  APPL_TRACE_DEBUG("bta_sys_hw_api_disable for %d, active modules: 0x%04X",
                   p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active);

  /* make sure the related SW blocks were stopped */
  bta_sys_disable(p_sys_hw_msg->hw_module);
  bta_sys_disable();

  /* register which module we turn off */
  bta_sys_cb.sys_hw_module_active &= ~((uint32_t)1 << p_sys_hw_msg->hw_module);

  /* if there are still some SW modules using the HW, just provide an answer to
   * the calling */
  if (bta_sys_cb.sys_hw_module_active != 0) {
    /*  if there are still some SW modules using the HW,  directly notify the
     * caller */
    if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module] != NULL)
      bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module](BTA_SYS_HW_OFF_EVT);
  } else {
  bta_sys_cb.bluetooth_active = false;

  /* manually update the state of our system */
  bta_sys_cb.state = BTA_SYS_HW_STOPPING;

  tBTA_SYS_HW_MSG* p_msg =
      (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG));
  p_msg->hdr.event = BTA_SYS_EVT_DISABLED_EVT;
    p_msg->hw_module = p_sys_hw_msg->hw_module;

  bta_sys_sendmsg(p_msg);
}
}

/*******************************************************************************
 *
@@ -386,7 +350,6 @@ void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
 *
 ******************************************************************************/
void bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
  APPL_TRACE_EVENT("bta_sys_hw_evt_enabled for %i", p_sys_hw_msg->hw_module);
  BTM_DeviceReset(NULL);
}

@@ -401,15 +364,8 @@ void bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
 *
 ******************************************************************************/
void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
  uint8_t hw_module_index;

  APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X",
                   p_sys_hw_msg->hw_module);

  for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES;
       hw_module_index++) {
    if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
      bta_sys_cb.sys_hw_cback[hw_module_index](BTA_SYS_HW_OFF_EVT);
  if (bta_sys_cb.sys_hw_cback != NULL) {
    bta_sys_cb.sys_hw_cback(BTA_SYS_HW_OFF_EVT);
  }
}

@@ -425,14 +381,8 @@ void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
 *
 ******************************************************************************/
void bta_sys_hw_evt_stack_enabled(UNUSED_ATTR tBTA_SYS_HW_MSG* p_sys_hw_msg) {
  uint8_t hw_module_index;

  APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers");

  for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES;
       hw_module_index++) {
    if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
      bta_sys_cb.sys_hw_cback[hw_module_index](BTA_SYS_HW_ON_EVT);
  if (bta_sys_cb.sys_hw_cback != NULL) {
    bta_sys_cb.sys_hw_cback(BTA_SYS_HW_ON_EVT);
  }
}

@@ -569,21 +519,9 @@ void bta_sys_start_timer(alarm_t* alarm, uint64_t interval_ms, uint16_t event,
 * Returns          void
 *
 ******************************************************************************/
void bta_sys_disable(tBTA_SYS_HW_MODULE module) {
  int bta_id = 0;
  int bta_id_max = 0;

  APPL_TRACE_DEBUG("bta_sys_disable: module %i", module);

  switch (module) {
    case BTA_SYS_HW_BLUETOOTH:
      bta_id = BTA_ID_DM_SEARCH;
      bta_id_max = BTA_ID_BLUETOOTH_MAX;
      break;
    default:
      APPL_TRACE_WARNING("bta_sys_disable: unkown module");
      return;
  }
void bta_sys_disable() {
  int bta_id = BTA_ID_DM_SEARCH;
  int bta_id_max = BTA_ID_BLUETOOTH_MAX;

  for (; bta_id <= bta_id_max; bta_id++) {
    if (bta_sys_cb.reg[bta_id] != NULL) {