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

Commit a81d2be4 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by android-build-merger
Browse files

Centralize call to gatt_update_app_use_link_flag for GATT_Connect

am: fc138f08

Change-Id: Icb9fd21e6af43dc4d31afba64bd58655a8f6ff5a
parents 0f9bc115 fc138f08
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -1099,25 +1099,39 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
                  tBT_TRANSPORT transport, bool opportunistic,
                  uint8_t initiating_phys) {
  LOG(INFO) << __func__ << "gatt_if=" << +gatt_if << " " << bd_addr;
  LOG(INFO) << __func__ << "gatt_if=" << +gatt_if << ", address=" << bd_addr;

  /* Make sure app is registered */
  tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
  if (!p_reg) {
    LOG(ERROR) << "gatt_if = " << +gatt_if << " is not registered";
    return (false);
    return false;
  }

  if (is_direct)
    return gatt_act_connect(p_reg, bd_addr, transport, opportunistic,
                            initiating_phys);

  // is not direct
  if (transport != BT_TRANSPORT_LE) {
  if (!is_direct && transport != BT_TRANSPORT_LE) {
    LOG(ERROR) << "Unsupported transport for background connection";
    return false;
  }
  return gatt_auto_connect_dev_add(gatt_if, bd_addr);

  bool ret;
  if (is_direct) {
    ret = gatt_act_connect(p_reg, bd_addr, transport, initiating_phys);
  } else {
    ret = gatt::connection_manager::background_connect_add(gatt_if, bd_addr);
  }

  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
  // background connections don't necesarly create tcb
  if (!p_tcb) return ret;

  if (ret) {
    if (!opportunistic)
      gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, !is_direct);
    else
      VLOG(1) << __func__
              << ": connection is opportunistic, not updating app usage";
  }
  return ret;
}

/*******************************************************************************
+1 −4
Original line number Diff line number Diff line
@@ -396,8 +396,7 @@ extern void gatt_set_err_rsp(bool enable, uint8_t req_op_code,
/* from gatt_main.cc */
extern bool gatt_disconnect(tGATT_TCB* p_tcb);
extern bool gatt_act_connect(tGATT_REG* p_reg, const RawAddress& bd_addr,
                             tBT_TRANSPORT transport, bool opportunistic,
                             int8_t initiating_phys);
                             tBT_TRANSPORT transport, int8_t initiating_phys);
extern bool gatt_connect(const RawAddress& rem_bda, tGATT_TCB* p_tcb,
                         tBT_TRANSPORT transport, uint8_t initiating_phys);
extern void gatt_data_process(tGATT_TCB& p_tcb, BT_HDR* p_buf);
@@ -467,8 +466,6 @@ extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle);
extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg);

/* for background connection */
extern bool gatt_auto_connect_dev_add(tGATT_IF gatt_if,
                                      const RawAddress& bd_addr);
extern bool gatt_auto_connect_dev_remove(tGATT_IF gatt_if,
                                         const RawAddress& bd_addr);

+18 −29
Original line number Diff line number Diff line
@@ -343,48 +343,37 @@ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb,

/** GATT connection initiation */
bool gatt_act_connect(tGATT_REG* p_reg, const RawAddress& bd_addr,
                      tBT_TRANSPORT transport, bool opportunistic,
                      int8_t initiating_phys) {
  bool ret = false;

                      tBT_TRANSPORT transport, int8_t initiating_phys) {
  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
  if (p_tcb != NULL) {
    ret = true;
    uint8_t st = gatt_get_ch_state(p_tcb);

    /* before link down, another app try to open a GATT connection */
    uint8_t st = gatt_get_ch_state(p_tcb);
    if (st == GATT_CH_OPEN && p_tcb->app_hold_link.empty() &&
        transport == BT_TRANSPORT_LE) {
      if (!gatt_connect(bd_addr, p_tcb, transport, initiating_phys))
        ret = false;
        return false;
    } else if (st == GATT_CH_CLOSING) {
      /* need to complete the closing first */
      ret = false;
      return false;
    }
  } else {

    return true;
  }

  p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, transport);
  if (!p_tcb) {
      ret = 0;
    LOG(ERROR) << "Max TCB for gatt_if [ " << +p_reg->gatt_if << "] reached.";
    } else {
    return false;
  }

  if (!gatt_connect(bd_addr, p_tcb, transport, initiating_phys)) {
    LOG(ERROR) << "gatt_connect failed";
    fixed_queue_free(p_tcb->pending_ind_q, NULL);
    *p_tcb = tGATT_TCB();
      } else
        ret = true;
    }
  }

  if (ret) {
    if (!opportunistic)
      gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, false);
    else
      VLOG(1) << __func__
              << ": connection is opportunistic, not updating app usage";
    return false;
  }

  return ret;
  return true;
}

/** This callback function is called by L2CAP to indicate that the ATT fixed
+0 −20
Original line number Diff line number Diff line
@@ -1296,26 +1296,6 @@ uint8_t* gatt_dbg_op_name(uint8_t op_code) {
    return (uint8_t*)"Op Code Exceed Max";
}

/**
 * This function add a device for background connection procedure.
 *
 * Parameters       p_reg: application record,
 *                  bd_addr: peer device address.
 *
 * Returns          true if connection started; false otherwise.
 */
bool gatt_auto_connect_dev_add(tGATT_IF gatt_if, const RawAddress& bd_addr) {
  VLOG(1) << __func__;

  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
  bool ret = gatt::connection_manager::background_connect_add(gatt_if, bd_addr);
  if (ret && p_tcb != NULL) {
    /* if a connected device, update the link holding number */
    gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true);
  }
  return ret;
}

/** Remove the application interface for the specified background device */
bool gatt_auto_connect_dev_remove(tGATT_IF gatt_if, const RawAddress& bd_addr) {
  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);