Loading system/stack/gatt/gatt_int.h +2 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading system/stack/gatt/gatt_sr.cc +16 −4 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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"); Loading system/stack/gatt/gatt_utils.cc +77 −22 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; Loading @@ -1365,6 +1374,7 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb) { } return true; } } /******************************************************************************* * Loading @@ -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; Loading @@ -1383,6 +1396,7 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) { } return true; } } /******************************************************************************* * Loading @@ -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; Loading @@ -1407,6 +1434,7 @@ void gatt_sr_reset_cback_cnt(tGATT_TCB& tcb, uint16_t cid) { } } } } /******************************************************************************* * Loading Loading @@ -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 { Loading @@ -1498,6 +1539,7 @@ void gatt_sr_update_cback_cnt(tGATT_TCB& tcb, uint16_t cid, tGATT_IF gatt_if, bo } } } } /******************************************************************************* * Loading @@ -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 { Loading @@ -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)) { Loading Loading
system/stack/gatt/gatt_int.h +2 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading
system/stack/gatt/gatt_sr.cc +16 −4 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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"); Loading
system/stack/gatt/gatt_utils.cc +77 −22 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; Loading @@ -1365,6 +1374,7 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb) { } return true; } } /******************************************************************************* * Loading @@ -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; Loading @@ -1383,6 +1396,7 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) { } return true; } } /******************************************************************************* * Loading @@ -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; Loading @@ -1407,6 +1434,7 @@ void gatt_sr_reset_cback_cnt(tGATT_TCB& tcb, uint16_t cid) { } } } } /******************************************************************************* * Loading Loading @@ -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 { Loading @@ -1498,6 +1539,7 @@ void gatt_sr_update_cback_cnt(tGATT_TCB& tcb, uint16_t cid, tGATT_IF gatt_if, bo } } } } /******************************************************************************* * Loading @@ -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 { Loading @@ -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)) { Loading