Loading system/bta/gatt/bta_gattc_act.cc +19 −4 Original line number Diff line number Diff line Loading @@ -224,13 +224,28 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) { continue; } if (bta_gattc_cb.bg_track[i].cif_mask & ((tBTA_GATTC_CIF_MASK)1 << (p_clreg->client_if - 1))) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { if (bta_gattc_cb.bg_track[i].cif_set.contains(p_clreg->client_if)) { bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) { log::warn("Unable to cancel GATT connection client_if:{} peer:{} is_direct:{}", log::warn( "Unable to cancel GATT connection client_if:{} peer:{} " "is_direct:{}", p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); } } } else { if (bta_gattc_cb.bg_track[i].cif_mask & ((tBTA_GATTC_CIF_MASK)1 << (p_clreg->client_if - 1))) { bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) { log::warn( "Unable to cancel GATT connection client_if:{} peer:{} " "is_direct:{}", p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); } } } } if (p_clreg->num_clcb == 0) { Loading system/bta/gatt/bta_gattc_int.h +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <cstdint> #include <deque> #include <unordered_set> #include "bta/gatt/database.h" #include "bta/gatt/database_builder.h" Loading Loading @@ -322,7 +323,7 @@ typedef struct { bool in_use; RawAddress remote_bda; tBTA_GATTC_CIF_MASK cif_mask; std::unordered_set<tGATT_IF> cif_set; } tBTA_GATTC_BG_TCK; typedef struct { Loading system/bta/gatt/bta_gattc_utils.cc +30 −11 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #define LOG_TAG "bt_bta_gattc" #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <cstdint> Loading Loading @@ -555,6 +556,23 @@ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda_ptr for (i = 0; i < ble_acceptlist_size(); i++, p_bg_tck++) { if (p_bg_tck->in_use && ((p_bg_tck->remote_bda == remote_bda_ptr) || (p_bg_tck->remote_bda.IsEmpty()))) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { auto& p_cif_set = p_bg_tck->cif_set; if (add) { /* mask on the cif bit */ p_cif_set.insert(client_if); } else { if (client_if != 0) { p_cif_set.erase(client_if); } else { p_cif_set.clear(); } } /* no BG connection for this device, make it available */ if (p_bg_tck->cif_set.empty()) { p_bg_tck->in_use = false; p_bg_tck->remote_bda = RawAddress::kEmpty; } } else { p_cif_mask = &p_bg_tck->cif_mask; if (add) { /* mask on the cif bit */ Loading @@ -570,6 +588,7 @@ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda_ptr if (p_bg_tck->cif_mask == 0) { memset(p_bg_tck, 0, sizeof(tBTA_GATTC_BG_TCK)); } } return true; } } Loading system/stack/gatt/gatt_api.cc +59 −1 Original line number Diff line number Diff line Loading @@ -72,6 +72,9 @@ tGATT_HDL_LIST_ELEM& gatt_add_an_item_to_list(uint16_t s_handle) { return *rit; } static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info, bool eatt_support); /***************************************************************************** * * GATT SERVER API Loading Loading @@ -1216,6 +1219,9 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout, tBT_TRAN ******************************************************************************/ tGATT_IF GATT_Register(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info, bool eatt_support) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { return GATT_Register_Dynamic(app_uuid128, name, p_cb_info, eatt_support); } tGATT_REG* p_reg; uint8_t i_gatt_if = 0; tGATT_IF gatt_if = 0; Loading Loading @@ -1252,6 +1258,54 @@ tGATT_IF GATT_Register(const Uuid& app_uuid128, const std::string& name, tGATT_C return 0; } static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info, bool eatt_support) { for (auto& [gatt_if, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->app_uuid128 == app_uuid128) { log::error("Application already registered, uuid={}", app_uuid128.ToString()); return 0; } } if (stack_config_get_interface()->get_pts_use_eatt_for_all_services()) { log::info("PTS: Force to use EATT for servers"); eatt_support = true; } if (gatt_cb.cl_rcb_map.size() >= GATT_CL_RCB_MAX) { log::error("Unable to register GATT client, MAX client reached: {}", gatt_cb.cl_rcb_map.size()); return 0; } uint8_t i_gatt_if = gatt_cb.next_gatt_if; for (int i = 0; i < GATT_CL_RCB_MAX; i++) { if (gatt_cb.cl_rcb_map.find(static_cast<tGATT_IF>(i_gatt_if)) == gatt_cb.cl_rcb_map.end()) { gatt_cb.cl_rcb_map.emplace(i_gatt_if, std::make_unique<tGATT_REG>()); tGATT_REG* p_reg = gatt_cb.cl_rcb_map[i_gatt_if].get(); p_reg->app_uuid128 = app_uuid128; p_reg->gatt_if = (tGATT_IF)i_gatt_if; p_reg->app_cb = *p_cb_info; p_reg->in_use = true; p_reg->eatt_support = eatt_support; p_reg->name = name; log::info("Allocated name:{} uuid:{} gatt_if:{} eatt_support:{}", name, app_uuid128.ToString(), p_reg->gatt_if, eatt_support); gatt_cb.next_gatt_if = (tGATT_IF)(i_gatt_if + 1); if (gatt_cb.next_gatt_if == 0) { gatt_cb.next_gatt_if = 1; } } i_gatt_if++; if (i_gatt_if == 0) { i_gatt_if = 1; } } log::error("Unable to register GATT client, MAX client reached: {}", gatt_cb.cl_rcb_map.size()); return 0; } /******************************************************************************* * * Function GATT_Deregister Loading Loading @@ -1319,8 +1373,12 @@ void GATT_Deregister(tGATT_IF gatt_if) { connection_manager::on_app_deregistered(gatt_if); } if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { gatt_cb.cl_rcb_map.erase(gatt_if); } else { *p_reg = {}; } } /******************************************************************************* * Loading system/stack/gatt/gatt_auth.cc +12 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ ******************************************************************************/ #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <string.h> #include "gatt_api.h" Loading Loading @@ -214,11 +215,19 @@ void gatt_notify_enc_cmpl(const RawAddress& bd_addr) { return; } if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_rcb] : gatt_cb.cl_rcb_map) { if (p_rcb->app_cb.p_enc_cmpl_cb) { (*p_rcb->app_cb.p_enc_cmpl_cb)(p_rcb->gatt_if, bd_addr); } } } else { for (uint8_t i = 0; i < GATT_MAX_APPS; i++) { if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) { (*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr); } } } if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) { gatt_set_sec_act(p_tcb, GATT_SEC_NONE); Loading Loading
system/bta/gatt/bta_gattc_act.cc +19 −4 Original line number Diff line number Diff line Loading @@ -224,13 +224,28 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) { continue; } if (bta_gattc_cb.bg_track[i].cif_mask & ((tBTA_GATTC_CIF_MASK)1 << (p_clreg->client_if - 1))) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { if (bta_gattc_cb.bg_track[i].cif_set.contains(p_clreg->client_if)) { bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) { log::warn("Unable to cancel GATT connection client_if:{} peer:{} is_direct:{}", log::warn( "Unable to cancel GATT connection client_if:{} peer:{} " "is_direct:{}", p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); } } } else { if (bta_gattc_cb.bg_track[i].cif_mask & ((tBTA_GATTC_CIF_MASK)1 << (p_clreg->client_if - 1))) { bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) { log::warn( "Unable to cancel GATT connection client_if:{} peer:{} " "is_direct:{}", p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false); } } } } if (p_clreg->num_clcb == 0) { Loading
system/bta/gatt/bta_gattc_int.h +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <cstdint> #include <deque> #include <unordered_set> #include "bta/gatt/database.h" #include "bta/gatt/database_builder.h" Loading Loading @@ -322,7 +323,7 @@ typedef struct { bool in_use; RawAddress remote_bda; tBTA_GATTC_CIF_MASK cif_mask; std::unordered_set<tGATT_IF> cif_set; } tBTA_GATTC_BG_TCK; typedef struct { Loading
system/bta/gatt/bta_gattc_utils.cc +30 −11 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #define LOG_TAG "bt_bta_gattc" #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <cstdint> Loading Loading @@ -555,6 +556,23 @@ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda_ptr for (i = 0; i < ble_acceptlist_size(); i++, p_bg_tck++) { if (p_bg_tck->in_use && ((p_bg_tck->remote_bda == remote_bda_ptr) || (p_bg_tck->remote_bda.IsEmpty()))) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { auto& p_cif_set = p_bg_tck->cif_set; if (add) { /* mask on the cif bit */ p_cif_set.insert(client_if); } else { if (client_if != 0) { p_cif_set.erase(client_if); } else { p_cif_set.clear(); } } /* no BG connection for this device, make it available */ if (p_bg_tck->cif_set.empty()) { p_bg_tck->in_use = false; p_bg_tck->remote_bda = RawAddress::kEmpty; } } else { p_cif_mask = &p_bg_tck->cif_mask; if (add) { /* mask on the cif bit */ Loading @@ -570,6 +588,7 @@ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda_ptr if (p_bg_tck->cif_mask == 0) { memset(p_bg_tck, 0, sizeof(tBTA_GATTC_BG_TCK)); } } return true; } } Loading
system/stack/gatt/gatt_api.cc +59 −1 Original line number Diff line number Diff line Loading @@ -72,6 +72,9 @@ tGATT_HDL_LIST_ELEM& gatt_add_an_item_to_list(uint16_t s_handle) { return *rit; } static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info, bool eatt_support); /***************************************************************************** * * GATT SERVER API Loading Loading @@ -1216,6 +1219,9 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout, tBT_TRAN ******************************************************************************/ tGATT_IF GATT_Register(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info, bool eatt_support) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { return GATT_Register_Dynamic(app_uuid128, name, p_cb_info, eatt_support); } tGATT_REG* p_reg; uint8_t i_gatt_if = 0; tGATT_IF gatt_if = 0; Loading Loading @@ -1252,6 +1258,54 @@ tGATT_IF GATT_Register(const Uuid& app_uuid128, const std::string& name, tGATT_C return 0; } static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info, bool eatt_support) { for (auto& [gatt_if, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->app_uuid128 == app_uuid128) { log::error("Application already registered, uuid={}", app_uuid128.ToString()); return 0; } } if (stack_config_get_interface()->get_pts_use_eatt_for_all_services()) { log::info("PTS: Force to use EATT for servers"); eatt_support = true; } if (gatt_cb.cl_rcb_map.size() >= GATT_CL_RCB_MAX) { log::error("Unable to register GATT client, MAX client reached: {}", gatt_cb.cl_rcb_map.size()); return 0; } uint8_t i_gatt_if = gatt_cb.next_gatt_if; for (int i = 0; i < GATT_CL_RCB_MAX; i++) { if (gatt_cb.cl_rcb_map.find(static_cast<tGATT_IF>(i_gatt_if)) == gatt_cb.cl_rcb_map.end()) { gatt_cb.cl_rcb_map.emplace(i_gatt_if, std::make_unique<tGATT_REG>()); tGATT_REG* p_reg = gatt_cb.cl_rcb_map[i_gatt_if].get(); p_reg->app_uuid128 = app_uuid128; p_reg->gatt_if = (tGATT_IF)i_gatt_if; p_reg->app_cb = *p_cb_info; p_reg->in_use = true; p_reg->eatt_support = eatt_support; p_reg->name = name; log::info("Allocated name:{} uuid:{} gatt_if:{} eatt_support:{}", name, app_uuid128.ToString(), p_reg->gatt_if, eatt_support); gatt_cb.next_gatt_if = (tGATT_IF)(i_gatt_if + 1); if (gatt_cb.next_gatt_if == 0) { gatt_cb.next_gatt_if = 1; } } i_gatt_if++; if (i_gatt_if == 0) { i_gatt_if = 1; } } log::error("Unable to register GATT client, MAX client reached: {}", gatt_cb.cl_rcb_map.size()); return 0; } /******************************************************************************* * * Function GATT_Deregister Loading Loading @@ -1319,8 +1373,12 @@ void GATT_Deregister(tGATT_IF gatt_if) { connection_manager::on_app_deregistered(gatt_if); } if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { gatt_cb.cl_rcb_map.erase(gatt_if); } else { *p_reg = {}; } } /******************************************************************************* * Loading
system/stack/gatt/gatt_auth.cc +12 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ ******************************************************************************/ #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <string.h> #include "gatt_api.h" Loading Loading @@ -214,11 +215,19 @@ void gatt_notify_enc_cmpl(const RawAddress& bd_addr) { return; } if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_rcb] : gatt_cb.cl_rcb_map) { if (p_rcb->app_cb.p_enc_cmpl_cb) { (*p_rcb->app_cb.p_enc_cmpl_cb)(p_rcb->gatt_if, bd_addr); } } } else { for (uint8_t i = 0; i < GATT_MAX_APPS; i++) { if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) { (*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr); } } } if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) { gatt_set_sec_act(p_tcb, GATT_SEC_NONE); Loading