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

Commit a82aaf80 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun Committed by Gerrit Code Review
Browse files

Merge "Relax the limitation of cback_cnt, prep_cnt" into main

parents 7c6cf1cb e5ebf0ef
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -229,6 +229,7 @@ typedef struct {
  uint8_t op_code;
  uint8_t status;
  uint8_t cback_cnt[GATT_MAX_APPS];
  std::unordered_map<tGATT_IF, uint8_t> cback_cnt_map;
  uint16_t cid;
} tGATT_SR_CMD;

@@ -316,6 +317,7 @@ typedef struct {
  alarm_t* conf_timer; /* peer confirm to indication timer */

  uint8_t prep_cnt[GATT_MAX_APPS];
  std::unordered_map<tGATT_IF, uint8_t> prep_cnt_map;
  uint8_t ind_count;

  std::deque<tGATT_CMD_Q> cl_cmd_q;
+16 −4
Original line number Diff line number Diff line
@@ -402,6 +402,17 @@ void gatt_process_exec_write_req(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code,
    trans_id = gatt_sr_enqueue_cmd(tcb, cid, op_code, 0);
    gatt_sr_copy_prep_cnt_to_cback_cnt(tcb);

    if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
      auto prep_cnt_it = tcb.prep_cnt_map.begin();
      while (prep_cnt_it != tcb.prep_cnt_map.end()) {
        gatt_if = i;
        conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, gatt_if);
        tGATTS_DATA gatts_data;
        gatts_data.exec_write = flag;
        gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_WRITE_EXEC, &gatts_data);
        prep_cnt_it = tcb.prep_cnt_map.erase(prep_cnt_it);
      }
    } else {
      for (i = 0; i < GATT_MAX_APPS; i++) {
        if (tcb.prep_cnt[i]) {
          gatt_if = (tGATT_IF)(i + 1);
@@ -412,6 +423,7 @@ void gatt_process_exec_write_req(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code,
          tcb.prep_cnt[i] = 0;
        }
      }
    }
  } else /* nothing needs to be executed , send response now */
  {
    log::error("gatt_process_exec_write_req: no prepare write pending");
+77 −22
Original line number Diff line number Diff line
@@ -1323,12 +1323,18 @@ tGATT_TCB* gatt_find_tcb_by_cid(uint16_t lcid) {
}

void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB& tcb) {
  if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
    for (auto& [i, cnt] : tcb.prep_cnt_map) {
      tcb.sr_cmd.cback_cnt_map[i] = 1;
    }
  } else {
    for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
      if (tcb.prep_cnt[i]) {
        tcb.sr_cmd.cback_cnt[i] = 1;
      }
    }
  }
}

/* Get outstanding server command pointer by the transaction id */
tGATT_SR_CMD* gatt_sr_get_cmd_by_trans_id(tGATT_TCB* p_tcb, uint32_t trans_id) {
@@ -1358,6 +1364,9 @@ tGATT_SR_CMD* gatt_sr_get_cmd_by_trans_id(tGATT_TCB* p_tcb, uint32_t trans_id) {
 *
 ******************************************************************************/
bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb) {
  if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
    return tcb.sr_cmd.cback_cnt_map.empty();
  } else {
    for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
      if (tcb.sr_cmd.cback_cnt[i]) {
        return false;
@@ -1365,6 +1374,7 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb) {
    }
    return true;
  }
}

/*******************************************************************************
 *
@@ -1376,6 +1386,9 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb) {
 *
 ******************************************************************************/
bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) {
  if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
    return tcb.prep_cnt_map.empty();
  } else {
    for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
      if (tcb.prep_cnt[i]) {
        return false;
@@ -1383,6 +1396,7 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) {
    }
    return true;
  }
}

/*******************************************************************************
 *
@@ -1394,11 +1408,24 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) {
 *
 ******************************************************************************/
void gatt_sr_reset_cback_cnt(tGATT_TCB& tcb, uint16_t cid) {
  if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
    if (cid == tcb.att_lcid) {
      tcb.sr_cmd.cback_cnt_map.clear();
    } else {
      EattChannel* channel = EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cid);
      if (channel == nullptr) {
        log::warn("{}, cid 0x{:02x} already disconnected", tcb.peer_bda, cid);
        return;
      }
      channel->server_outstanding_cmd_.cback_cnt_map.clear();
    }
  } else {
    for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
      if (cid == tcb.att_lcid) {
        tcb.sr_cmd.cback_cnt[i] = 0;
      } else {
      EattChannel* channel = EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cid);
        EattChannel* channel =
                EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cid);
        if (channel == nullptr) {
          log::warn("{}, cid 0x{:02x} already disconnected", tcb.peer_bda, cid);
          return;
@@ -1407,6 +1434,7 @@ void gatt_sr_reset_cback_cnt(tGATT_TCB& tcb, uint16_t cid) {
      }
    }
  }
}

/*******************************************************************************
 *
@@ -1490,6 +1518,19 @@ void gatt_sr_update_cback_cnt(tGATT_TCB& tcb, uint16_t cid, tGATT_IF gatt_if, bo
  if (is_reset_first) {
    gatt_sr_reset_cback_cnt(tcb, cid);
  }

  if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
    if (is_inc) {
      sr_cmd_p->cback_cnt_map[idx]++;
    } else {
      auto cback_cnt_it = sr_cmd_p->cback_cnt_map.find(idx);
      if (cback_cnt_it != sr_cmd_p->cback_cnt_map.end()) {
        if ((--cback_cnt_it->second) <= 0) {
          sr_cmd_p->cback_cnt_map.erase(cback_cnt_it);
        }
      }
    }
  } else {
    if (is_inc) {
      sr_cmd_p->cback_cnt[idx]++;
    } else {
@@ -1498,6 +1539,7 @@ void gatt_sr_update_cback_cnt(tGATT_TCB& tcb, uint16_t cid, tGATT_IF gatt_if, bo
      }
    }
  }
}

/*******************************************************************************
 *
@@ -1517,6 +1559,18 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc, bool
  if (is_reset_first) {
    gatt_sr_reset_prep_cnt(tcb);
  }
  if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
    if (is_inc) {
      tcb.prep_cnt_map[gatt_if]++;
    } else {
      auto prep_cnt_i = tcb.prep_cnt_map.find(gatt_if);
      if (prep_cnt_i != tcb.prep_cnt_map.end()) {
        if (--prep_cnt_i->second <= 0) {
          tcb.prep_cnt_map.erase(prep_cnt_i);
        }
      }
    }
  } else {
    if (is_inc) {
      tcb.prep_cnt[idx]++;
    } else {
@@ -1525,6 +1579,7 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc, bool
      }
    }
  }
}

static bool gatt_is_anybody_interested_in_connection(const RawAddress& bda) {
  if (connection_manager::is_background_connection(bda)) {