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

Commit 1fdaa9f1 authored by Yun-hao Chung's avatar Yun-hao Chung Committed by Gerrit Code Review
Browse files

Merge "Floss: Add dynamically control HIDP and HOGP"

parents 189f048a da0404eb
Loading
Loading
Loading
Loading
+26 −19
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ static const char* bta_hh_hid_event_name(uint16_t event);
 *
 ******************************************************************************/
void bta_hh_api_enable(const tBTA_HH_DATA* p_data) {
  tBTA_HH_STATUS status = BTA_HH_ERR;
  tBTA_HH_STATUS status = BTA_HH_OK;
  uint8_t xx;

  /* initialize BTE HID */
@@ -84,12 +84,8 @@ void bta_hh_api_enable(const tBTA_HH_DATA* p_data) {

  memset(&bta_hh_cb, 0, sizeof(tBTA_HH_CB));

  /* Register with L2CAP */
  if (HID_HostRegister(bta_hh_cback) == HID_SUCCESS) {
  /* store parameters */
  bta_hh_cb.p_cback = p_data->api_enable.p_cback;

    status = BTA_HH_OK;
  /* initialize device CB */
  for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
    bta_hh_cb.kdev[xx].state = BTA_HH_IDLE_ST;
@@ -98,20 +94,31 @@ void bta_hh_api_enable(const tBTA_HH_DATA* p_data) {
  }

  /* initialize control block map */
    for (xx = 0; xx < BTA_HH_MAX_KNOWN; xx++)
  for (xx = 0; xx < BTA_HH_MAX_KNOWN; xx++) {
    bta_hh_cb.cb_index[xx] = BTA_HH_IDX_INVALID;
  }

  if (status == BTA_HH_OK) {
  if (p_data->api_enable.enable_hid) {
    /* Register with L2CAP */
    if (HID_HostRegister(bta_hh_cback) != HID_SUCCESS) {
      status = BTA_HH_ERR;
    }
  }

  if (status == BTA_HH_OK && p_data->api_enable.enable_hogp) {
    bta_hh_le_enable();
  } else
  {
  } else {
    /* signal BTA call back event */
    tBTA_HH bta_hh;
    bta_hh.status = status;
    if (status != BTA_HH_OK) {
      LOG_ERROR("Failed to register, status: %d", status);
    }
    if (bta_hh_cb.p_cback) {
      (*bta_hh_cb.p_cback)(BTA_HH_ENABLE_EVT, &bta_hh);
    }
  }
}
/*******************************************************************************
 *
 * Function         bta_hh_api_disable
+4 −2
Original line number Diff line number Diff line
@@ -54,11 +54,11 @@ static const tBTA_SYS_REG bta_hh_reg = {bta_hh_hdl_event, BTA_HhDisable};
 * Returns          void
 *
 ******************************************************************************/
void BTA_HhEnable(tBTA_HH_CBACK* p_cback) {
void BTA_HhEnable(tBTA_HH_CBACK* p_cback, bool enable_hid, bool enable_hogp) {
  /* register with BTA system manager */
  bta_sys_register(BTA_ID_HH, &bta_hh_reg);

  post_on_bt_main([p_cback]() {
  post_on_bt_main([p_cback, enable_hid, enable_hogp]() {
    tBTA_HH_DATA data = {
        .api_enable =
            {
@@ -67,6 +67,8 @@ void BTA_HhEnable(tBTA_HH_CBACK* p_cback) {
                        .event = BTA_HH_API_ENABLE_EVT,
                    },
                .p_cback = p_cback,
                .enable_hid = enable_hid,
                .enable_hogp = enable_hogp,
            },
    };
    bta_hh_api_enable(&data);
+2 −0
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ typedef struct {
  BT_HDR_RIGID hdr;
  uint8_t service_name[BTA_SERVICE_NAME_LEN + 1];
  tBTA_HH_CBACK* p_cback;
  bool enable_hid;
  bool enable_hogp;
} tBTA_HH_API_ENABLE;

typedef struct {
+4 −3
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ typedef void(tBTA_HH_CBACK)(tBTA_HH_EVT event, tBTA_HH* p_data);

/*******************************************************************************
 *
 * Function         BTA_HhRegister
 * Function         BTA_HhEnable
 *
 * Description      This function enable HID host and registers HID-Host with
 *                  lower layers.
@@ -335,11 +335,12 @@ typedef void(tBTA_HH_CBACK)(tBTA_HH_EVT event, tBTA_HH* p_data);
 * Returns          void
 *
 ******************************************************************************/
extern void BTA_HhEnable(tBTA_HH_CBACK* p_cback);
extern void BTA_HhEnable(tBTA_HH_CBACK* p_cback, bool enable_hid,
                         bool enable_hogp);

/*******************************************************************************
 *
 * Function         BTA_HhDeregister
 * Function         BTA_HhDisable
 *
 * Description      This function is called when the host is about power down.
 *
+22 −2
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ typedef struct hid_kb_list {
btif_hh_cb_t btif_hh_cb;

static bthh_callbacks_t* bt_hh_callbacks = NULL;
static bthh_profile_enable_t bt_hh_enable_type = {.hidp_enabled = true,
                                                  .hogp_enabled = true};

/* List of HID keyboards for which the NUMLOCK state needs to be
 * turned ON by default. Add devices to this list to apply the
@@ -704,7 +706,8 @@ void btif_hh_service_registration(bool enable) {
      btif_hd_service_registration();
    }
  } else if (enable) {
    BTA_HhEnable(bte_hh_evt);
    BTA_HhEnable(bte_hh_evt, bt_hh_enable_type.hidp_enabled,
                 bt_hh_enable_type.hogp_enabled);
  } else {
    btif_hh_cb.service_dereg_active = TRUE;
    BTA_HhDisable();
@@ -1830,6 +1833,21 @@ static void cleanup(void) {
  }
}

/*******************************************************************************
 *
 * Function         configure_enabled_profiles
 *
 * Description      Configure HIDP or HOGP enablement. Require to cleanup and
 *re-init to take effect.
 *
 * Returns          void
 *
 ******************************************************************************/
static void configure_enabled_profiles(bool enable_hidp, bool enable_hogp) {
  bt_hh_enable_type.hidp_enabled = enable_hidp;
  bt_hh_enable_type.hogp_enabled = enable_hogp;
}

static const bthh_interface_t bthhInterface = {
    sizeof(bthhInterface),
    init,
@@ -1846,6 +1864,7 @@ static const bthh_interface_t bthhInterface = {
    set_report,
    send_data,
    cleanup,
    configure_enabled_profiles,
};

/*******************************************************************************
@@ -1860,7 +1879,8 @@ static const bthh_interface_t bthhInterface = {
bt_status_t btif_hh_execute_service(bool b_enable) {
  if (b_enable) {
    /* Enable and register with BTA-HH */
    BTA_HhEnable(bte_hh_evt);
    BTA_HhEnable(bte_hh_evt, bt_hh_enable_type.hidp_enabled,
                 bt_hh_enable_type.hogp_enabled);
  } else {
    /* Disable HH */
    BTA_HhDisable();
Loading