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

Commit e5ebf0ef authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

Relax the limitation of cback_cnt, prep_cnt

Bug: 348559823
Bug: 273561907
Test: atest BluetoothInstrumentationTests
Change-Id: I042a46add291e36040874e11d68381d1ad8f9ce7
parent 4c49d759
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -228,6 +228,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;

@@ -315,6 +316,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;
+17 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
 ******************************************************************************/

#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>
#include <string.h>

#include <algorithm>
@@ -401,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);
@@ -411,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
@@ -1316,12 +1316,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) {
@@ -1351,6 +1357,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;
@@ -1358,6 +1367,7 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb) {
    }
    return true;
  }
}

/*******************************************************************************
 *
@@ -1369,6 +1379,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;
@@ -1376,6 +1389,7 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) {
    }
    return true;
  }
}

/*******************************************************************************
 *
@@ -1387,11 +1401,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;
@@ -1400,6 +1427,7 @@ void gatt_sr_reset_cback_cnt(tGATT_TCB& tcb, uint16_t cid) {
      }
    }
  }
}

/*******************************************************************************
 *
@@ -1483,6 +1511,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 {
@@ -1491,6 +1532,7 @@ void gatt_sr_update_cback_cnt(tGATT_TCB& tcb, uint16_t cid, tGATT_IF gatt_if, bo
      }
    }
  }
}

/*******************************************************************************
 *
@@ -1510,6 +1552,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 {
@@ -1518,6 +1572,7 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc, bool
      }
    }
  }
}

/** Cancel LE Create Connection request */
bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {