diff options
| author | 2024-08-14 10:22:26 +0000 | |
|---|---|---|
| committer | 2024-09-12 07:15:35 +0000 | |
| commit | 747064ec31e2603d087294231940727233b10ee7 (patch) | |
| tree | 37d27925f9ab033b807328189a1422bb1e158c1e | |
| parent | 9bea7d83ea9fb05ac42b402ef68b5942f4d4b279 (diff) | |
Define tCONN_ID for GATT Connection ID
Introduce tCONN_ID as a type for
GATT connection IDs used internally
by the native stack.
Althogh this change itself doesn't do anything,
this is a preparatory step for expanding
tGATT_IF to uint16_t and tCONN_ID to uint32_t.
Rust stack cleanup will follow in a subsequent CL.
Flag: EXEMPT, mechanical refactor
Bug: 273561907
Test: atest BluetoothInstrumentationTests
Change-Id: I307fbb0815f3f3c31c80e75c12c4223237099adc
51 files changed, 685 insertions, 655 deletions
diff --git a/system/bta/csis/csis_client.cc b/system/bta/csis/csis_client.cc index ea616f605a..d873b2f66f 100644 --- a/system/bta/csis/csis_client.cc +++ b/system/bta/csis/csis_client.cc @@ -336,7 +336,7 @@ public: NotifyGroupStatus(group_id, false, status, std::move(cb)); } - void OnGattCsisWriteLockRsp(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, void* data) { + void OnGattCsisWriteLockRsp(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, void* data) { auto device = FindDeviceByConnId(conn_id); if (device == nullptr) { log::error("Device not there for conn_id: 0x{:04x}", conn_id); @@ -433,7 +433,7 @@ public: BtaGattQueue::WriteCharacteristic( device->conn_id, csis_instance->svc_data.lock_handle.val_hdl, value, GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (instance) { instance->OnGattCsisWriteLockRsp(conn_id, status, handle, data); @@ -758,7 +758,7 @@ public: } private: - std::shared_ptr<CsisDevice> FindDeviceByConnId(uint16_t conn_id) { + std::shared_ptr<CsisDevice> FindDeviceByConnId(tCONN_ID conn_id) { auto it = find_if(devices_.begin(), devices_.end(), CsisDevice::MatchConnId(conn_id)); if (it != devices_.end()) { return *it; @@ -913,7 +913,7 @@ private: } } - void OnGattWriteCcc(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, void* user_data) { + void OnGattWriteCcc(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, void* user_data) { auto device = FindDeviceByConnId(conn_id); if (device == nullptr) { log::info("unknown conn_id= 0x{:04x}", conn_id); @@ -946,7 +946,7 @@ private: } } - void OnCsisNotification(uint16_t conn_id, uint16_t handle, uint16_t len, const uint8_t* value) { + void OnCsisNotification(tCONN_ID conn_id, uint16_t handle, uint16_t len, const uint8_t* value) { auto device = FindDeviceByConnId(conn_id); if (device == nullptr) { log::warn("Skipping unknown device, conn_id= 0x{:04x}", conn_id); @@ -1044,7 +1044,7 @@ private: } } - void OnCsisSizeValueUpdate(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnCsisSizeValueUpdate(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, bool notify_valid_services = false) { auto device = FindDeviceByConnId(conn_id); @@ -1092,7 +1092,7 @@ private: } } - void OnCsisLockReadRsp(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnCsisLockReadRsp(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, bool notify_valid_services = false) { auto device = FindDeviceByConnId(conn_id); if (device == nullptr) { @@ -1132,7 +1132,7 @@ private: } } - void OnCsisRankReadRsp(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnCsisRankReadRsp(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, bool notify_valid_services) { auto device = FindDeviceByConnId(conn_id); if (device == nullptr) { @@ -1511,7 +1511,7 @@ private: }); } - void OnCsisSirkValueUpdate(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnCsisSirkValueUpdate(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, bool notify_valid_services = true) { auto device = FindDeviceByConnId(conn_id); if (device == nullptr) { @@ -1760,7 +1760,7 @@ private: /* Read SIRK */ BtaGattQueue::ReadCharacteristic( device->conn_id, csis_inst->svc_data.sirk_handle.val_hdl, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* user_data) { if (instance) { instance->OnCsisSirkValueUpdate(conn_id, status, handle, len, value, @@ -1773,7 +1773,7 @@ private: if (csis_inst->svc_data.lock_handle.val_hdl != GAP_INVALID_HANDLE) { BtaGattQueue::ReadCharacteristic( device->conn_id, csis_inst->svc_data.lock_handle.val_hdl, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* user_data) { if (instance) { instance->OnCsisLockReadRsp(conn_id, status, handle, len, value, (bool)user_data); @@ -1786,7 +1786,7 @@ private: if (csis_inst->svc_data.size_handle.val_hdl != GAP_INVALID_HANDLE) { BtaGattQueue::ReadCharacteristic( device->conn_id, csis_inst->svc_data.size_handle.val_hdl, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* user_data) { if (instance) { instance->OnCsisSizeValueUpdate(conn_id, status, handle, len, value, @@ -1800,7 +1800,7 @@ private: if (csis_inst->svc_data.rank_handle != GAP_INVALID_HANDLE) { BtaGattQueue::ReadCharacteristic( device->conn_id, csis_inst->svc_data.rank_handle, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* user_data) { if (instance) { instance->OnCsisRankReadRsp(conn_id, status, handle, len, value, (bool)user_data); @@ -2110,7 +2110,7 @@ private: } } - static uint16_t FindCccHandle(uint16_t conn_id, uint16_t char_handle) { + static uint16_t FindCccHandle(tCONN_ID conn_id, uint16_t char_handle) { const gatt::Characteristic* p_char = BTA_GATTC_GetCharacteristic(conn_id, char_handle); if (!p_char) { log::warn("No such characteristic: 0x{:04x}", char_handle); @@ -2126,7 +2126,7 @@ private: return GAP_INVALID_HANDLE; } - void SubscribeForNotifications(uint16_t conn_id, const RawAddress& address, uint16_t value_handle, + void SubscribeForNotifications(tCONN_ID conn_id, const RawAddress& address, uint16_t value_handle, uint16_t ccc_handle) { if (value_handle != GAP_INVALID_HANDLE) { tGATT_STATUS register_status = @@ -2144,7 +2144,7 @@ private: UINT16_TO_STREAM(value_ptr, GATT_CHAR_CLIENT_CONFIG_NOTIFICATION); BtaGattQueue::WriteDescriptor( conn_id, ccc_handle, std::move(value), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data) { if (instance) { instance->OnGattWriteCcc(conn_id, status, handle, user_data); @@ -2153,7 +2153,7 @@ private: nullptr); } - void DisableGattNotification(uint16_t conn_id, const RawAddress& address, uint16_t value_handle) { + void DisableGattNotification(tCONN_ID conn_id, const RawAddress& address, uint16_t value_handle) { if (value_handle != GAP_INVALID_HANDLE) { tGATT_STATUS register_status = BTA_GATTC_DeregisterForNotifications(gatt_if_, address, value_handle); diff --git a/system/bta/csis/csis_types.h b/system/bta/csis/csis_types.h index 809b9b0d2a..22dcc00bd2 100644 --- a/system/bta/csis/csis_types.h +++ b/system/bta/csis/csis_types.h @@ -91,7 +91,7 @@ public: */ bool connecting_actively = false; - uint16_t conn_id = GATT_INVALID_CONN_ID; + tCONN_ID conn_id = GATT_INVALID_CONN_ID; uint16_t service_handle = GAP_INVALID_HANDLE; bool is_gatt_service_valid = false; @@ -114,10 +114,10 @@ public: class MatchConnId { private: - uint16_t conn_id; + tCONN_ID conn_id; public: - MatchConnId(uint16_t conn_id) : conn_id(conn_id) {} + MatchConnId(tCONN_ID conn_id) : conn_id(conn_id) {} bool operator()(const std::shared_ptr<GattServiceDevice>& other) const { return conn_id == other->conn_id; } diff --git a/system/bta/dm/bta_dm_disc.cc b/system/bta/dm/bta_dm_disc.cc index c84c0f4388..ae33b0059e 100644 --- a/system/bta/dm/bta_dm_disc.cc +++ b/system/bta/dm/bta_dm_disc.cc @@ -91,7 +91,7 @@ static void post_disc_evt(tBTA_DM_DISC_EVT event, std::unique_ptr<tBTA_DM_MSG> m } } -static void bta_dm_gatt_disc_complete(uint16_t conn_id, tGATT_STATUS status); +static void bta_dm_gatt_disc_complete(tCONN_ID conn_id, tGATT_STATUS status); static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data); static void bta_dm_execute_queued_discovery_request(); static void bta_dm_close_gatt_conn(); @@ -101,12 +101,12 @@ namespace { struct gatt_interface_t { void (*BTA_GATTC_CancelOpen)(tGATT_IF client_if, const RawAddress& remote_bda, bool is_direct); void (*BTA_GATTC_Refresh)(const RawAddress& remote_bda); - void (*BTA_GATTC_GetGattDb)(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, + void (*BTA_GATTC_GetGattDb)(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count); void (*BTA_GATTC_AppRegister)(tBTA_GATTC_CBACK* p_client_cb, BtaAppRegisterCallback cb, bool eatt_support); - void (*BTA_GATTC_Close)(uint16_t conn_id); - void (*BTA_GATTC_ServiceSearchRequest)(uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid); + void (*BTA_GATTC_Close)(tCONN_ID conn_id); + void (*BTA_GATTC_ServiceSearchRequest)(tCONN_ID conn_id, const bluetooth::Uuid* p_srvc_uuid); void (*BTA_GATTC_Open)(tGATT_IF client_if, const RawAddress& remote_bda, tBTM_BLE_CONN_TYPE connection_type, bool opportunistic); } default_gatt_interface = { @@ -116,7 +116,7 @@ struct gatt_interface_t { }, .BTA_GATTC_Refresh = [](const RawAddress& remote_bda) { BTA_GATTC_Refresh(remote_bda); }, .BTA_GATTC_GetGattDb = - [](uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, + [](tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count) { BTA_GATTC_GetGattDb(conn_id, start_handle, end_handle, db, count); }, @@ -124,9 +124,9 @@ struct gatt_interface_t { [](tBTA_GATTC_CBACK* p_client_cb, BtaAppRegisterCallback cb, bool eatt_support) { BTA_GATTC_AppRegister(p_client_cb, cb, eatt_support); }, - .BTA_GATTC_Close = [](uint16_t conn_id) { BTA_GATTC_Close(conn_id); }, + .BTA_GATTC_Close = [](tCONN_ID conn_id) { BTA_GATTC_Close(conn_id); }, .BTA_GATTC_ServiceSearchRequest = - [](uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid) { + [](tCONN_ID conn_id, const bluetooth::Uuid* p_srvc_uuid) { if (p_srvc_uuid) { BTA_GATTC_ServiceSearchRequest(conn_id, *p_srvc_uuid); } else { @@ -162,7 +162,7 @@ void bta_dm_disc_remove_device(const RawAddress& bd_addr) { if (bta_dm_discovery_cb.service_discovery_state == BTA_DM_DISCOVER_ACTIVE && bta_dm_discovery_cb.peer_bdaddr == bd_addr) { log::info("Device removed while service discovery was pending, conclude the service discovery"); - bta_dm_gatt_disc_complete((uint16_t)GATT_INVALID_CONN_ID, (tGATT_STATUS)GATT_ERROR); + bta_dm_gatt_disc_complete(GATT_INVALID_CONN_ID, (tGATT_STATUS)GATT_ERROR); } } @@ -491,7 +491,7 @@ void bta_dm_gatt_finished(RawAddress bda, tBTA_STATUS result, * Parameters: * ******************************************************************************/ -static void bta_dm_gatt_disc_complete(uint16_t conn_id, tGATT_STATUS status) { +static void bta_dm_gatt_disc_complete(tCONN_ID conn_id, tGATT_STATUS status) { bool sdp_pending = bta_dm_discovery_cb.transports & BT_TRANSPORT_BR_EDR; bool le_pending = bta_dm_discovery_cb.transports & BT_TRANSPORT_LE; @@ -672,7 +672,7 @@ static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { if (bta_dm_discovery_get_state() == BTA_DM_DISCOVER_ACTIVE) { /* in case of disconnect before search is completed */ if (p_data->close.remote_bda == bta_dm_discovery_cb.peer_bdaddr) { - bta_dm_gatt_disc_complete((uint16_t)GATT_INVALID_CONN_ID, (tGATT_STATUS)GATT_ERROR); + bta_dm_gatt_disc_complete(GATT_INVALID_CONN_ID, (tGATT_STATUS)GATT_ERROR); } } break; diff --git a/system/bta/dm/bta_dm_disc_int.h b/system/bta/dm/bta_dm_disc_int.h index 3b948da5e2..df8d2f2444 100644 --- a/system/bta/dm/bta_dm_disc_int.h +++ b/system/bta/dm/bta_dm_disc_int.h @@ -106,7 +106,7 @@ typedef struct { tBTA_DM_SERVICE_DISCOVERY_STATE service_discovery_state; std::unique_ptr<tBTA_DM_SDP_STATE> sdp_state; - uint16_t conn_id; + tCONN_ID conn_id; alarm_t* gatt_close_timer; /* GATT channel close delay timer */ RawAddress pending_close_bda; /* pending GATT channel remote device address */ } tBTA_DM_SERVICE_DISCOVERY_CB; diff --git a/system/bta/dm/bta_dm_gatt_client.cc b/system/bta/dm/bta_dm_gatt_client.cc index 1de70b5fa1..54ce8d7f28 100644 --- a/system/bta/dm/bta_dm_gatt_client.cc +++ b/system/bta/dm/bta_dm_gatt_client.cc @@ -60,11 +60,11 @@ gatt_interface_t default_gatt_interface = { BTA_GATTC_Refresh(remote_bda); }, .BTA_GATTC_GetGattDb = - [](uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, + [](tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count) { - gatt_history_.Push( - base::StringPrintf("%-32s conn_id:%hu start_handle:%hu end:handle:%hu", - "GATTC_GetGattDb", conn_id, start_handle, end_handle)); + gatt_history_.Push(base::StringPrintf( + "%-32s conn_id:%hu start_handle:%hu end:handle:%hu", "GATTC_GetGattDb", + static_cast<uint16_t>(conn_id), start_handle, end_handle)); BTA_GATTC_GetGattDb(conn_id, start_handle, end_handle, db, count); }, .BTA_GATTC_AppRegister = @@ -75,15 +75,16 @@ gatt_interface_t default_gatt_interface = { BTA_GATTC_AppRegister(p_client_cb, cb, eatt_support); }, .BTA_GATTC_Close = - [](uint16_t conn_id) { - gatt_history_.Push( - base::StringPrintf("%-32s conn_id:%hu", "GATTC_Close", conn_id)); + [](tCONN_ID conn_id) { + gatt_history_.Push(base::StringPrintf("%-32s conn_id:%hu", "GATTC_Close", + static_cast<uint16_t>(conn_id))); BTA_GATTC_Close(conn_id); }, .BTA_GATTC_ServiceSearchRequest = - [](uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid) { + [](tCONN_ID conn_id, const bluetooth::Uuid* p_srvc_uuid) { gatt_history_.Push(base::StringPrintf("%-32s conn_id:%hu", - "GATTC_ServiceSearchRequest", conn_id)); + "GATTC_ServiceSearchRequest", + static_cast<uint16_t>(conn_id))); if (p_srvc_uuid) { BTA_GATTC_ServiceSearchRequest(conn_id, *p_srvc_uuid); } else { diff --git a/system/bta/dm/bta_dm_gatt_client.h b/system/bta/dm/bta_dm_gatt_client.h index 6cb764a3e0..b0071fd000 100644 --- a/system/bta/dm/bta_dm_gatt_client.h +++ b/system/bta/dm/bta_dm_gatt_client.h @@ -30,12 +30,12 @@ struct gatt_interface_t { void (*BTA_GATTC_CancelOpen)(tGATT_IF client_if, const RawAddress& remote_bda, bool is_direct); void (*BTA_GATTC_Refresh)(const RawAddress& remote_bda); - void (*BTA_GATTC_GetGattDb)(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, + void (*BTA_GATTC_GetGattDb)(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count); void (*BTA_GATTC_AppRegister)(tBTA_GATTC_CBACK* p_client_cb, BtaAppRegisterCallback cb, bool eatt_support); - void (*BTA_GATTC_Close)(uint16_t conn_id); - void (*BTA_GATTC_ServiceSearchRequest)(uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid); + void (*BTA_GATTC_Close)(tCONN_ID conn_id); + void (*BTA_GATTC_ServiceSearchRequest)(tCONN_ID conn_id, const bluetooth::Uuid* p_srvc_uuid); void (*BTA_GATTC_Open)(tGATT_IF client_if, const RawAddress& remote_bda, tBTM_BLE_CONN_TYPE connection_type, bool opportunistic); }; diff --git a/system/bta/gatt/bta_gattc_act.cc b/system/bta/gatt/bta_gattc_act.cc index fbaadb0bf8..ef1df7c113 100644 --- a/system/bta/gatt/bta_gattc_act.cc +++ b/system/bta/gatt/bta_gattc_act.cc @@ -53,20 +53,20 @@ using namespace bluetooth; /***************************************************************************** * Constants ****************************************************************************/ -static void bta_gattc_conn_cback(tGATT_IF gattc_if, const RawAddress& bda, uint16_t conn_id, +static void bta_gattc_conn_cback(tGATT_IF gattc_if, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); -static void bta_gattc_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +static void bta_gattc_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB* p_clreg); static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, const RawAddress& bda); -static void bta_gattc_cong_cback(uint16_t conn_id, bool congested); -static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint8_t tx_phy, +static void bta_gattc_cong_cback(tCONN_ID conn_id, bool congested); +static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status); -static void bta_gattc_conn_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t interval, +static void bta_gattc_conn_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t interval, uint16_t latency, uint16_t timeout, tGATT_STATUS status); -static void bta_gattc_subrate_chg_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t subrate_factor, +static void bta_gattc_subrate_chg_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t subrate_factor, uint16_t latency, uint16_t cont_num, uint16_t timeout, tGATT_STATUS status); static void bta_gattc_init_bk_conn(const tBTA_GATTC_API_OPEN* p_data, tBTA_GATTC_RCB* p_clreg); @@ -303,7 +303,7 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) { .hdr = { .event = BTA_GATTC_API_CLOSE_EVT, - .layer_specific = p_clcb->bta_conn_id, + .layer_specific = static_cast<uint16_t>(p_clcb->bta_conn_id), }, }; bta_gattc_close(p_clcb.get(), &gattc_data); @@ -318,7 +318,7 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) { BT_HDR_RIGID buf; buf.event = BTA_GATTC_API_CLOSE_EVT; - buf.layer_specific = bta_gattc_cb.clcb[i].bta_conn_id; + buf.layer_specific = static_cast<uint16_t>(bta_gattc_cb.clcb[i].bta_conn_id); bta_gattc_close(&bta_gattc_cb.clcb[i], (tBTA_GATTC_DATA*)&buf); } } @@ -462,7 +462,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) { /* a connected remote device */ if (GATT_GetConnIdIfConnected(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, &p_clcb->bta_conn_id, p_data->api_conn.transport)) { - gattc_data.int_conn.hdr.layer_specific = p_clcb->bta_conn_id; + gattc_data.int_conn.hdr.layer_specific = static_cast<uint16_t>(p_clcb->bta_conn_id); bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, &gattc_data); } @@ -487,7 +487,7 @@ static void bta_gattc_init_bk_conn(const tBTA_GATTC_API_OPEN* p_data, tBTA_GATTC return; } - uint16_t conn_id; + tCONN_ID conn_id; if (!GATT_GetConnIdIfConnected(p_data->client_if, p_data->remote_bda, &conn_id, p_data->transport)) { log::info("Not a connected remote device yet"); @@ -505,7 +505,7 @@ static void bta_gattc_init_bk_conn(const tBTA_GATTC_API_OPEN* p_data, tBTA_GATTC tBTA_GATTC_DATA gattc_data = { .hdr = { - .layer_specific = conn_id, + .layer_specific = static_cast<uint16_t>(conn_id), }, }; @@ -567,10 +567,9 @@ void bta_gattc_conn(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) { if (p_data != NULL) { log::verbose("conn_id=0x{:x}", p_data->hdr.layer_specific); - p_clcb->bta_conn_id = p_data->int_conn.hdr.layer_specific; + p_clcb->bta_conn_id = static_cast<tCONN_ID>(p_data->int_conn.hdr.layer_specific); - if (!GATT_GetConnectionInfor(p_data->hdr.layer_specific, &gatt_if, p_clcb->bda, - &p_clcb->transport)) { + if (!GATT_GetConnectionInfor(p_clcb->bta_conn_id, &gatt_if, p_clcb->bda, &p_clcb->transport)) { log::warn("Unable to get GATT connection information peer:{}", p_clcb->bda); } } @@ -664,7 +663,7 @@ void bta_gattc_close_fail(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data if (p_clcb->p_rcb->p_cback) { memset(&cb_data, 0, sizeof(tBTA_GATTC)); cb_data.close.client_if = p_clcb->p_rcb->client_if; - cb_data.close.conn_id = p_data->hdr.layer_specific; + cb_data.close.conn_id = static_cast<tCONN_ID>(p_data->hdr.layer_specific); cb_data.close.remote_bda = p_clcb->bda; cb_data.close.reason = BTA_GATT_CONN_NONE; cb_data.close.status = GATT_ERROR; @@ -716,7 +715,7 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) { bta_gattc_clcb_dealloc(p_clcb); if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) { - cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific); + cb_data.close.status = GATT_Disconnect(static_cast<tCONN_ID>(p_data->hdr.layer_specific)); cb_data.close.reason = GATT_CONN_TERMINATE_LOCAL_HOST; log::debug("Local close event client_if:{} conn_id:{} reason:{}", cb_data.close.client_if, cb_data.close.conn_id, @@ -946,7 +945,7 @@ void bta_gattc_continue_discovery_if_needed(const RawAddress& bd_addr, uint16_t return; } - uint16_t conn_id = p_srcb->blocked_conn_id; + tCONN_ID conn_id = p_srcb->blocked_conn_id; p_srcb->disc_blocked_waiting_on_version = false; p_srcb->blocked_conn_id = 0; @@ -1176,8 +1175,8 @@ void bta_gattc_execute(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) { /** send handle value confirmation */ void bta_gattc_confirm(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) { uint16_t cid = p_data->api_confirm.cid; - - if (GATTC_SendHandleValueConfirm(p_data->api_confirm.hdr.layer_specific, cid) != GATT_SUCCESS) { + auto conn_id = static_cast<tCONN_ID>(p_data->api_confirm.hdr.layer_specific); + if (GATTC_SendHandleValueConfirm(conn_id, cid) != GATT_SUCCESS) { log::error("to cid=0x{:x} failed", cid); } else { /* if over BR_EDR, inform PM for mode change */ @@ -1451,7 +1450,7 @@ static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB* p_clreg) { } /** callback functions to GATT client stack */ -static void bta_gattc_conn_cback(tGATT_IF gattc_if, const RawAddress& bdaddr, uint16_t conn_id, +static void bta_gattc_conn_cback(tGATT_IF gattc_if, const RawAddress& bdaddr, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport) { if (connected) { @@ -1466,7 +1465,7 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, const RawAddress& bdaddr, ui tBTA_GATTC_DATA* p_buf = (tBTA_GATTC_DATA*)osi_calloc(sizeof(tBTA_GATTC_DATA)); p_buf->int_conn.hdr.event = connected ? BTA_GATTC_INT_CONN_EVT : BTA_GATTC_INT_DISCONN_EVT; - p_buf->int_conn.hdr.layer_specific = conn_id; + p_buf->int_conn.hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->int_conn.client_if = gattc_if; p_buf->int_conn.role = bluetooth::stack::l2cap::get_interface().L2CA_GetBleConnRole(bdaddr); p_buf->int_conn.reason = reason; @@ -1528,7 +1527,7 @@ void bta_gattc_process_api_refresh(const RawAddress& remote_bda) { } /** process service change indication */ -static bool bta_gattc_process_srvc_chg_ind(uint16_t conn_id, tBTA_GATTC_RCB* p_clrcb, +static bool bta_gattc_process_srvc_chg_ind(tCONN_ID conn_id, tBTA_GATTC_RCB* p_clrcb, tBTA_GATTC_SERV* p_srcb, tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_NOTIFY* p_notify, tGATT_VALUE* att_value) { Uuid gattp_uuid = Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER); @@ -1635,7 +1634,7 @@ static void bta_gattc_proc_other_indication(tBTA_GATTC_CLCB* p_clcb, uint8_t op, } /** process indication/notification */ -static void bta_gattc_process_indicate(uint16_t conn_id, tGATTC_OPTYPE op, +static void bta_gattc_process_indicate(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPLETE* p_data) { uint16_t handle = p_data->att_value.handle; tBTA_GATTC_NOTIFY notify; @@ -1721,7 +1720,7 @@ static void bta_gattc_process_indicate(uint16_t conn_id, tGATTC_OPTYPE op, } /** client operation complete callback register with BTE GATT */ -static void bta_gattc_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +static void bta_gattc_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { log::verbose("conn_id:{} op:{} status:{}", conn_id, op, status); @@ -1747,13 +1746,13 @@ static void bta_gattc_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATU } /** client operation complete send message */ -void bta_gattc_cmpl_sendmsg(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +void bta_gattc_cmpl_sendmsg(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { const size_t len = sizeof(tBTA_GATTC_OP_CMPL) + sizeof(tGATT_CL_COMPLETE); tBTA_GATTC_OP_CMPL* p_buf = (tBTA_GATTC_OP_CMPL*)osi_calloc(len); p_buf->hdr.event = BTA_GATTC_OP_CMPL_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->status = status; p_buf->op_code = op; @@ -1766,7 +1765,7 @@ void bta_gattc_cmpl_sendmsg(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS sta } /** congestion callback for BTA GATT client */ -static void bta_gattc_cong_cback(uint16_t conn_id, bool congested) { +static void bta_gattc_cong_cback(tCONN_ID conn_id, bool congested) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (!p_clcb || !p_clcb->p_rcb->p_cback) { return; @@ -1779,7 +1778,7 @@ static void bta_gattc_cong_cback(uint16_t conn_id, bool congested) { (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CONGEST_EVT, &cb_data); } -static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint8_t tx_phy, +static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status) { tBTA_GATTC_RCB* p_clreg = bta_gattc_cl_get_regcb(gatt_if); @@ -1797,7 +1796,7 @@ static void bta_gattc_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint8 (*p_clreg->p_cback)(BTA_GATTC_PHY_UPDATE_EVT, &cb_data); } -static void bta_gattc_conn_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t interval, +static void bta_gattc_conn_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t interval, uint16_t latency, uint16_t timeout, tGATT_STATUS status) { tBTA_GATTC_RCB* p_clreg = bta_gattc_cl_get_regcb(gatt_if); @@ -1815,7 +1814,7 @@ static void bta_gattc_conn_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint (*p_clreg->p_cback)(BTA_GATTC_CONN_UPDATE_EVT, &cb_data); } -static void bta_gattc_subrate_chg_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t subrate_factor, +static void bta_gattc_subrate_chg_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t subrate_factor, uint16_t latency, uint16_t cont_num, uint16_t timeout, tGATT_STATUS status) { tBTA_GATTC_RCB* p_clreg = bta_gattc_cl_get_regcb(gatt_if); diff --git a/system/bta/gatt/bta_gattc_api.cc b/system/bta/gatt/bta_gattc_api.cc index ea2c7f528e..2e41b2e23f 100644 --- a/system/bta/gatt/bta_gattc_api.cc +++ b/system/bta/gatt/bta_gattc_api.cc @@ -208,11 +208,11 @@ void BTA_GATTC_CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda, bool * Returns void * ******************************************************************************/ -void BTA_GATTC_Close(uint16_t conn_id) { +void BTA_GATTC_Close(tCONN_ID conn_id) { BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID)); p_buf->event = BTA_GATTC_API_CLOSE_EVT; - p_buf->layer_specific = conn_id; + p_buf->layer_specific = static_cast<uint16_t>(conn_id); bta_sys_sendmsg(p_buf); } @@ -231,17 +231,17 @@ void BTA_GATTC_Close(uint16_t conn_id) { * ******************************************************************************/ -void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) { +void BTA_GATTC_ConfigureMTU(tCONN_ID conn_id, uint16_t mtu) { BTA_GATTC_ConfigureMTU(conn_id, mtu, NULL, NULL); } -void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu, GATT_CONFIGURE_MTU_OP_CB callback, +void BTA_GATTC_ConfigureMTU(tCONN_ID conn_id, uint16_t mtu, GATT_CONFIGURE_MTU_OP_CB callback, void* cb_data) { tBTA_GATTC_API_CFG_MTU* p_buf = (tBTA_GATTC_API_CFG_MTU*)osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU)); p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->mtu = mtu; p_buf->mtu_cb = callback; p_buf->mtu_cb_data = cb_data; @@ -249,32 +249,32 @@ void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu, GATT_CONFIGURE_MTU_O bta_sys_sendmsg(p_buf); } -void BTA_GATTC_ServiceSearchAllRequest(uint16_t conn_id) { +void BTA_GATTC_ServiceSearchAllRequest(tCONN_ID conn_id) { const size_t len = sizeof(tBTA_GATTC_API_SEARCH); tBTA_GATTC_API_SEARCH* p_buf = (tBTA_GATTC_API_SEARCH*)osi_calloc(len); p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->p_srvc_uuid = NULL; bta_sys_sendmsg(p_buf); } -void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id, Uuid p_srvc_uuid) { +void BTA_GATTC_ServiceSearchRequest(tCONN_ID conn_id, Uuid p_srvc_uuid) { const size_t len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(Uuid); tBTA_GATTC_API_SEARCH* p_buf = (tBTA_GATTC_API_SEARCH*)osi_calloc(len); p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->p_srvc_uuid = (Uuid*)(p_buf + 1); *p_buf->p_srvc_uuid = p_srvc_uuid; bta_sys_sendmsg(p_buf); } -void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id, const Uuid& srvc_uuid) { +void BTA_GATTC_DiscoverServiceByUuid(tCONN_ID conn_id, const Uuid& srvc_uuid) { do_in_main_thread(base::BindOnce( - base::IgnoreResult<tGATT_STATUS (*)(uint16_t, tGATT_DISC_TYPE, uint16_t, uint16_t, + base::IgnoreResult<tGATT_STATUS (*)(tCONN_ID, tGATT_DISC_TYPE, uint16_t, uint16_t, const Uuid&)>(&GATTC_Discover), conn_id, GATT_DISC_SRVC_BY_UUID, 0x0001, 0xFFFF, srvc_uuid)); } @@ -291,7 +291,7 @@ void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id, const Uuid& srvc_uuid) { * Returns returns list of gatt::Service or NULL. * ******************************************************************************/ -const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id) { +const std::list<gatt::Service>* BTA_GATTC_GetServices(tCONN_ID conn_id) { return bta_gattc_get_services(conn_id); } @@ -308,7 +308,7 @@ const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id) { * Returns returns pointer to gatt::Characteristic or NULL. * ******************************************************************************/ -const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id, uint16_t handle) { +const gatt::Characteristic* BTA_GATTC_GetCharacteristic(tCONN_ID conn_id, uint16_t handle) { return bta_gattc_get_characteristic(conn_id, handle); } @@ -325,19 +325,19 @@ const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id, uint16 * Returns returns pointer to gatt::Descriptor or NULL. * ******************************************************************************/ -const gatt::Descriptor* BTA_GATTC_GetDescriptor(uint16_t conn_id, uint16_t handle) { +const gatt::Descriptor* BTA_GATTC_GetDescriptor(tCONN_ID conn_id, uint16_t handle) { return bta_gattc_get_descriptor(conn_id, handle); } /* Return characteristic that owns descriptor with handle equal to |handle|, or * NULL */ -const gatt::Characteristic* BTA_GATTC_GetOwningCharacteristic(uint16_t conn_id, uint16_t handle) { +const gatt::Characteristic* BTA_GATTC_GetOwningCharacteristic(tCONN_ID conn_id, uint16_t handle) { return bta_gattc_get_owning_characteristic(conn_id, handle); } /* Return service that owns descriptor or characteristic with handle equal to * |handle|, or NULL */ -const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id, uint16_t handle) { +const gatt::Service* BTA_GATTC_GetOwningService(tCONN_ID conn_id, uint16_t handle) { return bta_gattc_get_service_for_handle(conn_id, handle); } @@ -353,7 +353,7 @@ const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id, uint16_t handl * count: number of elements in database. * ******************************************************************************/ -void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, +void BTA_GATTC_GetGattDb(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count) { bta_gattc_get_gatt_db(conn_id, start_handle, end_handle, db, count); } @@ -370,12 +370,12 @@ void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle, uint16_t end_h * Returns None * ******************************************************************************/ -void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, +void BTA_GATTC_ReadCharacteristic(tCONN_ID conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback, void* cb_data) { tBTA_GATTC_API_READ* p_buf = (tBTA_GATTC_API_READ*)osi_calloc(sizeof(tBTA_GATTC_API_READ)); p_buf->hdr.event = BTA_GATTC_API_READ_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->is_multi_read = false; p_buf->auth_req = auth_req; p_buf->handle = handle; @@ -389,13 +389,13 @@ void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tGATT_AUTH_ * This function is called to read a value of characteristic with uuid equal to * |uuid| */ -void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, const Uuid& uuid, uint16_t s_handle, +void BTA_GATTC_ReadUsingCharUuid(tCONN_ID conn_id, const Uuid& uuid, uint16_t s_handle, uint16_t e_handle, tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback, void* cb_data) { tBTA_GATTC_API_READ* p_buf = (tBTA_GATTC_API_READ*)osi_calloc(sizeof(tBTA_GATTC_API_READ)); p_buf->hdr.event = BTA_GATTC_API_READ_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->is_multi_read = false; p_buf->auth_req = auth_req; p_buf->handle = 0; @@ -420,12 +420,12 @@ void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, const Uuid& uuid, uint16_t s_ * Returns None * ******************************************************************************/ -void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, +void BTA_GATTC_ReadCharDescr(tCONN_ID conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback, void* cb_data) { tBTA_GATTC_API_READ* p_buf = (tBTA_GATTC_API_READ*)osi_calloc(sizeof(tBTA_GATTC_API_READ)); p_buf->hdr.event = BTA_GATTC_API_READ_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->is_multi_read = false; p_buf->auth_req = auth_req; p_buf->handle = handle; @@ -451,14 +451,14 @@ void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle, tGATT_AUTH_REQ a * Returns None * ******************************************************************************/ -void BTA_GATTC_ReadMultiple(uint16_t conn_id, tBTA_GATTC_MULTI& handles, bool variable_len, +void BTA_GATTC_ReadMultiple(tCONN_ID conn_id, tBTA_GATTC_MULTI& handles, bool variable_len, tGATT_AUTH_REQ auth_req, GATT_READ_MULTI_OP_CB callback, void* cb_data) { tBTA_GATTC_API_READ_MULTI* p_buf = (tBTA_GATTC_API_READ_MULTI*)osi_calloc(sizeof(tBTA_GATTC_API_READ_MULTI)); p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->is_multi_read = true; p_buf->auth_req = auth_req; p_buf->handles = handles; @@ -482,14 +482,14 @@ void BTA_GATTC_ReadMultiple(uint16_t conn_id, tBTA_GATTC_MULTI& handles, bool va * Returns None * ******************************************************************************/ -void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle, tGATT_WRITE_TYPE write_type, +void BTA_GATTC_WriteCharValue(tCONN_ID conn_id, uint16_t handle, tGATT_WRITE_TYPE write_type, std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req, GATT_WRITE_OP_CB callback, void* cb_data) { tBTA_GATTC_API_WRITE* p_buf = (tBTA_GATTC_API_WRITE*)osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->auth_req = auth_req; p_buf->handle = handle; p_buf->write_type = write_type; @@ -518,13 +518,13 @@ void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle, tGATT_WRITE_TYP * Returns None * ******************************************************************************/ -void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, +void BTA_GATTC_WriteCharDescr(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req, GATT_WRITE_OP_CB callback, void* cb_data) { tBTA_GATTC_API_WRITE* p_buf = (tBTA_GATTC_API_WRITE*)osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->auth_req = auth_req; p_buf->handle = handle; p_buf->write_type = GATT_WRITE; @@ -555,14 +555,14 @@ void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle, std::vector<uin * Returns None * ******************************************************************************/ -void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle, uint16_t offset, +void BTA_GATTC_PrepareWrite(tCONN_ID conn_id, uint16_t handle, uint16_t offset, std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req, GATT_WRITE_OP_CB callback, void* cb_data) { tBTA_GATTC_API_WRITE* p_buf = (tBTA_GATTC_API_WRITE*)osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->auth_req = auth_req; p_buf->handle = handle; p_buf->write_cb = callback; @@ -593,11 +593,11 @@ void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle, uint16_t offset, * Returns None * ******************************************************************************/ -void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute) { +void BTA_GATTC_ExecuteWrite(tCONN_ID conn_id, bool is_execute) { tBTA_GATTC_API_EXEC* p_buf = (tBTA_GATTC_API_EXEC*)osi_calloc(sizeof(tBTA_GATTC_API_EXEC)); p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->is_execute = is_execute; bta_sys_sendmsg(p_buf); @@ -615,14 +615,14 @@ void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute) { * Returns None * ******************************************************************************/ -void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t cid) { +void BTA_GATTC_SendIndConfirm(tCONN_ID conn_id, uint16_t cid) { tBTA_GATTC_API_CONFIRM* p_buf = (tBTA_GATTC_API_CONFIRM*)osi_calloc(sizeof(tBTA_GATTC_API_CONFIRM)); log::verbose("conn_id={} cid=0x{:x}", conn_id, cid); p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT; - p_buf->hdr.layer_specific = conn_id; + p_buf->hdr.layer_specific = static_cast<uint16_t>(conn_id); p_buf->cid = cid; bta_sys_sendmsg(p_buf); diff --git a/system/bta/gatt/bta_gattc_cache.cc b/system/bta/gatt/bta_gattc_cache.cc index ba8cbebb20..0b9612577c 100644 --- a/system/bta/gatt/bta_gattc_cache.cc +++ b/system/bta/gatt/bta_gattc_cache.cc @@ -60,10 +60,10 @@ using gatt::Descriptor; using gatt::IncludedService; using gatt::Service; -static tGATT_STATUS bta_gattc_sdp_service_disc(uint16_t conn_id, tBTA_GATTC_SERV* p_server_cb); +static tGATT_STATUS bta_gattc_sdp_service_disc(tCONN_ID conn_id, tBTA_GATTC_SERV* p_server_cb); const Descriptor* bta_gattc_get_descriptor_srcb(tBTA_GATTC_SERV* p_srcb, uint16_t handle); const Characteristic* bta_gattc_get_characteristic_srcb(tBTA_GATTC_SERV* p_srcb, uint16_t handle); -static void bta_gattc_explore_srvc_finished(uint16_t conn_id, tBTA_GATTC_SERV* p_srvc_cb); +static void bta_gattc_explore_srvc_finished(tCONN_ID conn_id, tBTA_GATTC_SERV* p_srvc_cb); static void bta_gattc_read_db_hash_cmpl(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_OP_CMPL* p_data, bool is_svc_chg); @@ -82,7 +82,7 @@ static void bta_gattc_read_ext_prop_desc_cmpl(tBTA_GATTC_CLCB* p_clcb, typedef struct { tSDP_DISCOVERY_DB* p_sdp_db; - uint16_t sdp_conn_id; + tCONN_ID sdp_conn_id; } tBTA_GATTC_CB_DATA; #if (BTA_GATT_DEBUG == TRUE) @@ -199,7 +199,7 @@ RobustCachingSupport GetRobustCachingSupport(const tBTA_GATTC_CLCB* p_clcb, } /** Start primary service discovery */ -[[nodiscard]] tGATT_STATUS bta_gattc_discover_pri_service(uint16_t conn_id, +[[nodiscard]] tGATT_STATUS bta_gattc_discover_pri_service(tCONN_ID conn_id, tBTA_GATTC_SERV* p_server_cb, tGATT_DISC_TYPE disc_type) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); @@ -217,7 +217,7 @@ RobustCachingSupport GetRobustCachingSupport(const tBTA_GATTC_CLCB* p_clcb, /** start exploring next service, or finish discovery if no more services left */ -static void bta_gattc_explore_next_service(uint16_t conn_id, tBTA_GATTC_SERV* p_srvc_cb) { +static void bta_gattc_explore_next_service(tCONN_ID conn_id, tBTA_GATTC_SERV* p_srvc_cb) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (!p_clcb) { log::error("unknown conn_id=0x{:x}", conn_id); @@ -277,7 +277,7 @@ static void bta_gattc_explore_next_service(uint16_t conn_id, tBTA_GATTC_SERV* p_ bta_gattc_explore_srvc_finished(conn_id, p_srvc_cb); } -static void bta_gattc_explore_srvc_finished(uint16_t conn_id, tBTA_GATTC_SERV* p_srvc_cb) { +static void bta_gattc_explore_srvc_finished(tCONN_ID conn_id, tBTA_GATTC_SERV* p_srvc_cb) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (!p_clcb) { log::error("unknown conn_id=0x{:x}", conn_id); @@ -314,7 +314,7 @@ static void bta_gattc_explore_srvc_finished(uint16_t conn_id, tBTA_GATTC_SERV* p } /** Start discovery for characteristic descriptor */ -void bta_gattc_start_disc_char_dscp(uint16_t conn_id, tBTA_GATTC_SERV* p_srvc_cb) { +void bta_gattc_start_disc_char_dscp(tCONN_ID conn_id, tBTA_GATTC_SERV* p_srvc_cb) { log::verbose("starting discover characteristics descriptor"); std::pair<uint16_t, uint16_t> range = p_srvc_cb->pending_discovery.NextDescriptorRangeToExplore(); @@ -403,7 +403,7 @@ void bta_gattc_sdp_callback(tBTA_GATTC_CB_DATA* cb_data, const RawAddress& /* bd } /* Start DSP Service Discovery */ -static tGATT_STATUS bta_gattc_sdp_service_disc(uint16_t conn_id, tBTA_GATTC_SERV* p_server_cb) { +static tGATT_STATUS bta_gattc_sdp_service_disc(tCONN_ID conn_id, tBTA_GATTC_SERV* p_server_cb) { uint16_t num_attrs = 2; uint16_t attr_list[2]; @@ -460,7 +460,7 @@ void bta_gattc_op_cmpl_during_discovery(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATT } /** callback function to GATT client stack */ -void bta_gattc_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data) { +void bta_gattc_disc_res_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); tBTA_GATTC_SERV* p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id); @@ -498,7 +498,7 @@ void bta_gattc_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT } } -void bta_gattc_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status) { +void bta_gattc_disc_cmpl_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); tBTA_GATTC_SERV* p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id); @@ -597,7 +597,7 @@ const std::list<Service>* bta_gattc_get_services_srcb(tBTA_GATTC_SERV* p_srcb) { return &p_srcb->gatt_database.Services(); } -const std::list<Service>* bta_gattc_get_services(uint16_t conn_id) { +const std::list<Service>* bta_gattc_get_services(tCONN_ID conn_id) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { @@ -617,7 +617,7 @@ const Service* bta_gattc_get_service_for_handle_srcb(tBTA_GATTC_SERV* p_srcb, ui return bta_gattc_find_matching_service(*services, handle); } -const Service* bta_gattc_get_service_for_handle(uint16_t conn_id, uint16_t handle) { +const Service* bta_gattc_get_service_for_handle(tCONN_ID conn_id, uint16_t handle) { const std::list<Service>* services = bta_gattc_get_services(conn_id); if (services == NULL) { return NULL; @@ -642,7 +642,7 @@ const Characteristic* bta_gattc_get_characteristic_srcb(tBTA_GATTC_SERV* p_srcb, return NULL; } -const Characteristic* bta_gattc_get_characteristic(uint16_t conn_id, uint16_t handle) { +const Characteristic* bta_gattc_get_characteristic(tCONN_ID conn_id, uint16_t handle) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { @@ -671,7 +671,7 @@ const Descriptor* bta_gattc_get_descriptor_srcb(tBTA_GATTC_SERV* p_srcb, uint16_ return NULL; } -const Descriptor* bta_gattc_get_descriptor(uint16_t conn_id, uint16_t handle) { +const Descriptor* bta_gattc_get_descriptor(tCONN_ID conn_id, uint16_t handle) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { @@ -701,7 +701,7 @@ const Characteristic* bta_gattc_get_owning_characteristic_srcb(tBTA_GATTC_SERV* return NULL; } -const Characteristic* bta_gattc_get_owning_characteristic(uint16_t conn_id, uint16_t handle) { +const Characteristic* bta_gattc_get_owning_characteristic(tCONN_ID conn_id, uint16_t handle) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (!p_clcb) { return NULL; @@ -1021,7 +1021,7 @@ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV* p_srvc_cb, uint16_t star * Returns None. * ******************************************************************************/ -void bta_gattc_get_gatt_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, +void bta_gattc_get_gatt_db(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); diff --git a/system/bta/gatt/bta_gattc_int.h b/system/bta/gatt/bta_gattc_int.h index d213e68814..f4eeab85c6 100644 --- a/system/bta/gatt/bta_gattc_int.h +++ b/system/bta/gatt/bta_gattc_int.h @@ -256,7 +256,7 @@ typedef struct { uint16_t mtu; bool disc_blocked_waiting_on_version; - uint16_t blocked_conn_id; + tCONN_ID blocked_conn_id; } tBTA_GATTC_SERV; #ifndef BTA_GATTC_NOTIF_REG_MAX @@ -283,7 +283,7 @@ typedef struct { /* client channel is a mapping between a BTA client(cl_id) and a remote BD * address */ typedef struct { - uint16_t bta_conn_id; /* client channel ID, unique for clcb */ + tCONN_ID bta_conn_id; /* client channel ID, unique for clcb */ RawAddress bda; tBT_TRANSPORT transport; /* channel transport */ tBTA_GATTC_RCB* p_rcb; /* pointer to the registration CB */ @@ -405,7 +405,7 @@ void bta_gattc_op_cmpl_during_discovery(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATT void bta_gattc_restart_discover(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_msg); void bta_gattc_cancel_bk_conn(const tBTA_GATTC_API_CANCEL_OPEN* p_data); void bta_gattc_send_open_cback(tBTA_GATTC_RCB* p_clreg, tGATT_STATUS status, - const RawAddress& remote_bda, uint16_t conn_id, + const RawAddress& remote_bda, tCONN_ID conn_id, tBT_TRANSPORT transport, uint16_t mtu); void bta_gattc_process_api_refresh(const RawAddress& remote_bda); void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data); @@ -415,7 +415,7 @@ void bta_gattc_broadcast(tBTA_GATTC_DATA* p_msg); /* utility functions */ tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_cif(uint8_t client_if, const RawAddress& remote_bda, tBT_TRANSPORT transport); -tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(uint16_t conn_id); +tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(tCONN_ID conn_id); tBTA_GATTC_CLCB* bta_gattc_clcb_alloc(tGATT_IF client_if, const RawAddress& remote_bda, tBT_TRANSPORT transport); void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB* p_clcb); @@ -425,7 +425,7 @@ tBTA_GATTC_CLCB* bta_gattc_find_alloc_clcb(tGATT_IF client_if, const RawAddress& tBTA_GATTC_RCB* bta_gattc_cl_get_regcb(uint8_t client_if); tBTA_GATTC_SERV* bta_gattc_find_srcb(const RawAddress& bda); tBTA_GATTC_SERV* bta_gattc_srcb_alloc(const RawAddress& bda); -tBTA_GATTC_SERV* bta_gattc_find_scb_by_cid(uint16_t conn_id); +tBTA_GATTC_SERV* bta_gattc_find_scb_by_cid(tCONN_ID conn_id); tBTA_GATTC_CLCB* bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA* p_msg); tBTA_GATTC_CLCB* bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA* p_msg); @@ -439,7 +439,7 @@ bool bta_gattc_is_data_queued(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_ void bta_gattc_continue(tBTA_GATTC_CLCB* p_clcb); void bta_gattc_send_mtu_response(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data, uint16_t current_mtu); -void bta_gattc_cmpl_sendmsg(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +void bta_gattc_cmpl_sendmsg(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); bool bta_gattc_check_notif_registry(tBTA_GATTC_RCB* p_clreg, tBTA_GATTC_SERV* p_srcb, @@ -447,26 +447,26 @@ bool bta_gattc_check_notif_registry(tBTA_GATTC_RCB* p_clreg, tBTA_GATTC_SERV* p_ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda, bool add); bool bta_gattc_check_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda, uint8_t role); uint8_t bta_gattc_num_reg_app(void); -void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV* p_srcb, uint16_t conn_id, +void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV* p_srcb, tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle); tBTA_GATTC_SERV* bta_gattc_find_srvr_cache(const RawAddress& bda); /* discovery functions */ -void bta_gattc_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data); -void bta_gattc_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); -tGATT_STATUS bta_gattc_discover_pri_service(uint16_t conn_id, tBTA_GATTC_SERV* p_server_cb, +void bta_gattc_disc_res_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data); +void bta_gattc_disc_cmpl_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); +tGATT_STATUS bta_gattc_discover_pri_service(tCONN_ID conn_id, tBTA_GATTC_SERV* p_server_cb, tGATT_DISC_TYPE disc_type); void bta_gattc_search_service(tBTA_GATTC_CLCB* p_clcb, bluetooth::Uuid* p_uuid); -const std::list<gatt::Service>* bta_gattc_get_services(uint16_t conn_id); -const gatt::Service* bta_gattc_get_service_for_handle(uint16_t conn_id, uint16_t handle); +const std::list<gatt::Service>* bta_gattc_get_services(tCONN_ID conn_id); +const gatt::Service* bta_gattc_get_service_for_handle(tCONN_ID conn_id, uint16_t handle); const gatt::Characteristic* bta_gattc_get_characteristic_srcb(tBTA_GATTC_SERV* p_srcb, uint16_t handle); const gatt::Service* bta_gattc_get_service_for_handle_srcb(tBTA_GATTC_SERV* p_srcb, uint16_t handle); -const gatt::Characteristic* bta_gattc_get_characteristic(uint16_t conn_id, uint16_t handle); -const gatt::Descriptor* bta_gattc_get_descriptor(uint16_t conn_id, uint16_t handle); -const gatt::Characteristic* bta_gattc_get_owning_characteristic(uint16_t conn_id, uint16_t handle); -void bta_gattc_get_gatt_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, +const gatt::Characteristic* bta_gattc_get_characteristic(tCONN_ID conn_id, uint16_t handle); +const gatt::Descriptor* bta_gattc_get_descriptor(tCONN_ID conn_id, uint16_t handle); +const gatt::Characteristic* bta_gattc_get_owning_characteristic(tCONN_ID conn_id, uint16_t handle); +void bta_gattc_get_gatt_db(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count); void bta_gattc_init_cache(tBTA_GATTC_SERV* p_srvc_cb); diff --git a/system/bta/gatt/bta_gattc_main.cc b/system/bta/gatt/bta_gattc_main.cc index 0bf55b1cfb..fc642edfd4 100644 --- a/system/bta/gatt/bta_gattc_main.cc +++ b/system/bta/gatt/bta_gattc_main.cc @@ -328,7 +328,7 @@ bool bta_gattc_hdl_event(const BT_HDR_RIGID* p_msg) { } else if (p_msg->event == BTA_GATTC_INT_DISCONN_EVT) { p_clcb = bta_gattc_find_int_disconn_clcb((tBTA_GATTC_DATA*)p_msg); } else { - p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->layer_specific); + p_clcb = bta_gattc_find_clcb_by_conn_id(static_cast<tCONN_ID>(p_msg->layer_specific)); } if (p_clcb != nullptr) { diff --git a/system/bta/gatt/bta_gattc_queue.cc b/system/bta/gatt/bta_gattc_queue.cc index 9ecc016e05..6d2cc8c887 100644 --- a/system/bta/gatt/bta_gattc_queue.cc +++ b/system/bta/gatt/bta_gattc_queue.cc @@ -43,14 +43,14 @@ struct gatt_read_op_data { void* cb_data; }; -std::unordered_map<uint16_t, std::list<gatt_operation>> BtaGattQueue::gatt_op_queue; -std::unordered_set<uint16_t> BtaGattQueue::gatt_op_queue_executing; +std::unordered_map<tCONN_ID, std::list<gatt_operation>> BtaGattQueue::gatt_op_queue; +std::unordered_set<tCONN_ID> BtaGattQueue::gatt_op_queue_executing; -void BtaGattQueue::mark_as_not_executing(uint16_t conn_id) { +void BtaGattQueue::mark_as_not_executing(tCONN_ID conn_id) { gatt_op_queue_executing.erase(conn_id); } -void BtaGattQueue::gatt_read_op_finished(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +void BtaGattQueue::gatt_read_op_finished(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { gatt_read_op_data* tmp = (gatt_read_op_data*)data; GATT_READ_OP_CB tmp_cb = tmp->cb; @@ -72,7 +72,7 @@ struct gatt_write_op_data { void* cb_data; }; -void BtaGattQueue::gatt_write_op_finished(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +void BtaGattQueue::gatt_write_op_finished(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { gatt_write_op_data* tmp = (gatt_write_op_data*)data; GATT_WRITE_OP_CB tmp_cb = tmp->cb; @@ -94,7 +94,7 @@ struct gatt_configure_mtu_op_data { void* cb_data; }; -void BtaGattQueue::gatt_configure_mtu_op_finished(uint16_t conn_id, tGATT_STATUS status, +void BtaGattQueue::gatt_configure_mtu_op_finished(tCONN_ID conn_id, tGATT_STATUS status, void* data) { gatt_configure_mtu_op_data* tmp = (gatt_configure_mtu_op_data*)data; GATT_CONFIGURE_MTU_OP_CB tmp_cb = tmp->cb; @@ -128,7 +128,7 @@ struct gatt_read_multi_simulate_op_data { uint16_t values_end; }; -void BtaGattQueue::gatt_read_multi_op_finished(uint16_t conn_id, tGATT_STATUS status, +void BtaGattQueue::gatt_read_multi_op_finished(tCONN_ID conn_id, tGATT_STATUS status, tBTA_GATTC_MULTI& handles, uint16_t len, uint8_t* value, void* data) { gatt_read_multi_op_data* tmp = (gatt_read_multi_op_data*)data; @@ -146,7 +146,7 @@ void BtaGattQueue::gatt_read_multi_op_finished(uint16_t conn_id, tGATT_STATUS st } } -void BtaGattQueue::gatt_read_multi_op_simulate(uint16_t conn_id, tGATT_STATUS status, +void BtaGattQueue::gatt_read_multi_op_simulate(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data_read) { gatt_read_multi_simulate_op_data* data = (gatt_read_multi_simulate_op_data*)data_read; @@ -191,7 +191,7 @@ void BtaGattQueue::gatt_read_multi_op_simulate(uint16_t conn_id, tGATT_STATUS st } } -void BtaGattQueue::gatt_execute_next_op(uint16_t conn_id) { +void BtaGattQueue::gatt_execute_next_op(tCONN_ID conn_id) { log::verbose("conn_id=0x{:x}", conn_id); if (gatt_op_queue.empty()) { log::verbose("op queue is empty"); @@ -284,26 +284,26 @@ void BtaGattQueue::gatt_execute_next_op(uint16_t conn_id) { gatt_ops.pop_front(); } -void BtaGattQueue::Clean(uint16_t conn_id) { +void BtaGattQueue::Clean(tCONN_ID conn_id) { gatt_op_queue.erase(conn_id); gatt_op_queue_executing.erase(conn_id); } -void BtaGattQueue::ReadCharacteristic(uint16_t conn_id, uint16_t handle, GATT_READ_OP_CB cb, +void BtaGattQueue::ReadCharacteristic(tCONN_ID conn_id, uint16_t handle, GATT_READ_OP_CB cb, void* cb_data) { gatt_op_queue[conn_id].push_back( {.type = GATT_READ_CHAR, .handle = handle, .read_cb = cb, .read_cb_data = cb_data}); gatt_execute_next_op(conn_id); } -void BtaGattQueue::ReadDescriptor(uint16_t conn_id, uint16_t handle, GATT_READ_OP_CB cb, +void BtaGattQueue::ReadDescriptor(tCONN_ID conn_id, uint16_t handle, GATT_READ_OP_CB cb, void* cb_data) { gatt_op_queue[conn_id].push_back( {.type = GATT_READ_DESC, .handle = handle, .read_cb = cb, .read_cb_data = cb_data}); gatt_execute_next_op(conn_id); } -void BtaGattQueue::WriteCharacteristic(uint16_t conn_id, uint16_t handle, +void BtaGattQueue::WriteCharacteristic(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data) { gatt_op_queue[conn_id].push_back({.type = GATT_WRITE_CHAR, @@ -315,7 +315,7 @@ void BtaGattQueue::WriteCharacteristic(uint16_t conn_id, uint16_t handle, gatt_execute_next_op(conn_id); } -void BtaGattQueue::WriteDescriptor(uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, +void BtaGattQueue::WriteDescriptor(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data) { gatt_op_queue[conn_id].push_back({.type = GATT_WRITE_DESC, @@ -327,14 +327,14 @@ void BtaGattQueue::WriteDescriptor(uint16_t conn_id, uint16_t handle, std::vecto gatt_execute_next_op(conn_id); } -void BtaGattQueue::ConfigureMtu(uint16_t conn_id, uint16_t mtu) { +void BtaGattQueue::ConfigureMtu(tCONN_ID conn_id, uint16_t mtu) { log::info("mtu: {}", static_cast<int>(mtu)); std::vector<uint8_t> value = {static_cast<uint8_t>(mtu & 0xff), static_cast<uint8_t>(mtu >> 8)}; gatt_op_queue[conn_id].push_back({.type = GATT_CONFIG_MTU, .value = std::move(value)}); gatt_execute_next_op(conn_id); } -void BtaGattQueue::ReadMultiCharacteristic(uint16_t conn_id, tBTA_GATTC_MULTI& handles, +void BtaGattQueue::ReadMultiCharacteristic(tCONN_ID conn_id, tBTA_GATTC_MULTI& handles, GATT_READ_MULTI_OP_CB cb, void* cb_data) { gatt_op_queue[conn_id].push_back({.type = GATT_READ_MULTI, .handles = handles, diff --git a/system/bta/gatt/bta_gattc_utils.cc b/system/bta/gatt/bta_gattc_utils.cc index 94dec0c02b..994411e039 100644 --- a/system/bta/gatt/bta_gattc_utils.cc +++ b/system/bta/gatt/bta_gattc_utils.cc @@ -139,7 +139,7 @@ tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_cif(uint8_t client_if, const RawAddress& * Returns pointer to the clcb * ******************************************************************************/ -tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(uint16_t conn_id) { +tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(tCONN_ID conn_id) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& p_clcb : bta_gattc_cb.clcb_set) { if (p_clcb->bta_conn_id == conn_id) { @@ -388,7 +388,7 @@ tBTA_GATTC_SERV* bta_gattc_find_srvr_cache(const RawAddress& bda) { * Returns pointer to the server cache. * ******************************************************************************/ -tBTA_GATTC_SERV* bta_gattc_find_scb_by_cid(uint16_t conn_id) { +tBTA_GATTC_SERV* bta_gattc_find_scb_by_cid(tCONN_ID conn_id) { tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); if (p_clcb) { @@ -574,7 +574,7 @@ bool bta_gattc_check_notif_registry(tBTA_GATTC_RCB* p_clreg, tBTA_GATTC_SERV* p_ * Returns None. * ******************************************************************************/ -void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV* p_srcb, uint16_t conn_id, +void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV* p_srcb, tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle) { RawAddress remote_bda; tGATT_IF gatt_if; @@ -713,7 +713,7 @@ bool bta_gattc_check_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda, u * ******************************************************************************/ void bta_gattc_send_open_cback(tBTA_GATTC_RCB* p_clreg, tGATT_STATUS status, - const RawAddress& remote_bda, uint16_t conn_id, + const RawAddress& remote_bda, tCONN_ID conn_id, tBT_TRANSPORT transport, uint16_t mtu) { tBTA_GATTC cb_data; @@ -865,7 +865,8 @@ tBTA_GATTC_CLCB* bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA* p_msg) { tBTA_GATTC_CLCB* p_clcb = NULL; bta_gattc_conn_dealloc(p_msg->int_conn.remote_bda); - p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->int_conn.hdr.layer_specific); + p_clcb = + bta_gattc_find_clcb_by_conn_id(static_cast<tCONN_ID>(p_msg->int_conn.hdr.layer_specific)); if (p_clcb == NULL) { /* connection attempt failed, send connection callback event */ p_clcb = bta_gattc_find_clcb_by_cif(p_msg->int_conn.client_if, p_msg->int_conn.remote_bda, diff --git a/system/bta/gatt/bta_gatts_act.cc b/system/bta/gatt/bta_gatts_act.cc index f9759dbbdf..8d951ad3c2 100644 --- a/system/bta/gatt/bta_gatts_act.cc +++ b/system/bta/gatt/bta_gatts_act.cc @@ -44,17 +44,17 @@ static void bta_gatts_nv_save_cback(bool is_saved, tGATTS_HNDL_RANGE* p_hndl_ran static bool bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ* p_req, tGATTS_SRV_CHG_RSP* p_rsp); -static void bta_gatts_conn_cback(tGATT_IF gatt_if, const RawAddress& bda, uint16_t conn_id, +static void bta_gatts_conn_cback(tGATT_IF gatt_if, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); -static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id, +static void bta_gatts_send_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE req_type, tGATTS_DATA* p_data); -static void bta_gatts_cong_cback(uint16_t conn_id, bool congested); -static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint8_t tx_phy, +static void bta_gatts_cong_cback(tCONN_ID conn_id, bool congested); +static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status); -static void bta_gatts_conn_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t interval, +static void bta_gatts_conn_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t interval, uint16_t latency, uint16_t timeout, tGATT_STATUS status); -static void bta_gatts_subrate_chg_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t subrate_factor, +static void bta_gatts_subrate_chg_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t subrate_factor, uint16_t latency, uint16_t cont_num, uint16_t timeout, tGATT_STATUS status); @@ -334,8 +334,9 @@ void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB* p_srvc_cb, tBTA_GATTS_DATA* /* p * ******************************************************************************/ void bta_gatts_send_rsp(tBTA_GATTS_CB* /* p_cb */, tBTA_GATTS_DATA* p_msg) { - if (GATTS_SendRsp(p_msg->api_rsp.hdr.layer_specific, p_msg->api_rsp.trans_id, - p_msg->api_rsp.status, (tGATTS_RSP*)p_msg->api_rsp.p_rsp) != GATT_SUCCESS) { + auto conn_id = static_cast<tCONN_ID>(p_msg->api_rsp.hdr.layer_specific); + if (GATTS_SendRsp(conn_id, p_msg->api_rsp.trans_id, p_msg->api_rsp.status, + (tGATTS_RSP*)p_msg->api_rsp.p_rsp) != GATT_SUCCESS) { log::error("Sending response failed"); } } @@ -360,18 +361,16 @@ void bta_gatts_indicate_handle(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { p_srvc_cb = bta_gatts_find_srvc_cb_by_attr_id(p_cb, p_msg->api_indicate.attr_id); if (p_srvc_cb) { - if (GATT_GetConnectionInfor(p_msg->api_indicate.hdr.layer_specific, &gatt_if, remote_bda, - &transport)) { + auto conn_id = static_cast<tCONN_ID>(p_msg->api_indicate.hdr.layer_specific); + if (GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda, &transport)) { p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); if (p_msg->api_indicate.need_confirm) { - status = GATTS_HandleValueIndication(p_msg->api_indicate.hdr.layer_specific, - p_msg->api_indicate.attr_id, p_msg->api_indicate.len, - p_msg->api_indicate.value); + status = GATTS_HandleValueIndication(conn_id, p_msg->api_indicate.attr_id, + p_msg->api_indicate.len, p_msg->api_indicate.value); } else { - status = GATTS_HandleValueNotification(p_msg->api_indicate.hdr.layer_specific, - p_msg->api_indicate.attr_id, p_msg->api_indicate.len, - p_msg->api_indicate.value); + status = GATTS_HandleValueNotification(conn_id, p_msg->api_indicate.attr_id, + p_msg->api_indicate.len, p_msg->api_indicate.value); } /* if over BR_EDR, inform PM for mode change */ @@ -387,7 +386,7 @@ void bta_gatts_indicate_handle(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { if ((status != GATT_SUCCESS || !p_msg->api_indicate.need_confirm) && p_rcb && p_cb->rcb[p_srvc_cb->rcb_idx].p_cback) { cb_data.req_data.status = status; - cb_data.req_data.conn_id = p_msg->api_indicate.hdr.layer_specific; + cb_data.req_data.conn_id = conn_id; (*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data); } @@ -408,7 +407,7 @@ void bta_gatts_indicate_handle(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { void bta_gatts_open(tBTA_GATTS_CB* /* p_cb */, tBTA_GATTS_DATA* p_msg) { tBTA_GATTS_RCB* p_rcb = NULL; tGATT_STATUS status = GATT_ERROR; - uint16_t conn_id; + tCONN_ID conn_id; p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if); if (p_rcb != NULL) { @@ -486,11 +485,12 @@ void bta_gatts_close(tBTA_GATTS_CB* /* p_cb */, tBTA_GATTS_DATA* p_msg) { tGATT_IF gatt_if; RawAddress remote_bda; tBT_TRANSPORT transport; + tCONN_ID conn_id = static_cast<tCONN_ID>(p_msg->hdr.layer_specific); - if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda, &transport)) { + if (GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda, &transport)) { log::debug("Disconnecting gatt_if={}, remote_bda={}, transport={}", gatt_if, remote_bda, transport); - status = GATT_Disconnect(p_msg->hdr.layer_specific); + status = GATT_Disconnect(conn_id); if (status != GATT_SUCCESS) { log::error("fail conn_id={}", p_msg->hdr.layer_specific); status = GATT_ERROR; @@ -521,7 +521,7 @@ void bta_gatts_close(tBTA_GATTS_CB* /* p_cb */, tBTA_GATTS_DATA* p_msg) { * Returns none. * ******************************************************************************/ -static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id, +static void bta_gatts_send_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE req_type, tGATTS_DATA* p_data) { tBTA_GATTS cb_data; tBTA_GATTS_RCB* p_rcb; @@ -564,7 +564,7 @@ static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id, * Returns none. * ******************************************************************************/ -static void bta_gatts_conn_cback(tGATT_IF gatt_if, const RawAddress& bdaddr, uint16_t conn_id, +static void bta_gatts_conn_cback(tGATT_IF gatt_if, const RawAddress& bdaddr, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON, tBT_TRANSPORT transport) { tBTA_GATTS cb_data; uint8_t evt = connected ? BTA_GATTS_CONNECT_EVT : BTA_GATTS_DISCONNECT_EVT; @@ -601,7 +601,7 @@ static void bta_gatts_conn_cback(tGATT_IF gatt_if, const RawAddress& bdaddr, uin } } -static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint8_t tx_phy, +static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status) { tBTA_GATTS_RCB* p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if); if (!p_reg || !p_reg->p_cback) { @@ -618,7 +618,7 @@ static void bta_gatts_phy_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint8 (*p_reg->p_cback)(BTA_GATTS_PHY_UPDATE_EVT, &cb_data); } -static void bta_gatts_conn_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t interval, +static void bta_gatts_conn_update_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t interval, uint16_t latency, uint16_t timeout, tGATT_STATUS status) { tBTA_GATTS_RCB* p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if); if (!p_reg || !p_reg->p_cback) { @@ -636,7 +636,7 @@ static void bta_gatts_conn_update_cback(tGATT_IF gatt_if, uint16_t conn_id, uint (*p_reg->p_cback)(BTA_GATTS_CONN_UPDATE_EVT, &cb_data); } -static void bta_gatts_subrate_chg_cback(tGATT_IF gatt_if, uint16_t conn_id, uint16_t subrate_factor, +static void bta_gatts_subrate_chg_cback(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t subrate_factor, uint16_t latency, uint16_t cont_num, uint16_t timeout, tGATT_STATUS status) { tBTA_GATTS_RCB* p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if); @@ -665,7 +665,7 @@ static void bta_gatts_subrate_chg_cback(tGATT_IF gatt_if, uint16_t conn_id, uint * Returns none. * ******************************************************************************/ -static void bta_gatts_cong_cback(uint16_t conn_id, bool congested) { +static void bta_gatts_cong_cback(tCONN_ID conn_id, bool congested) { tBTA_GATTS_RCB* p_rcb; tGATT_IF gatt_if; tBT_TRANSPORT transport; diff --git a/system/bta/gatt/bta_gatts_queue.cc b/system/bta/gatt/bta_gatts_queue.cc index 32ab5d8b32..1344f036f0 100644 --- a/system/bta/gatt/bta_gatts_queue.cc +++ b/system/bta/gatt/bta_gatts_queue.cc @@ -31,15 +31,15 @@ using namespace bluetooth; constexpr uint8_t GATT_NOTIFY = 1; -std::unordered_map<uint16_t, std::list<gatts_operation>> BtaGattServerQueue::gatts_op_queue; -std::unordered_set<uint16_t> BtaGattServerQueue::gatts_op_queue_executing; -std::unordered_map<uint16_t, bool> BtaGattServerQueue::congestion_queue; +std::unordered_map<tCONN_ID, std::list<gatts_operation>> BtaGattServerQueue::gatts_op_queue; +std::unordered_set<tCONN_ID> BtaGattServerQueue::gatts_op_queue_executing; +std::unordered_map<tCONN_ID, bool> BtaGattServerQueue::congestion_queue; -void BtaGattServerQueue::mark_as_not_executing(uint16_t conn_id) { +void BtaGattServerQueue::mark_as_not_executing(tCONN_ID conn_id) { gatts_op_queue_executing.erase(conn_id); } -void BtaGattServerQueue::gatts_execute_next_op(uint16_t conn_id) { +void BtaGattServerQueue::gatts_execute_next_op(tCONN_ID conn_id) { log::verbose("conn_id=0x{:x}", conn_id); if (gatts_op_queue.empty()) { @@ -84,21 +84,21 @@ void BtaGattServerQueue::gatts_execute_next_op(uint16_t conn_id) { } } -void BtaGattServerQueue::Clean(uint16_t conn_id) { +void BtaGattServerQueue::Clean(tCONN_ID conn_id) { log::verbose("conn_id=0x{:x}", conn_id); gatts_op_queue.erase(conn_id); gatts_op_queue_executing.erase(conn_id); } -void BtaGattServerQueue::SendNotification(uint16_t conn_id, uint16_t handle, +void BtaGattServerQueue::SendNotification(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, bool need_confirm) { gatts_op_queue[conn_id].emplace_back(gatts_operation{ .type = GATT_NOTIFY, .attr_id = handle, .value = value, .need_confirm = need_confirm}); gatts_execute_next_op(conn_id); } -void BtaGattServerQueue::NotificationCallback(uint16_t conn_id) { +void BtaGattServerQueue::NotificationCallback(tCONN_ID conn_id) { auto map_ptr = gatts_op_queue.find(conn_id); if (map_ptr == gatts_op_queue.end() || map_ptr->second.empty()) { log::verbose("no more operations queued for conn_id {}", conn_id); @@ -111,7 +111,7 @@ void BtaGattServerQueue::NotificationCallback(uint16_t conn_id) { gatts_execute_next_op(conn_id); } -void BtaGattServerQueue::CongestionCallback(uint16_t conn_id, bool congested) { +void BtaGattServerQueue::CongestionCallback(tCONN_ID conn_id, bool congested) { log::verbose("conn_id: {}, congested: {}", conn_id, congested); congestion_queue[conn_id] = congested; diff --git a/system/bta/has/has_client.cc b/system/bta/has/has_client.cc index 1c17263c03..8b4ebbe7cc 100644 --- a/system/bta/has/has_client.cc +++ b/system/bta/has/has_client.cc @@ -285,7 +285,7 @@ public: void EnqueueCtpOp(HasCtpOp op) { pending_operations_.push_back(op); } - void OnHasActivePresetCycleStatus(uint16_t conn_id, tGATT_STATUS status, void* user_data) { + void OnHasActivePresetCycleStatus(tCONN_ID conn_id, tGATT_STATUS status, void* user_data) { log::debug("status: {}", status); auto device = GetDevice(conn_id); @@ -321,7 +321,7 @@ public: } } - void OnHasPresetNameSetStatus(uint16_t conn_id, tGATT_STATUS status, void* user_data) { + void OnHasPresetNameSetStatus(tCONN_ID conn_id, tGATT_STATUS status, void* user_data) { auto device = GetDevice(conn_id); if (!device) { log::warn("Device not connected to profile, conn_id={}", conn_id); @@ -355,7 +355,7 @@ public: } } - void OnHasPresetNameGetStatus(uint16_t conn_id, tGATT_STATUS status, void* user_data) { + void OnHasPresetNameGetStatus(tCONN_ID conn_id, tGATT_STATUS status, void* user_data) { auto device = GetDevice(conn_id); if (!device) { log::warn("Device not connected to profile, conn_id={}", conn_id); @@ -390,7 +390,7 @@ public: } } - void OnHasPresetIndexOperation(uint16_t conn_id, tGATT_STATUS status, void* user_data) { + void OnHasPresetIndexOperation(tCONN_ID conn_id, tGATT_STATUS status, void* user_data) { log::debug(""); auto device = GetDevice(conn_id); @@ -471,7 +471,7 @@ public: EnqueueCtpOp(operation); BtaGattQueue::WriteCharacteristic( device->conn_id, device->cp_handle, operation.ToCharacteristicValue(), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data) { if (instance) { instance->OnHasPresetNameGetStatus(conn_id, status, user_data); @@ -571,7 +571,7 @@ public: EnqueueCtpOp(operation); BtaGattQueue::WriteCharacteristic( device.conn_id, device.cp_handle, operation.ToCharacteristicValue(), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data) { if (instance) { instance->OnHasPresetIndexOperation(conn_id, status, user_data); @@ -731,7 +731,7 @@ public: EnqueueCtpOp(operation); BtaGattQueue::WriteCharacteristic( device.conn_id, device.cp_handle, operation.ToCharacteristicValue(), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data) { if (instance) { instance->OnHasActivePresetCycleStatus(conn_id, status, user_data); @@ -791,7 +791,7 @@ public: EnqueueCtpOp(operation); BtaGattQueue::WriteCharacteristic( device.conn_id, device.cp_handle, operation.ToCharacteristicValue(), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data) { if (instance) { instance->OnHasPresetNameSetStatus(conn_id, status, user_data); @@ -1066,7 +1066,7 @@ private: } } - void OnGattWriteCcc(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, void* user_data) { + void OnGattWriteCcc(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, void* user_data) { log::debug("handle=0x{:x}", handle); auto device = GetDevice(conn_id); @@ -1100,7 +1100,7 @@ private: } } - void OnHasNotification(uint16_t conn_id, uint16_t handle, uint16_t len, const uint8_t* value) { + void OnHasNotification(tCONN_ID conn_id, uint16_t handle, uint16_t len, const uint8_t* value) { auto device = GetDevice(conn_id); if (!device) { log::warn("Skipping unknown device, conn_id=0x{:x}", conn_id); @@ -1119,14 +1119,14 @@ private: } /* Gets the device from variant, possibly searching by conn_id */ - HasDevice* GetDevice(std::variant<uint16_t, HasDevice*> conn_id_device_variant) { + HasDevice* GetDevice(std::variant<tCONN_ID, HasDevice*> conn_id_device_variant) { HasDevice* device = nullptr; if (std::holds_alternative<HasDevice*>(conn_id_device_variant)) { device = std::get<HasDevice*>(conn_id_device_variant); } else { auto it = std::find_if(devices_.begin(), devices_.end(), - HasDevice::MatchConnId(std::get<uint16_t>(conn_id_device_variant))); + HasDevice::MatchConnId(std::get<tCONN_ID>(conn_id_device_variant))); if (it != devices_.end()) { device = &(*it); } @@ -1135,7 +1135,7 @@ private: return device; } - void OnHasFeaturesValue(std::variant<uint16_t, HasDevice*> conn_id_device_variant, + void OnHasFeaturesValue(std::variant<tCONN_ID, HasDevice*> conn_id_device_variant, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data = nullptr) { log::debug(""); @@ -1531,7 +1531,7 @@ private: } } - void OnHasActivePresetValue(std::variant<uint16_t, HasDevice*> conn_id_device_variant, + void OnHasActivePresetValue(std::variant<tCONN_ID, HasDevice*> conn_id_device_variant, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* user_data = nullptr) { log::debug(""); @@ -1776,7 +1776,7 @@ private: /* Read the initial features */ BtaGattQueue::ReadCharacteristic( device->conn_id, device->features_handle, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* user_data) { if (instance) { instance->OnHasFeaturesValue(conn_id, status, handle, len, value, user_data); @@ -1811,7 +1811,7 @@ private: /* Read the current active preset index */ BtaGattQueue::ReadCharacteristic( device->conn_id, device->active_preset_handle, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* user_data) { if (instance) { instance->OnHasActivePresetValue(conn_id, status, handle, len, value, user_data); @@ -2094,7 +2094,7 @@ private: } } - static uint16_t FindCccHandle(uint16_t conn_id, uint16_t char_handle) { + static uint16_t FindCccHandle(tCONN_ID conn_id, uint16_t char_handle) { const gatt::Characteristic* p_char = BTA_GATTC_GetCharacteristic(conn_id, char_handle); if (!p_char) { log::warn("No such characteristic: {}", char_handle); @@ -2110,7 +2110,7 @@ private: return GAP_INVALID_HANDLE; } - void SubscribeForNotifications(uint16_t conn_id, const RawAddress& address, uint16_t value_handle, + void SubscribeForNotifications(tCONN_ID conn_id, const RawAddress& address, uint16_t value_handle, uint16_t ccc_handle, uint16_t ccc_val = GATT_CHAR_CLIENT_CONFIG_NOTIFICATION) { if (value_handle != GAP_INVALID_HANDLE) { @@ -2129,7 +2129,7 @@ private: UINT16_TO_STREAM(value_ptr, ccc_val); BtaGattQueue::WriteDescriptor( conn_id, ccc_handle, std::move(value), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t value_handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t value_handle, uint16_t len, const uint8_t* value, void* data) { if (instance) { instance->OnGattWriteCcc(conn_id, status, value_handle, data); diff --git a/system/bta/has/has_types.h b/system/bta/has/has_types.h index cb15f543e8..5041838e02 100644 --- a/system/bta/has/has_types.h +++ b/system/bta/has/has_types.h @@ -84,7 +84,7 @@ static const uint8_t kMaxNumOfPresets = 255; class GattServiceDevice { public: RawAddress addr; - uint16_t conn_id = GATT_INVALID_CONN_ID; + tCONN_ID conn_id = GATT_INVALID_CONN_ID; uint16_t service_handle = GAP_INVALID_HANDLE; bool is_connecting_actively = false; @@ -109,10 +109,10 @@ public: class MatchConnId { private: - uint16_t conn_id; + tCONN_ID conn_id; public: - MatchConnId(uint16_t conn_id) : conn_id(conn_id) {} + MatchConnId(tCONN_ID conn_id) : conn_id(conn_id) {} bool operator()(const GattServiceDevice& other) const { return conn_id == other.conn_id; } }; diff --git a/system/bta/hearing_aid/hearing_aid.cc b/system/bta/hearing_aid/hearing_aid.cc index ad0d938f7c..796a8d2056 100644 --- a/system/bta/hearing_aid/hearing_aid.cc +++ b/system/bta/hearing_aid/hearing_aid.cc @@ -105,6 +105,8 @@ constexpr uint8_t OTHER_SIDE_IS_STREAMING = 0x01; // connnection intervals. constexpr uint16_t ADD_RENDER_DELAY_INTERVALS = 4; +constexpr tCONN_ID INVALID_CONN_ID = 0; + namespace { // clang-format off @@ -169,13 +171,14 @@ public: HearingDevice* FindOtherConnectedDeviceFromSet(const HearingDevice& device) { auto iter = std::find_if(devices.begin(), devices.end(), [&device](const HearingDevice& other) { - return &device != &other && device.hi_sync_id == other.hi_sync_id && other.conn_id != 0; + return &device != &other && device.hi_sync_id == other.hi_sync_id && + other.conn_id != INVALID_CONN_ID; }); return (iter == devices.end()) ? nullptr : &(*iter); } - HearingDevice* FindByConnId(uint16_t conn_id) { + HearingDevice* FindByConnId(tCONN_ID conn_id) { auto iter = std::find_if( devices.begin(), devices.end(), [&conn_id](const HearingDevice& device) { return device.conn_id == conn_id; }); @@ -220,7 +223,7 @@ public: std::vector<HearingDevice> devices; }; -static void write_rpt_ctl_cfg_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void write_rpt_ctl_cfg_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("handle= {}, conn_id={}, status= 0x{:x}, length={}", handle, conn_id, @@ -336,7 +339,7 @@ public: if (needs_parameter_update) { for (auto& device : hearingDevices.devices) { - if (device.conn_id != 0) { + if (device.conn_id != INVALID_CONN_ID) { device.connection_update_status = STARTED; device.requested_connection_interval = UpdateBleConnParams(device.address); } @@ -462,7 +465,7 @@ public: int GetDeviceCount() { return hearingDevices.size(); } - void OnGattConnected(tGATT_STATUS status, uint16_t conn_id, tGATT_IF client_if, + void OnGattConnected(tGATT_STATUS status, tCONN_ID conn_id, tGATT_IF client_if, RawAddress address, tBT_TRANSPORT transport, uint16_t mtu) { HearingDevice* hearingDevice = hearingDevices.FindByAddress(address); if (!hearingDevice) { @@ -502,7 +505,8 @@ public: // it to a direct connection to scan more aggressively for it if (hi_sync_id != 0) { for (auto& device : hearingDevices.devices) { - if (device.hi_sync_id == hi_sync_id && device.conn_id == 0 && !device.connecting_actively) { + if (device.hi_sync_id == hi_sync_id && device.conn_id == INVALID_CONN_ID && + !device.connecting_actively) { log::info("Promoting device from the set from background to direct connection, bda={}", device.address); device.connecting_actively = true; @@ -551,7 +555,7 @@ public: OnEncryptionComplete(address, true); } - void OnConnectionUpdateComplete(uint16_t conn_id, tBTA_GATTC* p_data) { + void OnConnectionUpdateComplete(tCONN_ID conn_id, tBTA_GATTC* p_data) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { log::error("unknown device: conn_id=0x{:x}", conn_id); @@ -621,7 +625,7 @@ public: } for (auto& device : hearingDevices.devices) { - if (device.conn_id && (device.connection_update_status == AWAITING)) { + if (device.conn_id != INVALID_CONN_ID && (device.connection_update_status == AWAITING)) { device.connection_update_status = STARTED; device.requested_connection_interval = UpdateBleConnParams(device.address); return; @@ -687,7 +691,7 @@ public: } // Just take care phy update successful case to avoid loop executing. - void OnPhyUpdateEvent(uint16_t conn_id, uint8_t tx_phys, uint8_t rx_phys, tGATT_STATUS status) { + void OnPhyUpdateEvent(tCONN_ID conn_id, uint8_t tx_phys, uint8_t rx_phys, tGATT_STATUS status) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { log::error("unknown device: conn_id=0x{:x}", conn_id); @@ -757,7 +761,7 @@ public: } } - void OnServiceSearchComplete(uint16_t conn_id, tGATT_STATUS status) { + void OnServiceSearchComplete(tCONN_ID conn_id, tGATT_STATUS status) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { log::error("unknown device: conn_id=0x{:x}", conn_id); @@ -850,7 +854,7 @@ public: } } - void OnNotificationEvent(uint16_t conn_id, uint16_t handle, uint16_t len, uint8_t* value) { + void OnNotificationEvent(tCONN_ID conn_id, uint16_t handle, uint16_t len, uint8_t* value) { HearingDevice* device = hearingDevices.FindByConnId(conn_id); if (!device) { log::error("unknown device: conn_id=0x{:x}", conn_id); @@ -878,7 +882,7 @@ public: device->command_acked = true; } - void OnReadOnlyPropertiesRead(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + void OnReadOnlyPropertiesRead(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { @@ -985,12 +989,12 @@ public: } } - void OnAudioStatus(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnAudioStatus(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { log::info("{}", base::HexEncode(value, len)); } - void OnPsmRead(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnPsmRead(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { @@ -1051,21 +1055,21 @@ public: } } - static void OnReadOnlyPropertiesReadStatic(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void OnReadOnlyPropertiesReadStatic(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (instance) { instance->OnReadOnlyPropertiesRead(conn_id, status, handle, len, value, data); } } - static void OnAudioStatusStatic(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void OnAudioStatusStatic(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (instance) { instance->OnAudioStatus(conn_id, status, handle, len, value, data); } } - static void OnPsmReadStatic(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + static void OnPsmReadStatic(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (instance) { instance->OnPsmRead(conn_id, status, handle, len, value, data); @@ -1221,7 +1225,7 @@ public: (device.hi_sync_id != this_side_device->hi_sync_id)) { continue; } - if (audio_running && (device.conn_id != 0)) { + if (audio_running && (device.conn_id != INVALID_CONN_ID)) { return OTHER_SIDE_IS_STREAMING; } else { return OTHER_SIDE_NOT_STREAMING; @@ -1273,7 +1277,7 @@ public: } } - static void StartAudioCtrlCallbackStatic(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void StartAudioCtrlCallbackStatic(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("handle={}, conn_id={}, status=0x{:x}", handle, conn_id, @@ -1287,7 +1291,7 @@ public: instance->StartAudioCtrlCallback(conn_id); } - void StartAudioCtrlCallback(uint16_t conn_id) { + void StartAudioCtrlCallback(tCONN_ID conn_id) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { log::error("Skipping unknown device, conn_id=0x{:x}", conn_id); @@ -1764,7 +1768,7 @@ public: DoDisconnectAudioStop(); } - void OnGattDisconnected(uint16_t conn_id, tGATT_IF client_if, RawAddress remote_bda) { + void OnGattDisconnected(tCONN_ID conn_id, tGATT_IF client_if, RawAddress remote_bda) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { log::error("unknown device: conn_id=0x{:x} bd_addr={}", conn_id, remote_bda); @@ -1828,10 +1832,10 @@ public: hearingDevice->connection_update_status = NONE; hearingDevice->gap_opened = false; - if (hearingDevice->conn_id) { + if (hearingDevice->conn_id != INVALID_CONN_ID) { BtaGattQueue::Clean(hearingDevice->conn_id); BTA_GATTC_Close(hearingDevice->conn_id); - hearingDevice->conn_id = 0; + hearingDevice->conn_id = INVALID_CONN_ID; } if (hearingDevice->gap_handle != GAP_INVALID_HANDLE) { @@ -1895,7 +1899,7 @@ private: HearingDevices hearingDevices; - void find_server_changed_ccc_handle(uint16_t conn_id, const gatt::Service* service) { + void find_server_changed_ccc_handle(tCONN_ID conn_id, const gatt::Service* service) { HearingDevice* hearingDevice = hearingDevices.FindByConnId(conn_id); if (!hearingDevice) { log::error("unknown device: conn_id=0x{:x}", conn_id); @@ -1919,7 +1923,7 @@ private: // Find the handle for the client characteristics configuration of a given // characteristics - uint16_t find_ccc_handle(uint16_t conn_id, uint16_t char_handle) { + uint16_t find_ccc_handle(tCONN_ID conn_id, uint16_t char_handle) { const gatt::Characteristic* p_char = BTA_GATTC_GetCharacteristic(conn_id, char_handle); if (!p_char) { @@ -1937,7 +1941,7 @@ private: } void send_state_change(HearingDevice* device, std::vector<uint8_t> payload) { - if (device->conn_id != 0) { + if (device->conn_id != INVALID_CONN_ID) { if (device->service_changed_rcvd) { log::info("service discover is in progress, skip send State Change cmd."); return; diff --git a/system/bta/hh/bta_hh_int.h b/system/bta/hh/bta_hh_int.h index 1929153182..c897c2105b 100644 --- a/system/bta/hh/bta_hh_int.h +++ b/system/bta/hh/bta_hh_int.h @@ -111,7 +111,7 @@ typedef struct { typedef struct { BT_HDR_RIGID hdr; - uint16_t conn_id; + tCONN_ID conn_id; tGATT_DISCONN_REASON reason; } tBTA_HH_LE_CLOSE; @@ -180,7 +180,7 @@ typedef struct { /* convert a GATT connection ID to HID device handle, it is the hi 4 bits of a * uint8_t */ #define BTA_HH_GET_LE_DEV_HDL(x) (uint8_t)(((x) + 1) << 4) -/* check to see if th edevice handle is a LE device handle */ +/* check to see if the device handle is a LE device handle */ #define BTA_HH_IS_LE_DEV_HDL(x) ((x) & 0xf0) #define BTA_HH_IS_LE_DEV_HDL_VALID(x) (((x) >> 4) <= BTA_HH_LE_MAX_KNOWN) @@ -213,7 +213,7 @@ typedef struct { tBTA_HH_STATUS status; tBTM_STATUS btm_status; tBTA_HH_LE_HID_SRVC hid_srvc; - uint16_t conn_id; + tCONN_ID conn_id; bool in_bg_conn; uint8_t clt_cfg_idx; bool scps_supported; diff --git a/system/bta/hh/bta_hh_le.cc b/system/bta/hh/bta_hh_le.cc index 599c051a47..883dc8ac66 100644 --- a/system/bta/hh/bta_hh_le.cc +++ b/system/bta/hh/bta_hh_le.cc @@ -195,7 +195,7 @@ void bta_hh_le_enable(void) { bta_hh_cb.le_cb_index[xx] = BTA_HH_IDX_INVALID; } - BTA_GATTC_AppRegister(bta_hh_gattc_callback, base::Bind([](uint8_t client_id, uint8_t r_status) { + BTA_GATTC_AppRegister(bta_hh_gattc_callback, base::Bind([](tGATT_IF client_id, uint8_t r_status) { tBTA_HH bta_hh; bta_hh.status = BTA_HH_ERR; @@ -284,7 +284,7 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB* p_cb) { * ID. * ******************************************************************************/ -static tBTA_HH_DEV_CB* bta_hh_le_find_dev_cb_by_conn_id(uint16_t conn_id) { +static tBTA_HH_DEV_CB* bta_hh_le_find_dev_cb_by_conn_id(tCONN_ID conn_id) { for (uint8_t i = 0; i < BTA_HH_MAX_DEVICE; i++) { tBTA_HH_DEV_CB* p_dev_cb = &bta_hh_cb.kdev[i]; if (p_dev_cb->in_use && p_dev_cb->conn_id == conn_id) { @@ -454,7 +454,7 @@ tBTA_HH_LE_RPT* bta_hh_le_find_alloc_report_entry(tBTA_HH_DEV_CB* p_cb, uint8_t return NULL; } -static const gatt::Descriptor* find_descriptor_by_short_uuid(uint16_t conn_id, uint16_t char_handle, +static const gatt::Descriptor* find_descriptor_by_short_uuid(tCONN_ID conn_id, uint16_t char_handle, uint16_t short_uuid) { const gatt::Characteristic* p_char = BTA_GATTC_GetCharacteristic(conn_id, char_handle); @@ -655,7 +655,7 @@ static bool bta_hh_le_write_ccc(tBTA_HH_DEV_CB* p_cb, uint16_t char_handle, uint static bool bta_hh_le_write_rpt_clt_cfg(tBTA_HH_DEV_CB* p_cb); -static void write_rpt_clt_cfg_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void write_rpt_clt_cfg_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { tBTA_HH_DEV_CB* p_dev_cb = (tBTA_HH_DEV_CB*)data; const gatt::Characteristic* characteristic = BTA_GATTC_GetOwningCharacteristic(conn_id, handle); @@ -756,7 +756,7 @@ void bta_hh_le_service_parsed(tBTA_HH_DEV_CB* p_dev_cb, tGATT_STATUS status) { } } -static void write_proto_mode_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void write_proto_mode_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { tBTA_HH_DEV_CB* p_dev_cb = (tBTA_HH_DEV_CB*)data; bta_hh_le_service_parsed(p_dev_cb, status); @@ -813,7 +813,7 @@ static bool bta_hh_le_set_protocol_mode(tBTA_HH_DEV_CB* p_cb, tBTA_HH_PROTO_MODE * application with the protocol mode. * ******************************************************************************/ -static void get_protocol_mode_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void get_protocol_mode_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { tBTA_HH_DEV_CB* p_dev_cb = (tBTA_HH_DEV_CB*)data; tBTA_HH_HSDATA hs_data; @@ -1237,7 +1237,7 @@ static void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB* p_cb, tBTA_HH_STATUS status } } -static void read_hid_info_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, +static void read_hid_info_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("error:{}", status); @@ -1272,7 +1272,7 @@ void bta_hh_le_save_report_map(tBTA_HH_DEV_CB* p_dev_cb, uint16_t len, uint8_t* } } -static void read_hid_report_map_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void read_hid_report_map_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("error reading characteristic:{}", status); @@ -1283,7 +1283,7 @@ static void read_hid_report_map_cb(uint16_t conn_id, tGATT_STATUS status, uint16 bta_hh_le_save_report_map(p_dev_cb, len, value); } -static void read_ext_rpt_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void read_ext_rpt_ref_desc_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("error:{}", status); @@ -1305,7 +1305,7 @@ static void read_ext_rpt_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint log::verbose("External Report Reference UUID 0x{:04x}", p_dev_cb->hid_srvc.ext_rpt_ref); } -static void read_report_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void read_report_ref_desc_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("error:{}", status); @@ -1345,7 +1345,7 @@ static void read_report_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint1 bta_hh_le_save_report_ref(p_dev_cb, p_rpt, rpt_type, rpt_id); } -static void read_pref_conn_params_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +static void read_pref_conn_params_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (status != GATT_SUCCESS) { log::error("error:{}", status); @@ -1794,7 +1794,7 @@ void bta_hh_le_api_disc_act(tBTA_HH_DEV_CB* p_cb) { * Parameters: * ******************************************************************************/ -static void read_report_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, +static void read_report_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { tBTA_HH_DEV_CB* p_dev_cb = (tBTA_HH_DEV_CB*)data; if (p_dev_cb->w4_evt != BTA_HH_GET_RPT_EVT) { @@ -1874,7 +1874,7 @@ static void bta_hh_le_get_rpt(tBTA_HH_DEV_CB* p_cb, tBTA_HH_RPT_TYPE r_type, uin BtaGattQueue::ReadCharacteristic(p_cb->conn_id, p_rpt->char_inst_id, read_report_cb, p_cb); } -static void write_report_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, +static void write_report_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { tBTA_HH_CBDATA cback_data; tBTA_HH_DEV_CB* p_dev_cb = (tBTA_HH_DEV_CB*)data; diff --git a/system/bta/include/bta_gatt_api.h b/system/bta/include/bta_gatt_api.h index 2bc8c3e094..0b55aa2074 100644 --- a/system/bta/include/bta_gatt_api.h +++ b/system/bta/include/bta_gatt_api.h @@ -132,7 +132,7 @@ typedef struct { } tBTA_GATTC_REG; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS status; uint16_t handle; uint16_t len; @@ -140,35 +140,35 @@ typedef struct { } tBTA_GATTC_READ; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS status; uint16_t handle; } tBTA_GATTC_WRITE; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS status; } tBTA_GATTC_EXEC_CMPL; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS status; } tBTA_GATTC_SEARCH_CMPL; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tBTA_GATT_ID service_uuid; } tBTA_GATTC_SRVC_RES; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS status; uint16_t mtu; } tBTA_GATTC_CFG_MTU; typedef struct { tGATT_STATUS status; - uint16_t conn_id; + tCONN_ID conn_id; tGATT_IF client_if; RawAddress remote_bda; tBT_TRANSPORT transport; @@ -176,7 +176,7 @@ typedef struct { } tBTA_GATTC_OPEN; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS status; tGATT_IF client_if; RawAddress remote_bda; @@ -184,7 +184,7 @@ typedef struct { } tBTA_GATTC_CLOSE; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; RawAddress bda; uint16_t handle; uint16_t len; @@ -194,14 +194,14 @@ typedef struct { } tBTA_GATTC_NOTIFY; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; bool congested; /* congestion indicator */ } tBTA_GATTC_CONGEST; typedef struct { tGATT_STATUS status; tGATT_IF client_if; - uint16_t conn_id; + tCONN_ID conn_id; RawAddress remote_bda; } tBTA_GATTC_OPEN_CLOSE; @@ -212,7 +212,7 @@ typedef struct { typedef struct { tGATT_IF server_if; - uint16_t conn_id; + tCONN_ID conn_id; uint8_t tx_phy; uint8_t rx_phy; tGATT_STATUS status; @@ -220,7 +220,7 @@ typedef struct { typedef struct { tGATT_IF server_if; - uint16_t conn_id; + tCONN_ID conn_id; uint16_t interval; uint16_t latency; uint16_t timeout; @@ -229,7 +229,7 @@ typedef struct { typedef struct { RawAddress remote_bda; - uint16_t conn_id; + tCONN_ID conn_id; } tBTA_GATTC_SERVICE_CHANGED; typedef struct { @@ -238,7 +238,7 @@ typedef struct { typedef struct { tGATT_IF server_if; - uint16_t conn_id; + tCONN_ID conn_id; uint16_t subrate_factor; uint16_t latency; uint16_t cont_num; @@ -349,7 +349,7 @@ typedef struct { tGATT_STATUS status; RawAddress remote_bda; uint32_t trans_id; - uint16_t conn_id; + tCONN_ID conn_id; tGATTS_DATA* p_data; } tBTA_GATTS_REQ; @@ -377,23 +377,23 @@ typedef struct { typedef struct { tGATT_IF server_if; RawAddress remote_bda; - uint16_t conn_id; + tCONN_ID conn_id; tBT_TRANSPORT transport; } tBTA_GATTS_CONN; typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; bool congested; /* report channel congestion indicator */ } tBTA_GATTS_CONGEST; typedef struct { - uint16_t conn_id; /* connection ID */ + tCONN_ID conn_id; /* connection ID */ tGATT_STATUS status; /* notification/indication status */ } tBTA_GATTS_CONF; typedef struct { tGATT_IF server_if; - uint16_t conn_id; + tCONN_ID conn_id; uint8_t tx_phy; uint8_t rx_phy; tGATT_STATUS status; @@ -401,7 +401,7 @@ typedef struct { typedef struct { tGATT_IF server_if; - uint16_t conn_id; + tCONN_ID conn_id; uint16_t interval; uint16_t latency; uint16_t timeout; @@ -410,7 +410,7 @@ typedef struct { typedef struct { tGATT_IF server_if; - uint16_t conn_id; + tCONN_ID conn_id; uint16_t subrate_factor; uint16_t latency; uint16_t cont_num; @@ -533,7 +533,7 @@ void BTA_GATTC_CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda, bool * Returns void * ******************************************************************************/ -void BTA_GATTC_Close(uint16_t conn_id); +void BTA_GATTC_Close(tCONN_ID conn_id); /******************************************************************************* * @@ -549,7 +549,7 @@ void BTA_GATTC_Close(uint16_t conn_id); * Returns None * ******************************************************************************/ -void BTA_GATTC_ServiceSearchAllRequest(uint16_t conn_id); +void BTA_GATTC_ServiceSearchAllRequest(tCONN_ID conn_id); /******************************************************************************* * @@ -566,13 +566,13 @@ void BTA_GATTC_ServiceSearchAllRequest(uint16_t conn_id); * Returns None * ******************************************************************************/ -void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id, bluetooth::Uuid p_srvc_uuid); +void BTA_GATTC_ServiceSearchRequest(tCONN_ID conn_id, bluetooth::Uuid p_srvc_uuid); /** * This function is called to send "Find service by UUID" request. Used only for * PTS tests. */ -void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id, const bluetooth::Uuid& srvc_uuid); +void BTA_GATTC_DiscoverServiceByUuid(tCONN_ID conn_id, const bluetooth::Uuid& srvc_uuid); /******************************************************************************* * @@ -586,7 +586,7 @@ void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id, const bluetooth::Uuid& sr * Returns returns list of gatt::Service or NULL. * ******************************************************************************/ -const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id); +const std::list<gatt::Service>* BTA_GATTC_GetServices(tCONN_ID conn_id); /******************************************************************************* * @@ -601,7 +601,7 @@ const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id); * Returns returns pointer to gatt::Characteristic or NULL. * ******************************************************************************/ -const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id, uint16_t handle); +const gatt::Characteristic* BTA_GATTC_GetCharacteristic(tCONN_ID conn_id, uint16_t handle); /******************************************************************************* * @@ -616,15 +616,15 @@ const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id, uint16 * Returns returns pointer to gatt::Descriptor or NULL. * ******************************************************************************/ -const gatt::Descriptor* BTA_GATTC_GetDescriptor(uint16_t conn_id, uint16_t handle); +const gatt::Descriptor* BTA_GATTC_GetDescriptor(tCONN_ID conn_id, uint16_t handle); /* Return characteristic that owns descriptor with handle equal to |handle|, or * NULL */ -const gatt::Characteristic* BTA_GATTC_GetOwningCharacteristic(uint16_t conn_id, uint16_t handle); +const gatt::Characteristic* BTA_GATTC_GetOwningCharacteristic(tCONN_ID conn_id, uint16_t handle); /* Return service that owns descriptor or characteristic with handle equal to * |handle|, or NULL */ -const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id, uint16_t handle); +const gatt::Service* BTA_GATTC_GetOwningService(tCONN_ID conn_id, uint16_t handle); /******************************************************************************* * @@ -638,15 +638,15 @@ const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id, uint16_t handl * count: number of elements in db. * ******************************************************************************/ -void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, +void BTA_GATTC_GetGattDb(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle, btgatt_db_element_t** db, int* count); -typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +typedef void (*GATT_READ_OP_CB)(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data); -typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, +typedef void (*GATT_WRITE_OP_CB)(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data); -typedef void (*GATT_CONFIGURE_MTU_OP_CB)(uint16_t conn_id, tGATT_STATUS status, void* data); -typedef void (*GATT_READ_MULTI_OP_CB)(uint16_t conn_id, tGATT_STATUS status, +typedef void (*GATT_CONFIGURE_MTU_OP_CB)(tCONN_ID conn_id, tGATT_STATUS status, void* data); +typedef void (*GATT_READ_MULTI_OP_CB)(tCONN_ID conn_id, tGATT_STATUS status, tBTA_GATTC_MULTI& handles, uint16_t len, uint8_t* value, void* data); /******************************************************************************* @@ -661,14 +661,14 @@ typedef void (*GATT_READ_MULTI_OP_CB)(uint16_t conn_id, tGATT_STATUS status, * Returns None * ******************************************************************************/ -void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, +void BTA_GATTC_ReadCharacteristic(tCONN_ID conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback, void* cb_data); /** * This function is called to read a value of characteristic with uuid equal to * |uuid| */ -void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, const bluetooth::Uuid& uuid, uint16_t s_handle, +void BTA_GATTC_ReadUsingCharUuid(tCONN_ID conn_id, const bluetooth::Uuid& uuid, uint16_t s_handle, uint16_t e_handle, tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback, void* cb_data); @@ -684,7 +684,7 @@ void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, const bluetooth::Uuid& uuid, * Returns None * ******************************************************************************/ -void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, +void BTA_GATTC_ReadCharDescr(tCONN_ID conn_id, uint16_t handle, tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback, void* cb_data); /******************************************************************************* @@ -701,7 +701,7 @@ void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle, tGATT_AUTH_REQ a * Returns None * ******************************************************************************/ -void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle, tGATT_WRITE_TYPE write_type, +void BTA_GATTC_WriteCharValue(tCONN_ID conn_id, uint16_t handle, tGATT_WRITE_TYPE write_type, std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req, GATT_WRITE_OP_CB callback, void* cb_data); @@ -718,7 +718,7 @@ void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle, tGATT_WRITE_TYP * Returns None * ******************************************************************************/ -void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, +void BTA_GATTC_WriteCharDescr(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req, GATT_WRITE_OP_CB callback, void* cb_data); /******************************************************************************* @@ -733,7 +733,7 @@ void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle, std::vector<uin * Returns None * ******************************************************************************/ -void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t cid); +void BTA_GATTC_SendIndConfirm(tCONN_ID conn_id, uint16_t cid); /******************************************************************************* * @@ -784,7 +784,7 @@ tGATT_STATUS BTA_GATTC_DeregisterForNotifications(tGATT_IF client_if, const RawA * Returns None * ******************************************************************************/ -void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle, uint16_t offset, +void BTA_GATTC_PrepareWrite(tCONN_ID conn_id, uint16_t handle, uint16_t offset, std::vector<uint8_t> value, tGATT_AUTH_REQ auth_req, GATT_WRITE_OP_CB callback, void* cb_data); @@ -801,7 +801,7 @@ void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle, uint16_t offset, * Returns None * ******************************************************************************/ -void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute); +void BTA_GATTC_ExecuteWrite(tCONN_ID conn_id, bool is_execute); /******************************************************************************* * @@ -818,7 +818,7 @@ void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute); * Returns None * ******************************************************************************/ -void BTA_GATTC_ReadMultiple(uint16_t conn_id, tBTA_GATTC_MULTI& p_read_multi, bool variable_len, +void BTA_GATTC_ReadMultiple(tCONN_ID conn_id, tBTA_GATTC_MULTI& p_read_multi, bool variable_len, tGATT_AUTH_REQ auth_req, GATT_READ_MULTI_OP_CB callback, void* cb_data); /******************************************************************************* @@ -847,8 +847,8 @@ void BTA_GATTC_Refresh(const RawAddress& remote_bda); * Returns void * ******************************************************************************/ -void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu); -void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu, GATT_CONFIGURE_MTU_OP_CB callback, +void BTA_GATTC_ConfigureMTU(tCONN_ID conn_id, uint16_t mtu); +void BTA_GATTC_ConfigureMTU(tCONN_ID conn_id, uint16_t mtu, GATT_CONFIGURE_MTU_OP_CB callback, void* cb_data); /******************************************************************************* @@ -977,7 +977,7 @@ void BTA_GATTS_StopService(uint16_t service_id); * Returns None * ******************************************************************************/ -void BTA_GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_id, std::vector<uint8_t> value, +void BTA_GATTS_HandleValueIndication(tCONN_ID conn_id, uint16_t attr_id, std::vector<uint8_t> value, bool need_confirm); /******************************************************************************* @@ -994,7 +994,7 @@ void BTA_GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_id, std::ve * Returns None * ******************************************************************************/ -void BTA_GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, tGATT_STATUS status, tGATTS_RSP* p_msg); +void BTA_GATTS_SendRsp(tCONN_ID conn_id, uint32_t trans_id, tGATT_STATUS status, tGATTS_RSP* p_msg); /******************************************************************************* * @@ -1042,7 +1042,7 @@ void BTA_GATTS_CancelOpen(tGATT_IF server_if, const RawAddress& remote_bda, bool * Returns void * ******************************************************************************/ -void BTA_GATTS_Close(uint16_t conn_id); +void BTA_GATTS_Close(tCONN_ID conn_id); // Adds bonded device for GATT server tracking service changes void BTA_GATTS_InitBonded(void); diff --git a/system/bta/include/bta_gatt_queue.h b/system/bta/include/bta_gatt_queue.h index 1cefb605da..0f01f053cf 100644 --- a/system/bta/include/bta_gatt_queue.h +++ b/system/bta/include/bta_gatt_queue.h @@ -35,20 +35,20 @@ */ class BtaGattQueue { public: - static void Clean(uint16_t conn_id); - static void ReadCharacteristic(uint16_t conn_id, uint16_t handle, GATT_READ_OP_CB cb, + static void Clean(tCONN_ID conn_id); + static void ReadCharacteristic(tCONN_ID conn_id, uint16_t handle, GATT_READ_OP_CB cb, void* cb_data); - static void ReadDescriptor(uint16_t conn_id, uint16_t handle, GATT_READ_OP_CB cb, void* cb_data); - static void WriteCharacteristic(uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, + static void ReadDescriptor(tCONN_ID conn_id, uint16_t handle, GATT_READ_OP_CB cb, void* cb_data); + static void WriteCharacteristic(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data); - static void WriteDescriptor(uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, + static void WriteDescriptor(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data); - static void ConfigureMtu(uint16_t conn_id, uint16_t mtu); + static void ConfigureMtu(tCONN_ID conn_id, uint16_t mtu); /* This method uses "Read Multiple Variable Length Characteristic Values". * If EATT is not enabled on remote, it would send multiple regular Characteristic Reads, and * concatenate their values into Length Value Tuple List */ - static void ReadMultiCharacteristic(uint16_t conn_id, tBTA_GATTC_MULTI& p_read_multi, + static void ReadMultiCharacteristic(tCONN_ID conn_id, tBTA_GATTC_MULTI& p_read_multi, GATT_READ_MULTI_OP_CB cb, void* cb_data); /* Holds pending GATT operations */ @@ -70,20 +70,20 @@ public: }; private: - static void mark_as_not_executing(uint16_t conn_id); - static void gatt_execute_next_op(uint16_t conn_id); - static void gatt_read_op_finished(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void mark_as_not_executing(tCONN_ID conn_id); + static void gatt_execute_next_op(tCONN_ID conn_id); + static void gatt_read_op_finished(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data); - static void gatt_write_op_finished(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void gatt_write_op_finished(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data); - static void gatt_configure_mtu_op_finished(uint16_t conn_id, tGATT_STATUS status, void* data); - static void gatt_read_multi_op_finished(uint16_t conn_id, tGATT_STATUS status, + static void gatt_configure_mtu_op_finished(tCONN_ID conn_id, tGATT_STATUS status, void* data); + static void gatt_read_multi_op_finished(tCONN_ID conn_id, tGATT_STATUS status, tBTA_GATTC_MULTI& handle, uint16_t len, uint8_t* value, void* data); - static void gatt_read_multi_op_simulate(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void gatt_read_multi_op_simulate(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data_read); // maps connection id to operations waiting for execution - static std::unordered_map<uint16_t, std::list<gatt_operation>> gatt_op_queue; + static std::unordered_map<tCONN_ID, std::list<gatt_operation>> gatt_op_queue; // contain connection ids that currently execute operations - static std::unordered_set<uint16_t> gatt_op_queue_executing; + static std::unordered_set<tCONN_ID> gatt_op_queue_executing; }; diff --git a/system/bta/include/bta_gatt_server_queue.h b/system/bta/include/bta_gatt_server_queue.h index 91909a4085..37f1ffa65d 100644 --- a/system/bta/include/bta_gatt_server_queue.h +++ b/system/bta/include/bta_gatt_server_queue.h @@ -23,11 +23,11 @@ class BtaGattServerQueue { public: - static void Clean(uint16_t conn_id); - static void SendNotification(uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, + static void Clean(tCONN_ID conn_id); + static void SendNotification(tCONN_ID conn_id, uint16_t handle, std::vector<uint8_t> value, bool need_confirm); - static void NotificationCallback(uint16_t conn_id); - static void CongestionCallback(uint16_t conn_id, bool congested); + static void NotificationCallback(tCONN_ID conn_id); + static void CongestionCallback(tCONN_ID conn_id, bool congested); /* Holds pending GATT operations */ struct gatts_operation { @@ -39,15 +39,15 @@ public: private: static bool is_congested; - static void mark_as_not_executing(uint16_t conn_id); - static void gatts_execute_next_op(uint16_t conn_id); + static void mark_as_not_executing(tCONN_ID conn_id); + static void gatts_execute_next_op(tCONN_ID conn_id); // maps connection id to operations waiting for execution - static std::unordered_map<uint16_t, std::list<gatts_operation>> gatts_op_queue; + static std::unordered_map<tCONN_ID, std::list<gatts_operation>> gatts_op_queue; // maps connection id to congestion status of each device - static std::unordered_map<uint16_t, bool> congestion_queue; + static std::unordered_map<tCONN_ID, bool> congestion_queue; // contain connection ids that currently execute operations - static std::unordered_set<uint16_t> gatts_op_queue_executing; -};
\ No newline at end of file + static std::unordered_set<tCONN_ID> gatts_op_queue_executing; +}; diff --git a/system/bta/include/bta_hearing_aid_api.h b/system/bta/include/bta_hearing_aid_api.h index 3cd3461271..19e89f5489 100644 --- a/system/bta/include/bta_hearing_aid_api.h +++ b/system/bta/include/bta_hearing_aid_api.h @@ -27,6 +27,7 @@ #include <functional> #include <vector> +#include "stack/include/btm_ble_api_types.h" #include "stack/include/gap_api.h" #include "types/raw_address.h" @@ -131,7 +132,7 @@ struct HearingDevice { */ bool accepting_audio; - uint16_t conn_id; + tCONN_ID conn_id; uint16_t gap_handle; uint16_t audio_control_point_handle; uint16_t audio_status_handle; diff --git a/system/bta/le_audio/client.cc b/system/bta/le_audio/client.cc index 39520133e4..1f008014dc 100644 --- a/system/bta/le_audio/client.cc +++ b/system/bta/le_audio/client.cc @@ -1810,13 +1810,13 @@ public: /* This is a generic read/notify/indicate handler for gatt. Here messages * are dispatched to correct elements e.g. ASEs, PACs, audio locations etc. */ - void LeAudioCharValueHandle(uint16_t conn_id, uint16_t hdl, uint16_t len, uint8_t* value, + void LeAudioCharValueHandle(tCONN_ID conn_id, uint16_t hdl, uint16_t len, uint8_t* value, bool notify = false) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByConnId(conn_id); struct ase* ase; if (!leAudioDevice) { - log::error("no leAudioDevice assigned to connection id: {}", static_cast<int>(conn_id)); + log::error("no leAudioDevice assigned to connection id: {}", conn_id); return; } @@ -1997,7 +1997,7 @@ public: } } - void OnGattReadRsp(uint16_t conn_id, tGATT_STATUS status, uint16_t hdl, uint16_t len, + void OnGattReadRsp(tCONN_ID conn_id, tGATT_STATUS status, uint16_t hdl, uint16_t len, uint8_t* value, void* data) { LeAudioCharValueHandle(conn_id, hdl, len, value); } @@ -2039,7 +2039,7 @@ public: } } - void OnGattConnected(tGATT_STATUS status, uint16_t conn_id, tGATT_IF client_if, + void OnGattConnected(tGATT_STATUS status, tCONN_ID conn_id, tGATT_IF client_if, RawAddress address, tBT_TRANSPORT transport, uint16_t mtu) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByAddress(address); @@ -2396,7 +2396,7 @@ public: std::chrono::milliseconds(kCsisGroupMemberDelayMs)); } - void OnGattDisconnected(uint16_t conn_id, tGATT_IF client_if, RawAddress address, + void OnGattDisconnected(tCONN_ID conn_id, tGATT_IF client_if, RawAddress address, tGATT_DISCONN_REASON reason) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByConnId(conn_id); @@ -2492,7 +2492,7 @@ public: } } - bool subscribe_for_notification(uint16_t conn_id, const RawAddress& address, + bool subscribe_for_notification(tCONN_ID conn_id, const RawAddress& address, struct bluetooth::le_audio::types::hdl_pair handle_pair, bool gatt_register = true, bool write_ccc = true) { std::vector<uint8_t> value(2); @@ -2517,7 +2517,7 @@ public: BtaGattQueue::WriteDescriptor( conn_id, ccc_handle, std::move(value), GATT_WRITE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (instance) { instance->OnGattWriteCcc(conn_id, status, handle, data); @@ -2585,7 +2585,7 @@ public: btif_storage_leaudio_clear_service_data(address); } - void OnMtuChanged(uint16_t conn_id, uint16_t mtu) { + void OnMtuChanged(tCONN_ID conn_id, uint16_t mtu) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByConnId(conn_id); if (!leAudioDevice) { log::debug("Unknown connectect id {}", conn_id); @@ -2610,7 +2610,7 @@ public: leAudioDevice->mtu_ = mtu; } - void OnPhyUpdate(uint16_t conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status) { + void OnPhyUpdate(tCONN_ID conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByConnId(conn_id); if (leAudioDevice == nullptr) { log::debug("Unknown conn_id {:#x}", conn_id); @@ -2658,7 +2658,7 @@ public: * a le audio device. Any missing mandatory attribute will result in reverting * and cleaning up device. */ - void OnServiceSearchComplete(uint16_t conn_id, tGATT_STATUS status) { + void OnServiceSearchComplete(tCONN_ID conn_id, tGATT_STATUS status) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByConnId(conn_id); if (!leAudioDevice) { @@ -3014,7 +3014,7 @@ public: bluetooth::le_audio::uuid::kCapServiceUuid); } - void OnGattWriteCcc(uint16_t conn_id, tGATT_STATUS status, uint16_t hdl, void* data) { + void OnGattWriteCcc(tCONN_ID conn_id, tGATT_STATUS status, uint16_t hdl, void* data) { LeAudioDevice* leAudioDevice = leAudioDevices_.FindByConnId(conn_id); std::vector<struct ase>::iterator ase_it; @@ -4955,7 +4955,7 @@ public: return false; } - static void OnGattCtpCccReadRspStatic(uint16_t conn_id, tGATT_STATUS status, uint16_t hdl, + static void OnGattCtpCccReadRspStatic(tCONN_ID conn_id, tGATT_STATUS status, uint16_t hdl, uint16_t len, uint8_t* value, void* data) { if (!instance) { return; @@ -4991,7 +4991,7 @@ public: } } - static void OnGattReadRspStatic(uint16_t conn_id, tGATT_STATUS status, uint16_t hdl, uint16_t len, + static void OnGattReadRspStatic(tCONN_ID conn_id, tGATT_STATUS status, uint16_t hdl, uint16_t len, uint8_t* value, void* data) { if (!instance) { return; @@ -5027,7 +5027,7 @@ public: } } - static void OnGattReadMultiRspStatic(uint16_t conn_id, tGATT_STATUS status, + static void OnGattReadMultiRspStatic(tCONN_ID conn_id, tGATT_STATUS status, tBTA_GATTC_MULTI& handles, uint16_t total_len, uint8_t* value, void* data) { if (!instance) { diff --git a/system/bta/le_audio/devices.cc b/system/bta/le_audio/devices.cc index 2677492ba6..5b44b790c0 100644 --- a/system/bta/le_audio/devices.cc +++ b/system/bta/le_audio/devices.cc @@ -1258,7 +1258,7 @@ std::shared_ptr<LeAudioDevice> LeAudioDevices::GetByAddress(const RawAddress& ad return (iter == leAudioDevices_.end()) ? nullptr : *iter; } -LeAudioDevice* LeAudioDevices::FindByConnId(uint16_t conn_id) const { +LeAudioDevice* LeAudioDevices::FindByConnId(tCONN_ID conn_id) const { auto iter = std::find_if( leAudioDevices_.begin(), leAudioDevices_.end(), [&conn_id](auto const& leAudioDevice) { return leAudioDevice->conn_id_ == conn_id; }); diff --git a/system/bta/le_audio/devices.h b/system/bta/le_audio/devices.h index b921f4e2f5..d874e8dbdb 100644 --- a/system/bta/le_audio/devices.h +++ b/system/bta/le_audio/devices.h @@ -33,6 +33,7 @@ namespace bluetooth::le_audio { // Maps to BluetoothProfile#LE_AUDIO #define LE_AUDIO_PROFILE_CONSTANT 22 +#define LE_AUDIO_INVALID_CIS_HANDLE 0xFFFF /* Enums */ enum class DeviceConnectState : uint8_t { @@ -82,7 +83,7 @@ public: bool notify_connected_after_read_; bool closing_stream_for_disconnection_; bool autoconnect_flag_; - uint16_t conn_id_; + tCONN_ID conn_id_; uint16_t mtu_; bool encrypted_; int group_id_; @@ -132,7 +133,10 @@ public: acl_asymmetric_(false), acl_phy_update_done_(false), link_quality_timer(nullptr), - dsa_({{DsaMode::DISABLED}, types::DataPathState::IDLE, GATT_INVALID_CONN_ID, false}) {} + dsa_({{DsaMode::DISABLED}, + types::DataPathState::IDLE, + LE_AUDIO_INVALID_CIS_HANDLE, + false}) {} ~LeAudioDevice(void); void SetConnectionState(DeviceConnectState state); @@ -260,7 +264,7 @@ public: void Remove(const RawAddress& address); LeAudioDevice* FindByAddress(const RawAddress& address) const; std::shared_ptr<LeAudioDevice> GetByAddress(const RawAddress& address) const; - LeAudioDevice* FindByConnId(uint16_t conn_id) const; + LeAudioDevice* FindByConnId(tCONN_ID conn_id) const; LeAudioDevice* FindByCisConnHdl(uint8_t cig_id, uint16_t conn_hdl) const; void SetInitialGroupAutoconnectState(int group_id, int gatt_if, tBTM_BLE_CONN_TYPE reconnection_mode, diff --git a/system/bta/le_audio/state_machine.cc b/system/bta/le_audio/state_machine.cc index 2a1c5edede..3b8cfaa1eb 100644 --- a/system/bta/le_audio/state_machine.cc +++ b/system/bta/le_audio/state_machine.cc @@ -671,7 +671,7 @@ public: if (group->dsa_.active && leAudioDevice->GetDsaDataPathState() == DataPathState::REMOVING) { log::info("DSA data path removed"); leAudioDevice->SetDsaDataPathState(DataPathState::IDLE); - leAudioDevice->SetDsaCisHandle(GATT_INVALID_CONN_ID); + leAudioDevice->SetDsaCisHandle(LE_AUDIO_INVALID_CIS_HANDLE); } } diff --git a/system/bta/ras/ras_client.cc b/system/bta/ras/ras_client.cc index 5884aa2677..3ff402cfbc 100644 --- a/system/bta/ras/ras_client.cc +++ b/system/bta/ras/ras_client.cc @@ -56,7 +56,7 @@ public: struct RasTracker { RasTracker(const RawAddress& address, const RawAddress& address_for_cs) : address_(address), address_for_cs_(address_for_cs) {} - uint16_t conn_id_; + tCONN_ID conn_id_; RawAddress address_; RawAddress address_for_cs_; const gatt::Service* service_ = nullptr; @@ -264,7 +264,7 @@ public: vendor_specific_characteristic.characteristicUuid_); BTA_GATTC_ReadCharacteristic( tracker->conn_id_, characteristic->value_handle, GATT_AUTH_REQ_NO_MITM, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { instance->OnReadCharacteristicCallback(conn_id, status, handle, len, value, data); @@ -425,7 +425,7 @@ public: } } - void GattWriteCallbackForVendorSpecificData(uint16_t conn_id, tGATT_STATUS status, + void GattWriteCallbackForVendorSpecificData(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, const uint8_t* value, GattWriteCallbackData* data) { if (data != nullptr) { @@ -460,7 +460,7 @@ public: } } - void GattWriteCallback(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + void GattWriteCallback(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, const uint8_t* value) { if (status != GATT_SUCCESS) { log::error("Fail to write conn_id {}, status {}, handle {}", conn_id, @@ -484,7 +484,7 @@ public: } } - static void GattWriteCallback(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void GattWriteCallback(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (instance != nullptr) { if (data != nullptr) { @@ -528,7 +528,7 @@ public: } BTA_GATTC_WriteCharDescr( tracker->conn_id_, ccc_handle, value, GATT_AUTH_REQ_NONE, - [](uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (instance) { instance->OnDescriptorWrite(conn_id, status, handle, len, value, data); @@ -537,7 +537,7 @@ public: nullptr); } - void OnDescriptorWrite(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnDescriptorWrite(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { log::info("conn_id:{}, handle:{}, status:{}", conn_id, handle, gatt_status_text(status)); } @@ -571,7 +571,7 @@ public: maybe_resolve_address(&ble_bd_addr.bda, &ble_bd_addr.type); } - void OnReadCharacteristicCallback(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + void OnReadCharacteristicCallback(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { log::info("conn_id: {}, handle: {}, len: {}", conn_id, handle, len); if (status != GATT_SUCCESS) { @@ -703,7 +703,7 @@ public: return GAP_INVALID_HANDLE; } - std::shared_ptr<RasTracker> FindTrackerByHandle(uint16_t conn_id) const { + std::shared_ptr<RasTracker> FindTrackerByHandle(tCONN_ID conn_id) const { for (auto tracker : trackers_) { if (tracker->conn_id_ == conn_id) { return tracker; diff --git a/system/bta/ras/ras_server.cc b/system/bta/ras/ras_server.cc index 543b7359fb..a24863990f 100644 --- a/system/bta/ras/ras_server.cc +++ b/system/bta/ras/ras_server.cc @@ -57,13 +57,13 @@ public: }; struct PendingWriteResponse { - uint16_t conn_id_; + tCONN_ID conn_id_; uint32_t trans_id_; uint16_t write_req_handle_; }; struct ClientTracker { - uint16_t conn_id_; + tCONN_ID conn_id_; std::unordered_map<Uuid, uint16_t> ccc_values_; std::vector<DataBuffer> buffers_; bool handling_control_point_command_ = false; @@ -390,7 +390,7 @@ public: } void OnReadDescriptor(tBTA_GATTS* p_data) { - uint16_t conn_id = p_data->req_data.conn_id; + tCONN_ID conn_id = p_data->req_data.conn_id; uint16_t read_req_handle = p_data->req_data.p_data->read_req.handle; RawAddress remote_bda = p_data->req_data.remote_bda; log::info("conn_id:{}, read_req_handle:0x{:04x}", conn_id, read_req_handle); @@ -419,7 +419,7 @@ public: } void OnWriteCharacteristic(tBTA_GATTS* p_data) { - uint16_t conn_id = p_data->req_data.conn_id; + tCONN_ID conn_id = p_data->req_data.conn_id; uint16_t write_req_handle = p_data->req_data.p_data->write_req.handle; uint16_t len = p_data->req_data.p_data->write_req.len; bool need_rsp = p_data->req_data.p_data->write_req.need_rsp; @@ -510,7 +510,7 @@ public: } void OnWriteDescriptor(tBTA_GATTS* p_data) { - uint16_t conn_id = p_data->req_data.conn_id; + tCONN_ID conn_id = p_data->req_data.conn_id; uint16_t write_req_handle = p_data->req_data.p_data->write_req.handle; uint16_t len = p_data->req_data.p_data->write_req.len; RawAddress remote_bda = p_data->req_data.remote_bda; diff --git a/system/bta/vc/devices.h b/system/bta/vc/devices.h index 50058e50b5..3e810726cb 100644 --- a/system/bta/vc/devices.h +++ b/system/bta/vc/devices.h @@ -47,7 +47,7 @@ public: bool mute; uint8_t flags; - uint16_t connection_id; + tCONN_ID connection_id; /* Volume Control Service */ uint16_t volume_state_handle; @@ -94,7 +94,7 @@ public: if (connection_id == GATT_INVALID_CONN_ID) { stream << " Not connected\n"; } else { - stream << " Connected. Conn_id = " << connection_id << "\n"; + stream << " Connected. Conn_id = " << static_cast<int>(connection_id) << "\n"; } stream << " volume: " << +volume << "\n" @@ -196,7 +196,7 @@ public: return (iter == devices_.end()) ? nullptr : &(*iter); } - VolumeControlDevice* FindByConnId(uint16_t connection_id) { + VolumeControlDevice* FindByConnId(tCONN_ID connection_id) { auto iter = std::find_if(devices_.begin(), devices_.end(), [&connection_id](const VolumeControlDevice& device) { return device.connection_id == connection_id; diff --git a/system/bta/vc/vc.cc b/system/bta/vc/vc.cc index d4d3e1ab15..c00fa87293 100644 --- a/system/bta/vc/vc.cc +++ b/system/bta/vc/vc.cc @@ -164,7 +164,7 @@ public: StartOpportunisticConnect(address); } - void OnGattConnected(tGATT_STATUS status, uint16_t connection_id, tGATT_IF /*client_if*/, + void OnGattConnected(tGATT_STATUS status, tCONN_ID connection_id, tGATT_IF /*client_if*/, RawAddress address, tBT_TRANSPORT transport, uint16_t /*mtu*/) { bluetooth::log::info("{}, conn_id=0x{:04x}, transport={}, status={}(0x{:02x})", address, connection_id, bt_transport_text(transport), gatt_status_text(status), @@ -276,7 +276,7 @@ public: } } - void OnServiceSearchComplete(uint16_t connection_id, tGATT_STATUS status) { + void OnServiceSearchComplete(tCONN_ID connection_id, tGATT_STATUS status) { VolumeControlDevice* device = volume_control_devices_.FindByConnId(connection_id); if (!device) { bluetooth::log::error("Skipping unknown device, connection_id={:#x}", connection_id); @@ -310,7 +310,7 @@ public: device->EnqueueInitialRequests(gatt_if_, chrc_read_callback_static, OnGattWriteCccStatic); } - void OnCharacteristicValueChanged(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + void OnCharacteristicValueChanged(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data, bool is_notification) { VolumeControlDevice* device = volume_control_devices_.FindByConnId(conn_id); @@ -385,12 +385,12 @@ public: bluetooth::log::error("{}, unknown handle={:#x}", device->address, handle); } - void OnNotificationEvent(uint16_t conn_id, uint16_t handle, uint16_t len, uint8_t* value) { + void OnNotificationEvent(tCONN_ID conn_id, uint16_t handle, uint16_t len, uint8_t* value) { bluetooth::log::info("connection_id={:#x}, handle={:#x}", conn_id, handle); OnCharacteristicValueChanged(conn_id, GATT_SUCCESS, handle, len, value, nullptr, true); } - void VolumeControlReadCommon(uint16_t conn_id, uint16_t handle) { + void VolumeControlReadCommon(tCONN_ID conn_id, uint16_t handle) { BtaGattQueue::ReadCharacteristic(conn_id, handle, chrc_read_callback_static, nullptr); } @@ -705,7 +705,7 @@ public: input->gain_settings.min, input->gain_settings.max); } - void OnExtAudioOutCPWrite(uint16_t connection_id, tGATT_STATUS status, uint16_t handle, + void OnExtAudioOutCPWrite(tCONN_ID connection_id, tGATT_STATUS status, uint16_t handle, void* /*data*/) { VolumeControlDevice* device = volume_control_devices_.FindByConnId(connection_id); if (!device) { @@ -740,7 +740,7 @@ public: callbacks_->OnExtAudioOutDescriptionChanged(device->address, offset->id, offset->description); } - void OnGattWriteCcc(uint16_t connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + void OnGattWriteCcc(tCONN_ID connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* /*data*/) { VolumeControlDevice* device = volume_control_devices_.FindByConnId(connection_id); if (!device) { @@ -768,7 +768,7 @@ public: verify_device_ready(device, handle); } - static void OnGattWriteCccStatic(uint16_t connection_id, tGATT_STATUS status, uint16_t handle, + static void OnGattWriteCccStatic(tCONN_ID connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (!instance) { bluetooth::log::error("connection_id={:#x}, no instance. Handle to write={:#x}", @@ -809,7 +809,7 @@ public: volume_control_devices_.Remove(address); } - void OnGattDisconnected(uint16_t connection_id, tGATT_IF /*client_if*/, RawAddress remote_bda, + void OnGattDisconnected(tCONN_ID connection_id, tGATT_IF /*client_if*/, RawAddress remote_bda, tGATT_DISCONN_REASON reason) { VolumeControlDevice* device = volume_control_devices_.FindByConnId(connection_id); if (!device) { @@ -912,7 +912,7 @@ public: } } - void OnWriteControlResponse(uint16_t connection_id, tGATT_STATUS status, uint16_t handle, + void OnWriteControlResponse(tCONN_ID connection_id, tGATT_STATUS status, uint16_t handle, void* data) { VolumeControlDevice* device = volume_control_devices_.FindByConnId(connection_id); if (!device) { @@ -1364,7 +1364,7 @@ private: const std::vector<uint8_t>* arg, int operation_id = -1) { volume_control_devices_.ControlPointOperation( devices, opcode, arg, - [](uint16_t connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (instance) { instance->OnWriteControlResponse(connection_id, status, handle, data); @@ -1404,7 +1404,7 @@ private: } device->ExtAudioOutControlPointOperation( ext_output_id, opcode, arg, - [](uint16_t connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, + [](tCONN_ID connection_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* data) { if (instance) { instance->OnExtAudioOutCPWrite(connection_id, status, handle, data); @@ -1474,7 +1474,7 @@ private: } } - static void chrc_read_callback_static(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, + static void chrc_read_callback_static(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* data) { if (instance) { instance->OnCharacteristicValueChanged(conn_id, status, handle, len, value, data, false); diff --git a/system/btif/src/btif_gatt_client.cc b/system/btif/src/btif_gatt_client.cc index 138c4a2712..bed322206b 100644 --- a/system/btif/src/btif_gatt_client.cc +++ b/system/btif/src/btif_gatt_client.cc @@ -76,7 +76,7 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks; typedef struct { tGATT_IF gatt_if; - uint16_t conn_id; + tCONN_ID conn_id; } btif_test_cb_t; static const char* disc_name[GATT_DISC_MAX] = { @@ -146,14 +146,14 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { tBTA_GATTC* p_data = (tBTA_GATTC*)p_param; switch (event) { case BTA_GATTC_EXEC_EVT: { - HAL_CBACK(callbacks, client->execute_write_cb, p_data->exec_cmpl.conn_id, + HAL_CBACK(callbacks, client->execute_write_cb, static_cast<int>(p_data->exec_cmpl.conn_id), p_data->exec_cmpl.status); break; } case BTA_GATTC_SEARCH_CMPL_EVT: { - HAL_CBACK(callbacks, client->search_complete_cb, p_data->search_cmpl.conn_id, - p_data->search_cmpl.status); + HAL_CBACK(callbacks, client->search_complete_cb, + static_cast<int>(p_data->search_cmpl.conn_id), p_data->search_cmpl.status); break; } @@ -167,7 +167,7 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { data.is_notify = p_data->notify.is_notify; data.len = p_data->notify.len; - HAL_CBACK(callbacks, client->notify_cb, p_data->notify.conn_id, data); + HAL_CBACK(callbacks, client->notify_cb, static_cast<int>(p_data->notify.conn_id), data); if (!p_data->notify.is_notify) { BTA_GATTC_SendIndConfirm(p_data->notify.conn_id, p_data->notify.cid); @@ -178,12 +178,12 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { case BTA_GATTC_OPEN_EVT: { log::debug("BTA_GATTC_OPEN_EVT {}", p_data->open.remote_bda); - HAL_CBACK(callbacks, client->open_cb, p_data->open.conn_id, p_data->open.status, - p_data->open.client_if, p_data->open.remote_bda); + HAL_CBACK(callbacks, client->open_cb, static_cast<int>(p_data->open.conn_id), + p_data->open.status, p_data->open.client_if, p_data->open.remote_bda); if (GATT_DEF_BLE_MTU_SIZE != p_data->open.mtu && p_data->open.mtu) { - HAL_CBACK(callbacks, client->configure_mtu_cb, p_data->open.conn_id, p_data->open.status, - p_data->open.mtu); + HAL_CBACK(callbacks, client->configure_mtu_cb, static_cast<int>(p_data->open.conn_id), + p_data->open.status, p_data->open.mtu); } if (p_data->open.status == GATT_SUCCESS) { @@ -194,8 +194,8 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { case BTA_GATTC_CLOSE_EVT: { log::debug("BTA_GATTC_CLOSE_EVT {}", p_data->close.remote_bda); - HAL_CBACK(callbacks, client->close_cb, p_data->close.conn_id, p_data->close.status, - p_data->close.client_if, p_data->close.remote_bda); + HAL_CBACK(callbacks, client->close_cb, static_cast<int>(p_data->close.conn_id), + p_data->close.status, p_data->close.client_if, p_data->close.remote_bda); break; } @@ -207,33 +207,34 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { break; case BTA_GATTC_CFG_MTU_EVT: { - HAL_CBACK(callbacks, client->configure_mtu_cb, p_data->cfg_mtu.conn_id, + HAL_CBACK(callbacks, client->configure_mtu_cb, static_cast<int>(p_data->cfg_mtu.conn_id), p_data->cfg_mtu.status, p_data->cfg_mtu.mtu); break; } case BTA_GATTC_CONGEST_EVT: - HAL_CBACK(callbacks, client->congestion_cb, p_data->congest.conn_id, + HAL_CBACK(callbacks, client->congestion_cb, static_cast<int>(p_data->congest.conn_id), p_data->congest.congested); break; case BTA_GATTC_PHY_UPDATE_EVT: - HAL_CBACK(callbacks, client->phy_updated_cb, p_data->phy_update.conn_id, + HAL_CBACK(callbacks, client->phy_updated_cb, static_cast<int>(p_data->phy_update.conn_id), p_data->phy_update.tx_phy, p_data->phy_update.rx_phy, p_data->phy_update.status); break; case BTA_GATTC_CONN_UPDATE_EVT: - HAL_CBACK(callbacks, client->conn_updated_cb, p_data->conn_update.conn_id, + HAL_CBACK(callbacks, client->conn_updated_cb, static_cast<int>(p_data->conn_update.conn_id), p_data->conn_update.interval, p_data->conn_update.latency, p_data->conn_update.timeout, p_data->conn_update.status); break; case BTA_GATTC_SRVC_CHG_EVT: - HAL_CBACK(callbacks, client->service_changed_cb, p_data->service_changed.conn_id); + HAL_CBACK(callbacks, client->service_changed_cb, + static_cast<int>(p_data->service_changed.conn_id)); break; case BTA_GATTC_SUBRATE_CHG_EVT: - HAL_CBACK(callbacks, client->subrate_chg_cb, p_data->subrate_chg.conn_id, + HAL_CBACK(callbacks, client->subrate_chg_cb, static_cast<int>(p_data->subrate_chg.conn_id), p_data->subrate_chg.subrate_factor, p_data->subrate_chg.latency, p_data->subrate_chg.cont_num, p_data->subrate_chg.timeout, p_data->subrate_chg.status); @@ -373,7 +374,7 @@ void btif_gattc_close_impl(int client_if, RawAddress address, int conn_id) { log::info("client_if={}, conn_id={}, address={}", client_if, conn_id, address); // Disconnect established connections if (conn_id != 0) { - BTA_GATTC_Close(conn_id); + BTA_GATTC_Close(static_cast<tCONN_ID>(conn_id)); } else { BTA_GATTC_CancelOpen(client_if, address, true); } @@ -396,20 +397,22 @@ static bt_status_t btif_gattc_search_service(int conn_id, const Uuid* filter_uui CHECK_BTGATT_INIT(); if (filter_uuid) { - return do_in_jni_thread(Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, *filter_uuid)); + return do_in_jni_thread( + Bind(&BTA_GATTC_ServiceSearchRequest, static_cast<tCONN_ID>(conn_id), *filter_uuid)); } else { - return do_in_jni_thread(Bind(&BTA_GATTC_ServiceSearchAllRequest, conn_id)); + return do_in_jni_thread( + Bind(&BTA_GATTC_ServiceSearchAllRequest, static_cast<tCONN_ID>(conn_id))); } } static void btif_gattc_discover_service_by_uuid(int conn_id, const Uuid& uuid) { - do_in_jni_thread(Bind(&BTA_GATTC_DiscoverServiceByUuid, conn_id, uuid)); + do_in_jni_thread(Bind(&BTA_GATTC_DiscoverServiceByUuid, static_cast<tCONN_ID>(conn_id), uuid)); } void btif_gattc_get_gatt_db_impl(int conn_id) { btgatt_db_element_t* db = NULL; int count = 0; - BTA_GATTC_GetGattDb(conn_id, 0x0000, 0xFFFF, &db, &count); + BTA_GATTC_GetGattDb(static_cast<tCONN_ID>(conn_id), 0x0000, 0xFFFF, &db, &count); auto callbacks = bt_gatt_callbacks; HAL_CBACK(callbacks, client->get_gatt_db_cb, conn_id, db, count); @@ -439,11 +442,11 @@ void read_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16 static bt_status_t btif_gattc_read_char(int conn_id, uint16_t handle, int auth_req) { CHECK_BTGATT_INIT(); - return do_in_jni_thread( - Bind(&BTA_GATTC_ReadCharacteristic, conn_id, handle, auth_req, read_char_cb, nullptr)); + return do_in_jni_thread(Bind(&BTA_GATTC_ReadCharacteristic, static_cast<tCONN_ID>(conn_id), + handle, auth_req, read_char_cb, nullptr)); } -void read_using_char_uuid_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, +void read_using_char_uuid_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* /* data */) { btgatt_read_params_t params = { .handle = handle, @@ -456,17 +459,17 @@ void read_using_char_uuid_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t han memcpy(params.value.value, value, len); } - CLI_CBACK_IN_JNI(read_characteristic_cb, conn_id, status, params); + CLI_CBACK_IN_JNI(read_characteristic_cb, static_cast<int>(conn_id), status, params); } static bt_status_t btif_gattc_read_using_char_uuid(int conn_id, const Uuid& uuid, uint16_t s_handle, uint16_t e_handle, int auth_req) { CHECK_BTGATT_INIT(); - return do_in_jni_thread(Bind(&BTA_GATTC_ReadUsingCharUuid, conn_id, uuid, s_handle, e_handle, - auth_req, read_using_char_uuid_cb, nullptr)); + return do_in_jni_thread(Bind(&BTA_GATTC_ReadUsingCharUuid, static_cast<tCONN_ID>(conn_id), uuid, + s_handle, e_handle, auth_req, read_using_char_uuid_cb, nullptr)); } -void read_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, +void read_desc_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, uint8_t* value, void* /* data */) { btgatt_read_params_t params; params.value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; @@ -477,24 +480,25 @@ void read_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16 if (len > 0) { memcpy(params.value.value, value, len); } - CLI_CBACK_IN_JNI(read_descriptor_cb, conn_id, status, params); + CLI_CBACK_IN_JNI(read_descriptor_cb, static_cast<int>(conn_id), status, params); } static bt_status_t btif_gattc_read_char_descr(int conn_id, uint16_t handle, int auth_req) { CHECK_BTGATT_INIT(); - return do_in_jni_thread( - Bind(&BTA_GATTC_ReadCharDescr, conn_id, handle, auth_req, read_desc_cb, nullptr)); + return do_in_jni_thread(Bind(&BTA_GATTC_ReadCharDescr, static_cast<tCONN_ID>(conn_id), handle, + auth_req, read_desc_cb, nullptr)); } -void write_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, +void write_char_cb(tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, const uint8_t* value, void* /* data */) { std::vector<uint8_t> val(value, value + len); CLI_CBACK_WRAP_IN_JNI( write_characteristic_cb, base::BindOnce( - [](write_characteristic_callback cb, uint16_t conn_id, tGATT_STATUS status, + [](write_characteristic_callback cb, tCONN_ID conn_id, tGATT_STATUS status, uint16_t handle, std::vector<uint8_t> moved_value) { - cb(conn_id, status, handle, moved_value.size(), moved_value.data()); + cb(static_cast<int>(conn_id), status, handle, moved_value.size(), + moved_value.data()); }, bt_gatt_callbacks->client->write_characteristic_cb, conn_id, status, handle, std::move(val))); @@ -510,8 +514,8 @@ static bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle, int write value.resize(GATT_MAX_ATTR_LEN); } - return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharValue, conn_id, handle, write_type, - std::move(value), auth_req, write_char_cb, nullptr)); + return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharValue, static_cast<tCONN_ID>(conn_id), handle, + write_type, std::move(value), auth_req, write_char_cb, nullptr)); } void write_descr_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, uint16_t len, @@ -539,13 +543,14 @@ static bt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle, int value.resize(GATT_MAX_ATTR_LEN); } - return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharDescr, conn_id, handle, std::move(value), - auth_req, write_descr_cb, nullptr)); + return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharDescr, static_cast<tCONN_ID>(conn_id), handle, + std::move(value), auth_req, write_descr_cb, nullptr)); } static bt_status_t btif_gattc_execute_write(int conn_id, int execute) { CHECK_BTGATT_INIT(); - return do_in_jni_thread(Bind(&BTA_GATTC_ExecuteWrite, conn_id, (uint8_t)execute)); + return do_in_jni_thread( + Bind(&BTA_GATTC_ExecuteWrite, static_cast<tCONN_ID>(conn_id), (uint8_t)execute)); } static void btif_gattc_reg_for_notification_impl(tGATT_IF client_if, const RawAddress& bda, @@ -601,8 +606,8 @@ static bt_status_t btif_gattc_read_remote_rssi(int client_if, const RawAddress& static bt_status_t btif_gattc_configure_mtu(int conn_id, int mtu) { CHECK_BTGATT_INIT(); return do_in_jni_thread(Bind( - base::IgnoreResult(static_cast<void (*)(uint16_t, uint16_t)>(&BTA_GATTC_ConfigureMTU)), - conn_id, mtu)); + base::IgnoreResult(static_cast<void (*)(tCONN_ID, uint16_t)>(&BTA_GATTC_ConfigureMTU)), + static_cast<tCONN_ID>(conn_id), mtu)); } static void btif_gattc_conn_parameter_update_impl(RawAddress addr, int min_interval, @@ -672,13 +677,13 @@ static bt_status_t btif_gattc_subrate_request(const RawAddress& bd_addr, int sub subrate_min, subrate_max, max_latency, cont_num, sup_timeout)); } -static void btif_test_connect_cback(tGATT_IF, const RawAddress&, uint16_t conn_id, bool connected, +static void btif_test_connect_cback(tGATT_IF, const RawAddress&, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON, tBT_TRANSPORT) { log::info("conn_id={}, connected={}", conn_id, connected); test_cb.conn_id = connected ? conn_id : 0; } -static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op, +static void btif_test_command_complete_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { log::info("op_code=0x{:02x}, conn_id=0x{:x}. status=0x{:x}", op, conn_id, status); @@ -705,7 +710,7 @@ static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op, } } -static void btif_test_discovery_result_cback(uint16_t /* conn_id */, tGATT_DISC_TYPE disc_type, +static void btif_test_discovery_result_cback(tCONN_ID /* conn_id */, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data) { log::info("------ GATT Discovery result {:<22s} -------", disc_name[disc_type]); log::info("Attribute handle: 0x{:04x} ({})", p_data->handle, p_data->handle); @@ -750,7 +755,7 @@ static void btif_test_discovery_result_cback(uint16_t /* conn_id */, tGATT_DISC_ log::info("-----------------------------------------------------------"); } -static void btif_test_discovery_complete_cback(uint16_t /* conn_id */, +static void btif_test_discovery_complete_cback(tCONN_ID /* conn_id */, tGATT_DISC_TYPE /* disc_type */, tGATT_STATUS status) { log::info("status={}", status); diff --git a/system/btif/src/btif_gatt_server.cc b/system/btif/src/btif_gatt_server.cc index 3714269c23..653384aff5 100644 --- a/system/btif/src/btif_gatt_server.cc +++ b/system/btif/src/btif_gatt_server.cc @@ -162,14 +162,14 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { case BTA_GATTS_CONNECT_EVT: { btif_gatt_check_encrypted_link(p_data->conn.remote_bda, p_data->conn.transport); - HAL_CBACK(callbacks, server->connection_cb, p_data->conn.conn_id, p_data->conn.server_if, - true, p_data->conn.remote_bda); + HAL_CBACK(callbacks, server->connection_cb, static_cast<int>(p_data->conn.conn_id), + p_data->conn.server_if, true, p_data->conn.remote_bda); break; } case BTA_GATTS_DISCONNECT_EVT: { - HAL_CBACK(callbacks, server->connection_cb, p_data->conn.conn_id, p_data->conn.server_if, - false, p_data->conn.remote_bda); + HAL_CBACK(callbacks, server->connection_cb, static_cast<int>(p_data->conn.conn_id), + p_data->conn.server_if, false, p_data->conn.remote_bda); break; } @@ -184,56 +184,60 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { break; case BTA_GATTS_READ_CHARACTERISTIC_EVT: { - HAL_CBACK(callbacks, server->request_read_characteristic_cb, p_data->req_data.conn_id, - p_data->req_data.trans_id, p_data->req_data.remote_bda, - p_data->req_data.p_data->read_req.handle, p_data->req_data.p_data->read_req.offset, + HAL_CBACK(callbacks, server->request_read_characteristic_cb, + static_cast<int>(p_data->req_data.conn_id), p_data->req_data.trans_id, + p_data->req_data.remote_bda, p_data->req_data.p_data->read_req.handle, + p_data->req_data.p_data->read_req.offset, p_data->req_data.p_data->read_req.is_long); break; } case BTA_GATTS_READ_DESCRIPTOR_EVT: { - HAL_CBACK(callbacks, server->request_read_descriptor_cb, p_data->req_data.conn_id, - p_data->req_data.trans_id, p_data->req_data.remote_bda, - p_data->req_data.p_data->read_req.handle, p_data->req_data.p_data->read_req.offset, + HAL_CBACK(callbacks, server->request_read_descriptor_cb, + static_cast<int>(p_data->req_data.conn_id), p_data->req_data.trans_id, + p_data->req_data.remote_bda, p_data->req_data.p_data->read_req.handle, + p_data->req_data.p_data->read_req.offset, p_data->req_data.p_data->read_req.is_long); break; } case BTA_GATTS_WRITE_CHARACTERISTIC_EVT: { const auto& req = p_data->req_data.p_data->write_req; - HAL_CBACK(callbacks, server->request_write_characteristic_cb, p_data->req_data.conn_id, - p_data->req_data.trans_id, p_data->req_data.remote_bda, req.handle, req.offset, - req.need_rsp, req.is_prep, req.value, req.len); + HAL_CBACK(callbacks, server->request_write_characteristic_cb, + static_cast<int>(p_data->req_data.conn_id), p_data->req_data.trans_id, + p_data->req_data.remote_bda, req.handle, req.offset, req.need_rsp, req.is_prep, + req.value, req.len); break; } case BTA_GATTS_WRITE_DESCRIPTOR_EVT: { const auto& req = p_data->req_data.p_data->write_req; - HAL_CBACK(callbacks, server->request_write_descriptor_cb, p_data->req_data.conn_id, - p_data->req_data.trans_id, p_data->req_data.remote_bda, req.handle, req.offset, - req.need_rsp, req.is_prep, req.value, req.len); + HAL_CBACK(callbacks, server->request_write_descriptor_cb, + static_cast<int>(p_data->req_data.conn_id), p_data->req_data.trans_id, + p_data->req_data.remote_bda, req.handle, req.offset, req.need_rsp, req.is_prep, + req.value, req.len); break; } case BTA_GATTS_EXEC_WRITE_EVT: { - HAL_CBACK(callbacks, server->request_exec_write_cb, p_data->req_data.conn_id, - p_data->req_data.trans_id, p_data->req_data.remote_bda, - p_data->req_data.p_data->exec_write); + HAL_CBACK(callbacks, server->request_exec_write_cb, + static_cast<int>(p_data->req_data.conn_id), p_data->req_data.trans_id, + p_data->req_data.remote_bda, p_data->req_data.p_data->exec_write); break; } case BTA_GATTS_CONF_EVT: - HAL_CBACK(callbacks, server->indication_sent_cb, p_data->req_data.conn_id, + HAL_CBACK(callbacks, server->indication_sent_cb, static_cast<int>(p_data->req_data.conn_id), p_data->req_data.status); break; case BTA_GATTS_CONGEST_EVT: - HAL_CBACK(callbacks, server->congestion_cb, p_data->congest.conn_id, + HAL_CBACK(callbacks, server->congestion_cb, static_cast<int>(p_data->congest.conn_id), p_data->congest.congested); break; case BTA_GATTS_MTU_EVT: - HAL_CBACK(callbacks, server->mtu_changed_cb, p_data->req_data.conn_id, + HAL_CBACK(callbacks, server->mtu_changed_cb, static_cast<int>(p_data->req_data.conn_id), p_data->req_data.p_data->mtu); break; @@ -244,18 +248,18 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { break; case BTA_GATTS_PHY_UPDATE_EVT: - HAL_CBACK(callbacks, server->phy_updated_cb, p_data->phy_update.conn_id, + HAL_CBACK(callbacks, server->phy_updated_cb, static_cast<int>(p_data->phy_update.conn_id), p_data->phy_update.tx_phy, p_data->phy_update.rx_phy, p_data->phy_update.status); break; case BTA_GATTS_CONN_UPDATE_EVT: - HAL_CBACK(callbacks, server->conn_updated_cb, p_data->conn_update.conn_id, + HAL_CBACK(callbacks, server->conn_updated_cb, static_cast<int>(p_data->conn_update.conn_id), p_data->conn_update.interval, p_data->conn_update.latency, p_data->conn_update.timeout, p_data->conn_update.status); break; case BTA_GATTS_SUBRATE_CHG_EVT: - HAL_CBACK(callbacks, server->subrate_chg_cb, p_data->subrate_chg.conn_id, + HAL_CBACK(callbacks, server->subrate_chg_cb, static_cast<int>(p_data->subrate_chg.conn_id), p_data->subrate_chg.subrate_factor, p_data->subrate_chg.latency, p_data->subrate_chg.cont_num, p_data->subrate_chg.timeout, p_data->subrate_chg.status); @@ -375,7 +379,7 @@ static bt_status_t btif_gatts_open(int server_if, const RawAddress& bd_addr, uin static void btif_gatts_close_impl(int server_if, const RawAddress& address, int conn_id) { // Close active connection if (conn_id != 0) { - BTA_GATTS_Close(conn_id); + BTA_GATTS_Close(static_cast<tCONN_ID>(conn_id)); } else { BTA_GATTS_CancelOpen(server_if, address, true); } @@ -437,8 +441,8 @@ static bt_status_t btif_gatts_send_indication(int /* server_if */, int attribute length = GATT_MAX_ATTR_LEN; } - return do_in_jni_thread(Bind(&BTA_GATTS_HandleValueIndication, conn_id, attribute_handle, - std::vector(value, value + length), confirm)); + return do_in_jni_thread(Bind(&BTA_GATTS_HandleValueIndication, static_cast<tCONN_ID>(conn_id), + attribute_handle, std::vector(value, value + length), confirm)); // TODO: Might need to send an ACK if handle value indication is // invoked without need for confirmation. } @@ -448,7 +452,8 @@ static void btif_gatts_send_response_impl(int conn_id, int trans_id, int status, tGATTS_RSP rsp_struct; btif_to_bta_response(&rsp_struct, &response); - BTA_GATTS_SendRsp(conn_id, trans_id, static_cast<tGATT_STATUS>(status), &rsp_struct); + BTA_GATTS_SendRsp(static_cast<tCONN_ID>(conn_id), trans_id, static_cast<tGATT_STATUS>(status), + &rsp_struct); auto callbacks = bt_gatt_callbacks; HAL_CBACK(callbacks, server->response_confirmation_cb, 0, rsp_struct.attr_value.handle); diff --git a/system/rust/src/gatt/ffi/gatt_shim.cc b/system/rust/src/gatt/ffi/gatt_shim.cc index 2ac8156b8f..eb7c84c315 100644 --- a/system/rust/src/gatt/ffi/gatt_shim.cc +++ b/system/rust/src/gatt/ffi/gatt_shim.cc @@ -38,7 +38,8 @@ std::optional<RawAddress> AddressOfConnection(uint16_t conn_id) { tGATT_IF gatt_if; RawAddress remote_bda; tBT_TRANSPORT transport; - auto valid = GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda, &transport); + auto valid = + GATT_GetConnectionInfor(static_cast<tCONN_ID>(conn_id), &gatt_if, remote_bda, &transport); if (!valid) { return std::nullopt; } diff --git a/system/stack/ais/ais_ble.cc b/system/stack/ais/ais_ble.cc index f545fc7981..c35c4a2acb 100644 --- a/system/stack/ais/ais_ble.cc +++ b/system/stack/ais/ais_ble.cc @@ -44,7 +44,7 @@ static uint16_t attr_api_level_handle; static uint32_t api_level; -void ais_request_cback(uint16_t, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*); +void ais_request_cback(tCONN_ID, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*); static tGATT_CBACK ais_cback = { .p_conn_cb = nullptr, @@ -60,7 +60,7 @@ static tGATT_CBACK ais_cback = { }; /** AIS ATT server attribute access request callback */ -void ais_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +void ais_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { tGATT_STATUS status = GATT_INVALID_PDU; tGATTS_RSP rsp_msg = {}; diff --git a/system/stack/gap/gap_ble.cc b/system/stack/gap/gap_ble.cc index 2a7ccbc61a..945d29f2f2 100644 --- a/system/stack/gap/gap_ble.cc +++ b/system/stack/gap/gap_ble.cc @@ -46,7 +46,7 @@ typedef struct { typedef struct { RawAddress bda; tGAP_BLE_CMPL_CBACK* p_cback; - uint16_t conn_id; + tCONN_ID conn_id; uint16_t cl_op_uuid; bool connected; std::queue<tGAP_REQUEST> requests; @@ -58,10 +58,10 @@ typedef struct { tGAP_BLE_ATTR_VALUE attr_value; } tGAP_ATTR; -void server_attr_request_cback(uint16_t, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*); -void client_connect_cback(tGATT_IF, const RawAddress&, uint16_t, bool, tGATT_DISCONN_REASON, +void server_attr_request_cback(tCONN_ID, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*); +void client_connect_cback(tGATT_IF, const RawAddress&, tCONN_ID, bool, tGATT_DISCONN_REASON, tBT_TRANSPORT); -void client_cmpl_cback(uint16_t, tGATTC_OPTYPE, tGATT_STATUS, tGATT_CL_COMPLETE*); +void client_cmpl_cback(tCONN_ID, tGATTC_OPTYPE, tGATT_STATUS, tGATT_CL_COMPLETE*); tGATT_CBACK gap_cback = { .p_conn_cb = client_connect_cback, @@ -96,7 +96,7 @@ tGAP_CLCB* find_clcb_by_bd_addr(const RawAddress& bda) { } /** returns LCB with matching connection ID, or nullptr if not found */ -tGAP_CLCB* ble_find_clcb_by_conn_id(uint16_t conn_id) { +tGAP_CLCB* ble_find_clcb_by_conn_id(tCONN_ID conn_id) { for (auto& cb : gap_clcbs) { if (cb.connected && cb.conn_id == conn_id) { return &cb; @@ -210,7 +210,7 @@ tGATT_STATUS proc_write_req(tGATTS_REQ_TYPE, tGATT_WRITE_REQ* p_data) { } /** GAP ATT server attribute access request callback */ -void server_attr_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +void server_attr_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { tGATT_STATUS status = GATT_INVALID_PDU; bool ignore = false; @@ -308,7 +308,7 @@ void cl_op_cmpl(tGAP_CLCB& clcb, bool status, uint16_t len, uint8_t* p_name) { } /** Client connection callback */ -void client_connect_cback(tGATT_IF, const RawAddress& bda, uint16_t conn_id, bool connected, +void client_connect_cback(tGATT_IF, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON /* reason */, tBT_TRANSPORT) { tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(bda); if (p_clcb == NULL) { @@ -333,7 +333,7 @@ void client_connect_cback(tGATT_IF, const RawAddress& bda, uint16_t conn_id, boo } /** Client operation complete callback */ -void client_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +void client_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { tGAP_CLCB* p_clcb = ble_find_clcb_by_conn_id(conn_id); uint16_t op_type; diff --git a/system/stack/gatt/gatt_api.cc b/system/stack/gatt/gatt_api.cc index 9008ee0850..19019f0cb7 100644 --- a/system/stack/gatt/gatt_api.cc +++ b/system/stack/gatt/gatt_api.cc @@ -457,17 +457,17 @@ void GATTS_StopService(uint16_t service_handle) { * code. * ******************************************************************************/ -tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, +tGATT_STATUS GATTS_HandleValueIndication(tCONN_ID conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t* p_val) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); log::verbose(""); if ((p_reg == NULL) || (p_tcb == NULL)) { log::error("Unknown conn_id=0x{:x}", conn_id); - return (tGATT_STATUS)GATT_INVALID_CONN_ID; + return GATT_ILLEGAL_PARAMETER; } if (!GATT_HANDLE_IS_VALID(attr_handle)) { @@ -554,11 +554,11 @@ static tGATT_STATUS GATTS_HandleMultipleValueNotification( * Returns GATT_SUCCESS if successfully sent; otherwise error code. * ******************************************************************************/ -tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, +tGATT_STATUS GATTS_HandleValueNotification(tCONN_ID conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t* p_val) { tGATT_VALUE notif; - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); #if (GATT_UPPER_TESTER_MULT_VARIABLE_LENGTH_NOTIF == TRUE) @@ -571,7 +571,7 @@ tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id, uint16_t attr_handl if ((p_reg == NULL) || (p_tcb == NULL)) { log::error("Unknown conn_id: {}", conn_id); - return (tGATT_STATUS)GATT_INVALID_CONN_ID; + return GATT_ILLEGAL_PARAMETER; } if (!GATT_HANDLE_IS_VALID(attr_handle)) { @@ -650,10 +650,10 @@ tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id, uint16_t attr_handl * Returns GATT_SUCCESS if successfully sent; otherwise error code. * ******************************************************************************/ -tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, tGATT_STATUS status, +tGATT_STATUS GATTS_SendRsp(tCONN_ID conn_id, uint32_t trans_id, tGATT_STATUS status, tGATTS_RSP* p_msg) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); @@ -662,7 +662,7 @@ tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, tGATT_STATUS sta if ((p_reg == NULL) || (p_tcb == NULL)) { log::error("Unknown conn_id=0x{:x}", conn_id); - return (tGATT_STATUS)GATT_INVALID_CONN_ID; + return GATT_ILLEGAL_PARAMETER; } tGATT_SR_CMD* sr_res_p = gatt_sr_get_cmd_by_trans_id(p_tcb, trans_id); @@ -699,9 +699,9 @@ tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, tGATT_STATUS sta * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); +tGATT_STATUS GATTC_ConfigureMTU(tCONN_ID conn_id, uint16_t mtu) { + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); @@ -774,7 +774,7 @@ tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) { * ******************************************************************************/ tGATTC_TryMtuRequestResult GATTC_TryMtuRequest(const RawAddress& remote_bda, - tBT_TRANSPORT transport, uint16_t conn_id, + tBT_TRANSPORT transport, tCONN_ID conn_id, uint16_t* current_mtu) { log::info("{} conn_id=0x{:04x}", remote_bda, conn_id); *current_mtu = GATT_DEF_BLE_MTU_SIZE; @@ -850,9 +850,9 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT } } -std::list<uint16_t> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest( +std::list<tCONN_ID> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest( const RawAddress& remote_bda) { - std::list result = std::list<uint16_t>(); + std::list result = std::list<tCONN_ID>(); tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(remote_bda, BT_TRANSPORT_LE); if (!p_tcb || p_tcb->conn_ids_waiting_for_mtu_exchange.empty()) { @@ -879,10 +879,10 @@ std::list<uint16_t> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest( * Returns GATT_SUCCESS if command received/sent successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, uint16_t start_handle, +tGATT_STATUS GATTC_Discover(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, uint16_t start_handle, uint16_t end_handle, const Uuid& uuid) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); @@ -923,7 +923,7 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, uint16_ return GATT_SUCCESS; } -tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, uint16_t start_handle, +tGATT_STATUS GATTC_Discover(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, uint16_t start_handle, uint16_t end_handle) { return GATTC_Discover(conn_id, disc_type, start_handle, end_handle, Uuid::kEmpty); } @@ -942,9 +942,9 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, uint16_ * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM* p_read) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); +tGATT_STATUS GATTC_Read(tCONN_ID conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM* p_read) { + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); #if (GATT_UPPER_TESTER_MULT_VARIABLE_LENGTH_READ == TRUE) @@ -1049,9 +1049,9 @@ tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE* p_write) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); +tGATT_STATUS GATTC_Write(tCONN_ID conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE* p_write) { + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); @@ -1099,9 +1099,9 @@ tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE* p * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); +tGATT_STATUS GATTC_ExecuteWrite(tCONN_ID conn_id, bool is_execute) { + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); @@ -1136,10 +1136,10 @@ tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute) { * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t cid) { +tGATT_STATUS GATTC_SendHandleValueConfirm(tCONN_ID conn_id, uint16_t cid) { log::info("conn_id=0x{:04x} , cid=0x{:04x}", conn_id, cid); - tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(GATT_GET_TCB_IDX(conn_id)); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(gatt_get_tcb_idx(conn_id)); if (!p_tcb) { log::error("Unknown conn_id=0x{:x}", conn_id); return GATT_ILLEGAL_PARAMETER; @@ -1405,7 +1405,7 @@ void GATT_StartIf(tGATT_IF gatt_if) { tGATT_TCB* p_tcb; RawAddress bda = {}; uint8_t start_idx, found_idx; - uint16_t conn_id; + tCONN_ID conn_id; tBT_TRANSPORT transport; log::debug("Starting GATT interface gatt_if_:{}", gatt_if); @@ -1417,7 +1417,7 @@ void GATT_StartIf(tGATT_IF gatt_if) { p_tcb = gatt_find_tcb_by_addr(bda, transport); log::info("GATT interface {} already has connected device {}", gatt_if, bda); if (p_reg->app_cb.p_conn_cb && p_tcb) { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); + conn_id = gatt_create_conn_id(p_tcb->tcb_idx, gatt_if); log::info("Invoking callback with connection id {}", conn_id); (*p_reg->app_cb.p_conn_cb)(gatt_if, bda, conn_id, true, GATT_CONN_OK, transport); } else { @@ -1629,17 +1629,17 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_dir * Returns GATT_SUCCESS if disconnected. * ******************************************************************************/ -tGATT_STATUS GATT_Disconnect(uint16_t conn_id) { +tGATT_STATUS GATT_Disconnect(tCONN_ID conn_id) { log::info("conn_id={}", conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); if (!p_tcb) { log::warn("Cannot find TCB for connection {}", conn_id); return GATT_ILLEGAL_PARAMETER; } - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true); return GATT_SUCCESS; } @@ -1658,11 +1658,11 @@ tGATT_STATUS GATT_Disconnect(uint16_t conn_id) { * Returns true the logical link information is found for conn_id * ******************************************************************************/ -bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if, RawAddress& bd_addr, +bool GATT_GetConnectionInfor(tCONN_ID conn_id, tGATT_IF* p_gatt_if, RawAddress& bd_addr, tBT_TRANSPORT* p_transport) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); log::verbose("conn_id=0x{:x}", conn_id); @@ -1692,14 +1692,14 @@ bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if, RawAddress& * Returns true the logical link is connected * ******************************************************************************/ -bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, const RawAddress& bd_addr, uint16_t* p_conn_id, +bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, const RawAddress& bd_addr, tCONN_ID* p_conn_id, tBT_TRANSPORT transport) { tGATT_REG* p_reg = gatt_get_regcb(gatt_if); tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); bool status = false; if (p_reg && p_tcb && (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN)) { - *p_conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); + *p_conn_id = gatt_create_conn_id(p_tcb->tcb_idx, gatt_if); status = true; } diff --git a/system/stack/gatt/gatt_attr.cc b/system/stack/gatt/gatt_attr.cc index 19b77f88ec..9cb7d1323d 100644 --- a/system/stack/gatt/gatt_attr.cc +++ b/system/stack/gatt/gatt_attr.cc @@ -63,33 +63,33 @@ typedef struct { gatt_sirk_cb sirk_cb; } gatt_op_cb_data; -static std::map<uint16_t, std::deque<gatt_op_cb_data>> OngoingOps; +static std::map<tCONN_ID, std::deque<gatt_op_cb_data>> OngoingOps; -static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id, uint8_t op_code, +static void gatt_request_cback(tCONN_ID conn_id, uint32_t trans_id, uint8_t op_code, tGATTS_DATA* p_data); -static void gatt_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, uint16_t conn_id, +static void gatt_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); -static void gatt_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, +static void gatt_disc_res_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data); -static void gatt_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); -static void gatt_cl_op_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +static void gatt_disc_cmpl_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); +static void gatt_cl_op_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB* p_clcb); static bool gatt_sr_is_robust_caching_enabled(); -static bool read_sr_supported_feat_req(uint16_t conn_id, +static bool read_sr_supported_feat_req(tCONN_ID conn_id, base::OnceCallback<void(const RawAddress&, uint8_t)> cb); -static bool read_sr_sirk_req(uint16_t conn_id, +static bool read_sr_sirk_req(tCONN_ID conn_id, base::OnceCallback<void(tGATT_STATUS status, const RawAddress&, uint8_t sirk_type, Octet16& sirk)> cb); -static tGATT_STATUS gatt_sr_read_db_hash(uint16_t conn_id, tGATT_VALUE* p_value); -static tGATT_STATUS gatt_sr_read_cl_supp_feat(uint16_t conn_id, tGATT_VALUE* p_value); -static tGATT_STATUS gatt_sr_write_cl_supp_feat(uint16_t conn_id, tGATT_WRITE_REQ* p_data); +static tGATT_STATUS gatt_sr_read_db_hash(tCONN_ID conn_id, tGATT_VALUE* p_value); +static tGATT_STATUS gatt_sr_read_cl_supp_feat(tCONN_ID conn_id, tGATT_VALUE* p_value); +static tGATT_STATUS gatt_sr_write_cl_supp_feat(tCONN_ID conn_id, tGATT_WRITE_REQ* p_data); static tGATT_CBACK gatt_profile_cback = { .p_conn_cb = gatt_connect_cback, @@ -113,8 +113,8 @@ static tGATT_CBACK gatt_profile_cback = { * Returns Connection ID * ******************************************************************************/ -uint16_t gatt_profile_find_conn_id_by_bd_addr(const RawAddress& remote_bda) { - uint16_t conn_id = GATT_INVALID_CONN_ID; +tCONN_ID gatt_profile_find_conn_id_by_bd_addr(const RawAddress& remote_bda) { + tCONN_ID conn_id = GATT_INVALID_CONN_ID; if (!GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id, BT_TRANSPORT_LE)) { log::warn( "Unable to get GATT connection id if connected peer:{} gatt_if:{} " @@ -141,7 +141,7 @@ uint16_t gatt_profile_find_conn_id_by_bd_addr(const RawAddress& remote_bda) { * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -static tGATT_PROFILE_CLCB* gatt_profile_find_clcb_by_conn_id(uint16_t conn_id) { +static tGATT_PROFILE_CLCB* gatt_profile_find_clcb_by_conn_id(tCONN_ID conn_id) { uint8_t i_clcb; tGATT_PROFILE_CLCB* p_clcb = NULL; @@ -189,7 +189,7 @@ static tGATT_PROFILE_CLCB* gatt_profile_find_clcb_by_bd_addr(const RawAddress& b * block. * ******************************************************************************/ -tGATT_PROFILE_CLCB* gatt_profile_clcb_alloc(uint16_t conn_id, const RawAddress& bda, +tGATT_PROFILE_CLCB* gatt_profile_clcb_alloc(tCONN_ID conn_id, const RawAddress& bda, tBT_TRANSPORT tranport) { uint8_t i_clcb = 0; tGATT_PROFILE_CLCB* p_clcb = NULL; @@ -226,7 +226,7 @@ void gatt_profile_clcb_dealloc(tGATT_PROFILE_CLCB* p_clcb) { } /** GAP Attributes Database Request callback */ -tGATT_STATUS read_attr_value(uint16_t conn_id, uint16_t handle, tGATT_VALUE* p_value, +tGATT_STATUS read_attr_value(tCONN_ID conn_id, uint16_t handle, tGATT_VALUE* p_value, bool is_long) { uint8_t* p = p_value->value; @@ -268,7 +268,7 @@ tGATT_STATUS read_attr_value(uint16_t conn_id, uint16_t handle, tGATT_VALUE* p_v } /** GAP Attributes Database Read/Read Blob Request process */ -tGATT_STATUS proc_read_req(uint16_t conn_id, tGATTS_REQ_TYPE, tGATT_READ_REQ* p_data, +tGATT_STATUS proc_read_req(tCONN_ID conn_id, tGATTS_REQ_TYPE, tGATT_READ_REQ* p_data, tGATTS_RSP* p_rsp) { if (p_data->is_long) { p_rsp->attr_value.offset = p_data->offset; @@ -280,7 +280,7 @@ tGATT_STATUS proc_read_req(uint16_t conn_id, tGATTS_REQ_TYPE, tGATT_READ_REQ* p_ } /** GAP ATT server process a write request */ -tGATT_STATUS proc_write_req(uint16_t conn_id, tGATTS_REQ_TYPE, tGATT_WRITE_REQ* p_data) { +tGATT_STATUS proc_write_req(tCONN_ID conn_id, tGATTS_REQ_TYPE, tGATT_WRITE_REQ* p_data) { uint16_t handle = p_data->handle; /* GATT_UUID_SERVER_SUP_FEAT*/ @@ -315,7 +315,7 @@ tGATT_STATUS proc_write_req(uint16_t conn_id, tGATTS_REQ_TYPE, tGATT_WRITE_REQ* * Returns void. * ******************************************************************************/ -static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +static void gatt_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { tGATT_STATUS status = GATT_INVALID_PDU; tGATTS_RSP rsp_msg; @@ -366,7 +366,7 @@ static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_T * Returns void * ******************************************************************************/ -static void gatt_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, uint16_t conn_id, +static void gatt_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON /* reason */, tBT_TRANSPORT transport) { log::verbose("from {} connected: {}, conn_id: 0x{:x}", bda, connected, conn_id); @@ -478,7 +478,7 @@ void gatt_profile_db_init(void) { * Returns void * ******************************************************************************/ -static void gatt_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, +static void gatt_disc_res_cback(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data) { tGATT_PROFILE_CLCB* p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id); @@ -521,7 +521,7 @@ static void gatt_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, * Returns void * ******************************************************************************/ -static void gatt_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE /* disc_type */, +static void gatt_disc_cmpl_cback(tCONN_ID conn_id, tGATT_DISC_TYPE /* disc_type */, tGATT_STATUS status) { tGATT_PROFILE_CLCB* p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { @@ -543,7 +543,7 @@ static void gatt_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE /* disc_type gatt_cl_start_config_ccc(p_clcb); } -static bool gatt_svc_read_cl_supp_feat_req(uint16_t conn_id) { +static bool gatt_svc_read_cl_supp_feat_req(tCONN_ID conn_id) { tGATT_READ_PARAM param; memset(¶m, 0, sizeof(tGATT_READ_PARAM)); @@ -570,7 +570,7 @@ static bool gatt_svc_read_cl_supp_feat_req(uint16_t conn_id) { return true; } -static bool gatt_att_write_cl_supp_feat(uint16_t conn_id, uint16_t handle) { +static bool gatt_att_write_cl_supp_feat(tCONN_ID conn_id, uint16_t handle) { tGATT_VALUE attr; memset(&attr, 0, sizeof(tGATT_VALUE)); @@ -598,12 +598,12 @@ static bool gatt_att_write_cl_supp_feat(uint16_t conn_id, uint16_t handle) { * Returns void * ******************************************************************************/ -static void gatt_cl_op_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +static void gatt_cl_op_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { auto iter = OngoingOps.find(conn_id); log::verbose("opcode: 0x{:x} status: {} conn id: 0x{:x}", static_cast<uint8_t>(op), status, - static_cast<uint8_t>(conn_id)); + static_cast<int>(conn_id)); if (op != GATTC_OPTYPE_READ && op != GATTC_OPTYPE_WRITE) { log::verbose("Not interested in opcode {}", op); @@ -639,7 +639,7 @@ static void gatt_cl_op_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STAT switch (cl_op_uuid) { case GATT_UUID_SERVER_SUP_FEAT: { - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB& tcb = gatt_cb.tcb[tcb_idx]; auto operation_callback_data = std::move(iter->second.front()); @@ -665,7 +665,7 @@ static void gatt_cl_op_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STAT break; } case GATT_UUID_CSIS_SIRK: { - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB& tcb = gatt_cb.tcb[tcb_idx]; auto operation_callback_data = std::move(iter->second.front()); @@ -819,7 +819,7 @@ void gatt_cl_init_sr_status(tGATT_TCB& tcb) { } } -static bool read_sr_supported_feat_req(uint16_t conn_id, +static bool read_sr_supported_feat_req(tCONN_ID conn_id, base::OnceCallback<void(const RawAddress&, uint8_t)> cb) { tGATT_READ_PARAM param = {}; @@ -843,7 +843,7 @@ static bool read_sr_supported_feat_req(uint16_t conn_id, return true; } -static bool read_sr_sirk_req(uint16_t conn_id, +static bool read_sr_sirk_req(tCONN_ID conn_id, base::OnceCallback<void(tGATT_STATUS status, const RawAddress&, uint8_t sirk_type, Octet16& sirk)> cb) { @@ -882,7 +882,7 @@ static bool read_sr_sirk_req(uint16_t conn_id, bool gatt_cl_read_sr_supp_feat_req(const RawAddress& peer_bda, base::OnceCallback<void(const RawAddress&, uint8_t)> cb) { tGATT_PROFILE_CLCB* p_clcb; - uint16_t conn_id; + tCONN_ID conn_id; if (!cb) { return false; @@ -933,7 +933,7 @@ bool gatt_cl_read_sirk_req(const RawAddress& peer_bda, uint8_t sirk_type, Octet16& sirk)> cb) { tGATT_PROFILE_CLCB* p_clcb; - uint16_t conn_id; + tCONN_ID conn_id; if (!cb) { return false; @@ -980,7 +980,7 @@ bool gatt_cl_read_sirk_req(const RawAddress& peer_bda, * ******************************************************************************/ bool gatt_profile_get_eatt_support(const RawAddress& remote_bda) { - uint16_t conn_id; + tCONN_ID conn_id; log::verbose("BDA: {} read GATT support", remote_bda); @@ -999,9 +999,9 @@ bool gatt_profile_get_eatt_support(const RawAddress& remote_bda) { return gatt_profile_get_eatt_support_by_conn_id(conn_id); } -bool gatt_profile_get_eatt_support_by_conn_id(uint16_t conn_id) { +bool gatt_profile_get_eatt_support_by_conn_id(tCONN_ID conn_id) { /* Get tcb info */ - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB& tcb = gatt_cb.tcb[tcb_idx]; return tcb.sr_supp_feat & BLE_GATT_SVR_SUP_FEAT_EATT_BITMASK; } @@ -1123,7 +1123,7 @@ void gatt_sr_update_cl_status(tGATT_TCB& tcb, bool chg_aware) { } /* handle request for reading database hash */ -static tGATT_STATUS gatt_sr_read_db_hash(uint16_t conn_id, tGATT_VALUE* p_value) { +static tGATT_STATUS gatt_sr_read_db_hash(tCONN_ID conn_id, tGATT_VALUE* p_value) { log::info("conn_id=0x{:x}", conn_id); uint8_t* p = p_value->value; @@ -1132,15 +1132,15 @@ static tGATT_STATUS gatt_sr_read_db_hash(uint16_t conn_id, tGATT_VALUE* p_value) p_value->len = (uint16_t)db_hash.size(); // Every time when database hash is requested, reset flag. - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); gatt_sr_update_cl_status(gatt_cb.tcb[tcb_idx], /* chg_aware= */ true); return GATT_SUCCESS; } /* handle request for reading client supported features */ -static tGATT_STATUS gatt_sr_read_cl_supp_feat(uint16_t conn_id, tGATT_VALUE* p_value) { +static tGATT_STATUS gatt_sr_read_cl_supp_feat(tCONN_ID conn_id, tGATT_VALUE* p_value) { // Get tcb info - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB& tcb = gatt_cb.tcb[tcb_idx]; uint8_t* p = p_value->value; @@ -1151,7 +1151,7 @@ static tGATT_STATUS gatt_sr_read_cl_supp_feat(uint16_t conn_id, tGATT_VALUE* p_v } /* handle request for writing client supported features */ -static tGATT_STATUS gatt_sr_write_cl_supp_feat(uint16_t conn_id, tGATT_WRITE_REQ* p_data) { +static tGATT_STATUS gatt_sr_write_cl_supp_feat(tCONN_ID conn_id, tGATT_WRITE_REQ* p_data) { std::list<uint8_t> tmp; uint16_t len = p_data->len; uint8_t value, *p = p_data->value; @@ -1170,7 +1170,7 @@ static tGATT_STATUS gatt_sr_write_cl_supp_feat(uint16_t conn_id, tGATT_WRITE_REQ } // Get tcb info - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + uint8_t tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB& tcb = gatt_cb.tcb[tcb_idx]; std::list<uint8_t> feature_list; diff --git a/system/stack/gatt/gatt_cl.cc b/system/stack/gatt/gatt_cl.cc index 10533d6648..de1923a4dc 100644 --- a/system/stack/gatt/gatt_cl.cc +++ b/system/stack/gatt/gatt_cl.cc @@ -623,7 +623,7 @@ void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, ui uint8_t* p_data) { tGATT_VALUE value = {}; tGATT_REG* p_reg; - uint16_t conn_id; + tCONN_ID conn_id; tGATT_STATUS encrypt_status = {}; uint8_t* p = p_data; uint8_t i; @@ -728,14 +728,14 @@ void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, ui if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) { - conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete); } } } else { for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) { - conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete); } } @@ -778,14 +778,14 @@ void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, ui if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) { - conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete); } } } else { for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) { - conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete); } } diff --git a/system/stack/gatt/gatt_db.cc b/system/stack/gatt/gatt_db.cc index 1fa67c192c..1b5cf2385b 100644 --- a/system/stack/gatt/gatt_db.cc +++ b/system/stack/gatt/gatt_db.cc @@ -701,7 +701,7 @@ static tGATT_STATUS gatts_send_app_read_request(tGATT_TCB& tcb, uint16_t cid, ui uint16_t handle, uint16_t offset, uint32_t trans_id, bt_gatt_db_attribute_type_t gatt_type) { tGATT_SRV_LIST_ELEM& el = *gatt_sr_find_i_rcb_by_handle(handle); - uint16_t conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, el.gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, el.gatt_if); if (trans_id == 0) { trans_id = gatt_sr_enqueue_cmd(tcb, cid, op_code, handle); diff --git a/system/stack/gatt/gatt_int.h b/system/stack/gatt/gatt_int.h index d8c36c3dd6..8525953ceb 100644 --- a/system/stack/gatt/gatt_int.h +++ b/system/stack/gatt/gatt_int.h @@ -38,11 +38,6 @@ #include "types/bluetooth/uuid.h" #include "types/raw_address.h" -#define GATT_CREATE_CONN_ID(tcb_idx, gatt_if) \ - ((uint16_t)((((uint8_t)(tcb_idx)) << 8) | ((uint8_t)(gatt_if)))) -#define GATT_GET_TCB_IDX(conn_id) ((uint8_t)(((uint16_t)(conn_id)) >> 8)) -#define GATT_GET_GATT_IF(conn_id) ((tGATT_IF)((uint8_t)(conn_id))) - #define GATT_TRANS_ID_MAX 0x0fffffff /* 4 MSB is reserved */ #define GATT_CL_RCB_MAX 255 /* Maximum number of cl_rcb */ @@ -342,7 +337,7 @@ typedef struct { /* ATT Exchange MTU data */ uint16_t pending_user_mtu_exchange_value; - std::list<uint16_t> conn_ids_waiting_for_mtu_exchange; + std::list<tCONN_ID> conn_ids_waiting_for_mtu_exchange; /* Used to set proper TX DATA LEN on the controller*/ uint16_t max_user_mtu; @@ -360,7 +355,7 @@ struct tGATT_CLCB { uint8_t sccb_idx; uint8_t* p_attr_buf; /* attribute buffer for read multiple, prepare write */ bluetooth::Uuid uuid; - uint16_t conn_id; /* connection handle */ + tCONN_ID conn_id; /* connection handle */ uint16_t s_handle; /* starting handle of the active request */ uint16_t e_handle; /* ending handle of the active request */ uint16_t counter; /* used as offset, attribute length, num of prepare write */ @@ -391,7 +386,7 @@ typedef struct { #define GATT_SVC_CHANGED_CONFIGURE_CCCD 5 /* config CCC */ typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; bool in_use; bool connected; RawAddress bda; @@ -519,10 +514,10 @@ void gatt_chk_srv_chg(tGATTS_SRV_CHG* p_srv_chg_clt); void gatt_add_a_bonded_dev_for_srv_chg(const RawAddress& bda); /* from gatt_attr.cc */ -uint16_t gatt_profile_find_conn_id_by_bd_addr(const RawAddress& bda); +tCONN_ID gatt_profile_find_conn_id_by_bd_addr(const RawAddress& bda); bool gatt_profile_get_eatt_support(const RawAddress& remote_bda); -bool gatt_profile_get_eatt_support_by_conn_id(uint16_t conn_id); +bool gatt_profile_get_eatt_support_by_conn_id(tCONN_ID conn_id); void gatt_cl_init_sr_status(tGATT_TCB& tcb); bool gatt_cl_read_sr_supp_feat_req(const RawAddress& peer_bda, base::OnceCallback<void(const RawAddress&, uint8_t)> cb); @@ -576,6 +571,9 @@ void gatt_delete_dev_from_srv_chg_clt_list(const RawAddress& bd_addr); void gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind); void gatt_free_srvc_db_buffer_app_id(const bluetooth::Uuid& app_id); bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb); +tCONN_ID gatt_create_conn_id(tTCB_IDX tcb_idx, tGATT_IF gatt_if); +tTCB_IDX gatt_get_tcb_idx(tCONN_ID conn_id); +tGATT_IF gatt_get_gatt_if(tCONN_ID conn_id); /* reserved handle list */ std::list<tGATT_HDL_LIST_ELEM>::iterator gatt_find_hdl_buffer_by_app_id( @@ -593,7 +591,7 @@ tGATT_STATUS gatt_sr_process_app_rsp(tGATT_TCB& tcb, tGATT_IF gatt_if, uint32_t tGATT_SR_CMD* sr_res_p); void gatt_server_handle_client_req(tGATT_TCB& p_tcb, uint16_t cid, uint8_t op_code, uint16_t len, uint8_t* p_data); -void gatt_sr_send_req_callback(uint16_t conn_id, uint32_t trans_id, uint8_t op_code, +void gatt_sr_send_req_callback(tCONN_ID conn_id, uint32_t trans_id, uint8_t op_code, tGATTS_DATA* p_req_data); uint32_t gatt_sr_enqueue_cmd(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, uint16_t handle); bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda); @@ -605,8 +603,8 @@ void gatt_notify_subrate_change(uint16_t handle, uint16_t subrate_factor, uint16 bool gatt_tcb_is_cid_busy(tGATT_TCB& tcb, uint16_t cid); tGATT_REG* gatt_get_regcb(tGATT_IF gatt_if); -bool gatt_is_clcb_allocated(uint16_t conn_id); -tGATT_CLCB* gatt_clcb_alloc(uint16_t conn_id); +bool gatt_is_clcb_allocated(tCONN_ID conn_id); +tGATT_CLCB* gatt_clcb_alloc(tCONN_ID conn_id); bool gatt_tcb_get_cid_available_for_indication(tGATT_TCB* p_tcb, bool eatt_support, uint16_t** indicate_handle_p, uint16_t* cid_p); @@ -617,7 +615,7 @@ std::string gatt_tcb_get_holders_info_string(const tGATT_TCB* p_tcb); void gatt_clcb_invalidate(tGATT_TCB* p_tcb, const tGATT_CLCB* p_clcb); uint16_t gatt_get_mtu(const RawAddress& bda, tBT_TRANSPORT transport); bool gatt_is_pending_mtu_exchange(tGATT_TCB* p_tcb); -void gatt_set_conn_id_waiting_for_mtu_exchange(tGATT_TCB* p_tcb, uint16_t conn_id); +void gatt_set_conn_id_waiting_for_mtu_exchange(tGATT_TCB* p_tcb, tCONN_ID conn_id); void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB& p_tcb); bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& p_tcb); diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc index 7c14d3a5a1..082cb67478 100644 --- a/system/stack/gatt/gatt_main.cc +++ b/system/stack/gatt/gatt_main.cc @@ -648,7 +648,7 @@ static void read_dis_cback(const RawAddress& bd_addr, tDIS_VALUE* p_dis_value) { static void gatt_channel_congestion(tGATT_TCB* p_tcb, bool congested) { uint8_t i = 0; tGATT_REG* p_reg = NULL; - uint16_t conn_id; + tCONN_ID conn_id; /* if uncongested, check to see if there is any more pending data */ if (p_tcb != NULL && !congested) { @@ -658,7 +658,7 @@ static void gatt_channel_congestion(tGATT_TCB* p_tcb, bool congested) { if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_congestion_cb) { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_congestion_cb)(conn_id, congested); } } @@ -666,7 +666,7 @@ static void gatt_channel_congestion(tGATT_TCB* p_tcb, bool congested) { for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { if (p_reg->in_use) { if (p_reg->app_cb.p_congestion_cb) { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_congestion_cb)(conn_id, congested); } } @@ -692,7 +692,7 @@ void gatt_notify_phy_updated(tHCI_STATUS status, uint16_t handle, uint8_t tx_phy if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_phy_update_cb) { - uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_phy_update_cb)(p_reg->gatt_if, conn_id, tx_phy, rx_phy, gatt_status); } } @@ -700,7 +700,7 @@ void gatt_notify_phy_updated(tHCI_STATUS status, uint16_t handle, uint8_t tx_phy for (int i = 0; i < GATT_MAX_APPS; i++) { tGATT_REG* p_reg = &gatt_cb.cl_rcb[i]; if (p_reg->in_use && p_reg->app_cb.p_phy_update_cb) { - uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_phy_update_cb)(p_reg->gatt_if, conn_id, tx_phy, rx_phy, gatt_status); } } @@ -718,7 +718,7 @@ void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16 if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_conn_update_cb) { - uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_conn_update_cb)(p_reg->gatt_if, conn_id, interval, latency, timeout, static_cast<tGATT_STATUS>(status)); } @@ -727,7 +727,7 @@ void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16 for (int i = 0; i < GATT_MAX_APPS; i++) { tGATT_REG* p_reg = &gatt_cb.cl_rcb[i]; if (p_reg->in_use && p_reg->app_cb.p_conn_update_cb) { - uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_conn_update_cb)(p_reg->gatt_if, conn_id, interval, latency, timeout, static_cast<tGATT_STATUS>(status)); } @@ -751,7 +751,7 @@ void gatt_notify_subrate_change(uint16_t handle, uint16_t subrate_factor, uint16 if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_subrate_chg_cb) { - uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_subrate_chg_cb)(p_reg->gatt_if, conn_id, subrate_factor, latency, cont_num, timeout, static_cast<tGATT_STATUS>(status)); } @@ -760,7 +760,7 @@ void gatt_notify_subrate_change(uint16_t handle, uint16_t subrate_factor, uint16 for (int i = 0; i < GATT_MAX_APPS; i++) { tGATT_REG* p_reg = &gatt_cb.cl_rcb[i]; if (p_reg->in_use && p_reg->app_cb.p_subrate_chg_cb) { - uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_subrate_chg_cb)(p_reg->gatt_if, conn_id, subrate_factor, latency, cont_num, timeout, static_cast<tGATT_STATUS>(status)); } @@ -1001,7 +1001,7 @@ static void gatt_l2cif_congest_cback(uint16_t lcid, bool congested) { static void gatt_send_conn_cback(tGATT_TCB* p_tcb) { uint8_t i; tGATT_REG* p_reg; - uint16_t conn_id; + tCONN_ID conn_id; std::set<tGATT_IF> apps = {}; if (com::android::bluetooth::flags::unified_connection_manager()) { @@ -1034,7 +1034,7 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) { } if (p_reg->app_cb.p_conn_cb) { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, kGattConnected, GATT_CONN_OK, p_tcb->transport); } @@ -1059,7 +1059,7 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) { } if (p_reg->app_cb.p_conn_cb) { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if); (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, kGattConnected, GATT_CONN_OK, p_tcb->transport); } @@ -1180,7 +1180,7 @@ void gatt_send_srv_chg_ind(const RawAddress& peer_bda) { return; } - uint16_t conn_id = gatt_profile_find_conn_id_by_bd_addr(peer_bda); + tCONN_ID conn_id = gatt_profile_find_conn_id_by_bd_addr(peer_bda); if (conn_id == GATT_INVALID_CONN_ID) { log::error("Unable to find conn_id for {}", peer_bda); return; diff --git a/system/stack/gatt/gatt_sr.cc b/system/stack/gatt/gatt_sr.cc index ccb017edcc..979bd4a3c2 100644 --- a/system/stack/gatt/gatt_sr.cc +++ b/system/stack/gatt/gatt_sr.cc @@ -371,7 +371,7 @@ void gatt_process_exec_write_req(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, uint8_t *p = p_data, flag, i = 0; uint32_t trans_id = 0; tGATT_IF gatt_if; - uint16_t conn_id; + tCONN_ID conn_id; #if (GATT_CONFORMANCE_TESTING == TRUE) if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { @@ -404,7 +404,7 @@ void gatt_process_exec_write_req(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, 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); + 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); @@ -414,7 +414,7 @@ void gatt_process_exec_write_req(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code, for (i = 0; i < GATT_MAX_APPS; i++) { if (tcb.prep_cnt[i]) { gatt_if = (tGATT_IF)(i + 1); - conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, gatt_if); + 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); @@ -885,14 +885,14 @@ static void gatts_process_mtu_req(tGATT_TCB& tcb, uint16_t cid, uint16_t len, ui if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use) { - uint16_t conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, p_reg->gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if); gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, &gatts_data); } } } else { for (int i = 0; i < GATT_MAX_APPS; i++) { if (gatt_cb.cl_rcb[i].in_use) { - uint16_t conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, gatt_cb.cl_rcb[i].gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, gatt_cb.cl_rcb[i].gatt_if); gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, &gatts_data); } } @@ -999,7 +999,7 @@ static void gatts_process_write_req(tGATT_TCB& tcb, uint16_t cid, tGATT_SRV_LIST tGATT_STATUS status; tGATT_SEC_FLAG sec_flag; uint8_t key_size, *p = p_data; - uint16_t conn_id; + tCONN_ID conn_id; memset(&sr_data, 0, sizeof(tGATTS_DATA)); @@ -1044,7 +1044,7 @@ static void gatts_process_write_req(tGATT_TCB& tcb, uint16_t cid, tGATT_SRV_LIST if (status == GATT_SUCCESS) { trans_id = gatt_sr_enqueue_cmd(tcb, cid, op_code, handle); if (trans_id != 0) { - conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, el.gatt_if); + conn_id = gatt_create_conn_id(tcb.tcb_idx, el.gatt_if); uint8_t opcode = 0; if (gatt_type == BTGATT_DB_DESCRIPTOR) { @@ -1306,7 +1306,7 @@ void gatts_process_value_conf(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code) { for (auto& el : *gatt_cb.srv_list_info) { if (el.s_hdl <= handle && el.e_hdl >= handle) { uint32_t trans_id = gatt_sr_enqueue_cmd(tcb, cid, op_code, handle); - uint16_t conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, el.gatt_if); + tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, el.gatt_if); gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_CONF, &gatts_data); } } diff --git a/system/stack/gatt/gatt_utils.cc b/system/stack/gatt/gatt_utils.cc index a893b20363..8e2dad4c33 100644 --- a/system/stack/gatt/gatt_utils.cc +++ b/system/stack/gatt/gatt_utils.cc @@ -422,7 +422,7 @@ uint8_t gatt_find_i_tcb_by_addr(const RawAddress& bda, tBT_TRANSPORT transport) * Returns NULL if not found. Otherwise index to the tcb. * ******************************************************************************/ -tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx) { +tGATT_TCB* gatt_get_tcb_by_idx(tTCB_IDX tcb_idx) { tGATT_TCB* p_tcb = NULL; if ((tcb_idx < gatt_get_max_phy_channel()) && gatt_cb.tcb[tcb_idx].in_use) { @@ -541,7 +541,7 @@ tGATT_TCB* gatt_allocate_tcb_by_bdaddr(const RawAddress& bda, tBT_TRANSPORT tran p_tcb->peer_bda = bda; p_tcb->eatt = 0; p_tcb->pending_user_mtu_exchange_value = 0; - p_tcb->conn_ids_waiting_for_mtu_exchange = std::list<uint16_t>(); + p_tcb->conn_ids_waiting_for_mtu_exchange = std::list<tCONN_ID>(); p_tcb->max_user_mtu = 0; gatt_sr_init_cl_status(*p_tcb); gatt_cl_init_sr_status(*p_tcb); @@ -565,7 +565,7 @@ bool gatt_is_pending_mtu_exchange(tGATT_TCB* p_tcb) { return p_tcb->pending_user_mtu_exchange_value != 0; } -void gatt_set_conn_id_waiting_for_mtu_exchange(tGATT_TCB* p_tcb, uint16_t conn_id) { +void gatt_set_conn_id_waiting_for_mtu_exchange(tGATT_TCB* p_tcb, tCONN_ID conn_id) { auto it = std::find(p_tcb->conn_ids_waiting_for_mtu_exchange.begin(), p_tcb->conn_ids_waiting_for_mtu_exchange.end(), conn_id); if (it == p_tcb->conn_ids_waiting_for_mtu_exchange.end()) { @@ -900,9 +900,9 @@ void gatt_sr_get_sec_info(const RawAddress& rem_bda, tBT_TRANSPORT transport, * Returns void * ******************************************************************************/ -void gatt_sr_send_req_callback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +void gatt_sr_send_req_callback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); if (!p_reg) { @@ -1115,10 +1115,10 @@ bool gatt_tcb_is_cid_busy(tGATT_TCB& tcb, uint16_t cid) { * block. * ******************************************************************************/ -tGATT_CLCB* gatt_clcb_alloc(uint16_t conn_id) { +tGATT_CLCB* gatt_clcb_alloc(tCONN_ID conn_id) { tGATT_CLCB clcb = {}; - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_IF gatt_if = gatt_get_gatt_if(conn_id); + tTCB_IDX tcb_idx = gatt_get_tcb_idx(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); tGATT_REG* p_reg = gatt_get_regcb(gatt_if); @@ -1790,7 +1790,7 @@ void gatt_end_operation(tGATT_CLCB* p_clcb, tGATT_STATUS status, void* p_data) { tGATT_DISC_TYPE disc_type = GATT_DISC_MAX; tGATT_DISC_CMPL_CB* p_disc_cmpl_cb = (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_disc_cmpl_cb : NULL; - uint16_t conn_id; + tCONN_ID conn_id; uint8_t operation; log::verbose("status={} op={} subtype={}", status, p_clcb->operation, p_clcb->op_subtype); @@ -1858,8 +1858,8 @@ static void gatt_le_disconnect_complete_notify_user(const RawAddress& bda, if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) { if (p_reg->in_use && p_reg->app_cb.p_conn_cb) { - uint16_t conn_id = - p_tcb ? GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID; + tCONN_ID conn_id = + p_tcb ? gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID; (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason, transport); } @@ -1876,8 +1876,8 @@ static void gatt_le_disconnect_complete_notify_user(const RawAddress& bda, for (uint8_t i = 0; i < GATT_MAX_APPS; i++) { tGATT_REG* p_reg = &gatt_cb.cl_rcb[i]; if (p_reg->in_use && p_reg->app_cb.p_conn_cb) { - uint16_t conn_id = - p_tcb ? GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID; + tCONN_ID conn_id = + p_tcb ? gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID; (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason, transport); } @@ -1997,3 +1997,11 @@ bool gatt_auto_connect_dev_remove(tGATT_IF gatt_if, const RawAddress& bd_addr) { return connection_manager::background_connect_remove(gatt_if, bd_addr); } } + +tCONN_ID gatt_create_conn_id(tTCB_IDX tcb_idx, tGATT_IF gatt_if) { + return (tcb_idx << 8) | gatt_if; +} + +tTCB_IDX gatt_get_tcb_idx(tCONN_ID conn_id) { return (uint8_t)(conn_id >> 8); } + +tGATT_IF gatt_get_gatt_if(tCONN_ID conn_id) { return (tGATT_IF)conn_id; } diff --git a/system/stack/include/btm_ble_api_types.h b/system/stack/include/btm_ble_api_types.h index 1e23a9050e..70b9a4f0fa 100644 --- a/system/stack/include/btm_ble_api_types.h +++ b/system/stack/include/btm_ble_api_types.h @@ -354,7 +354,9 @@ typedef void(tBTM_BLE_ADV_DATA_CMPL_CBACK)(tBTM_STATUS status); than this number */ #endif +typedef uint16_t tCONN_ID; typedef uint8_t tGATT_IF; +typedef uint8_t tTCB_IDX; typedef enum : uint8_t { BTM_BLE_DIRECT_CONNECTION = 0x00, diff --git a/system/stack/include/btm_iso_api_types.h b/system/stack/include/btm_iso_api_types.h index 16cb1ca6fa..5aac3e247e 100644 --- a/system/stack/include/btm_iso_api_types.h +++ b/system/stack/include/btm_iso_api_types.h @@ -21,6 +21,7 @@ #include "hcimsgs.h" #include "stack/include/bt_hdr.h" +#include "stack/include/btm_ble_api_types.h" namespace bluetooth { namespace hci { diff --git a/system/stack/include/gatt_api.h b/system/stack/include/gatt_api.h index 892047b630..abda34aa15 100644 --- a/system/stack/include/gatt_api.h +++ b/system/stack/include/gatt_api.h @@ -310,7 +310,7 @@ inline std::string gatt_disconnection_reason_text(const tGATT_DISCONN_REASON& re /* invalid connection ID */ -#define GATT_INVALID_CONN_ID 0xFFFF +#define GATT_INVALID_CONN_ID ((tCONN_ID)0xFFFF) /* GATT notification caching timer, default to be three seconds */ @@ -475,7 +475,7 @@ typedef uint8_t tGATT_AUTH_REQ; /* Attribute Value structure */ typedef struct { - uint16_t conn_id; + tCONN_ID conn_id; uint16_t handle; /* attribute handle */ uint16_t offset; /* attribute value offset, if no offset is needed for the command, ignore it */ @@ -691,42 +691,42 @@ typedef struct { #define GATT_INVALID_ACL_HANDLE 0xFFFF /* discover result callback function */ -typedef void(tGATT_DISC_RES_CB)(uint16_t conn_id, tGATT_DISC_TYPE disc_type, +typedef void(tGATT_DISC_RES_CB)(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES* p_data); /* discover complete callback function */ -typedef void(tGATT_DISC_CMPL_CB)(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); +typedef void(tGATT_DISC_CMPL_CB)(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); /* Define a callback function for when read/write/disc/config operation is * completed. */ -typedef void(tGATT_CMPL_CBACK)(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +typedef void(tGATT_CMPL_CBACK)(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); /* Define a callback function when an initialized connection is established. */ -typedef void(tGATT_CONN_CBACK)(tGATT_IF gatt_if, const RawAddress& bda, uint16_t conn_id, +typedef void(tGATT_CONN_CBACK)(tGATT_IF gatt_if, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); /* attribute request callback for ATT server */ -typedef void(tGATT_REQ_CBACK)(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +typedef void(tGATT_REQ_CBACK)(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data); /* channel congestion/uncongestion callback */ -typedef void(tGATT_CONGESTION_CBACK)(uint16_t conn_id, bool congested); +typedef void(tGATT_CONGESTION_CBACK)(tCONN_ID conn_id, bool congested); /* Define a callback function when encryption is established. */ typedef void(tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, const RawAddress& bda); /* Define a callback function when phy is updated. */ -typedef void(tGATT_PHY_UPDATE_CB)(tGATT_IF gatt_if, uint16_t conn_id, uint8_t tx_phy, +typedef void(tGATT_PHY_UPDATE_CB)(tGATT_IF gatt_if, tCONN_ID conn_id, uint8_t tx_phy, uint8_t rx_phy, tGATT_STATUS status); /* Define a callback function when connection parameters are updated */ -typedef void(tGATT_CONN_UPDATE_CB)(tGATT_IF gatt_if, uint16_t conn_id, uint16_t interval, +typedef void(tGATT_CONN_UPDATE_CB)(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t interval, uint16_t latency, uint16_t timeout, tGATT_STATUS status); /* Define a callback function when subrate change event is received */ -typedef void(tGATT_SUBRATE_CHG_CB)(tGATT_IF gatt_if, uint16_t conn_id, uint16_t subrate_factor, +typedef void(tGATT_SUBRATE_CHG_CB)(tGATT_IF gatt_if, tCONN_ID conn_id, uint16_t subrate_factor, uint16_t latency, uint16_t cont_num, uint16_t timeout, tGATT_STATUS status); @@ -884,7 +884,7 @@ void GATTS_StopService(uint16_t service_handle); * code. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle, +[[nodiscard]] tGATT_STATUS GATTS_HandleValueIndication(tCONN_ID conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t* p_val); /******************************************************************************* @@ -902,7 +902,7 @@ void GATTS_StopService(uint16_t service_handle); * Returns GATT_SUCCESS if successfully sent; otherwise error code. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id, uint16_t attr_handle, +[[nodiscard]] tGATT_STATUS GATTS_HandleValueNotification(tCONN_ID conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t* p_val); /******************************************************************************* @@ -919,7 +919,7 @@ void GATTS_StopService(uint16_t service_handle); * Returns GATT_SUCCESS if successfully sent; otherwise error code. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, tGATT_STATUS status, +[[nodiscard]] tGATT_STATUS GATTS_SendRsp(tCONN_ID conn_id, uint32_t trans_id, tGATT_STATUS status, tGATTS_RSP* p_msg); /******************************************************************************/ @@ -939,7 +939,7 @@ void GATTS_StopService(uint16_t service_handle); * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu); +[[nodiscard]] tGATT_STATUS GATTC_ConfigureMTU(tCONN_ID conn_id, uint16_t mtu); /******************************************************************************* * Function GATTC_UpdateUserAttMtuIfNeeded @@ -985,10 +985,10 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT ******************************************************************************/ [[nodiscard]] tGATTC_TryMtuRequestResult GATTC_TryMtuRequest(const RawAddress& remote_bda, tBT_TRANSPORT transport, - uint16_t conn_id, + tCONN_ID conn_id, uint16_t* current_mtu); -[[nodiscard]] std::list<uint16_t> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest( +[[nodiscard]] std::list<tCONN_ID> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest( const RawAddress& remote_bda); /******************************************************************************* * @@ -1006,10 +1006,10 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT * Returns GATT_SUCCESS if command received/sent successfully. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, +[[nodiscard]] tGATT_STATUS GATTC_Discover(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, uint16_t start_handle, uint16_t end_handle, const bluetooth::Uuid& uuid); -[[nodiscard]] tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, +[[nodiscard]] tGATT_STATUS GATTC_Discover(tCONN_ID conn_id, tGATT_DISC_TYPE disc_type, uint16_t start_handle, uint16_t end_handle); /******************************************************************************* @@ -1026,7 +1026,7 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type, +[[nodiscard]] tGATT_STATUS GATTC_Read(tCONN_ID conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM* p_read); /******************************************************************************* @@ -1043,7 +1043,7 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type, +[[nodiscard]] tGATT_STATUS GATTC_Write(tCONN_ID conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE* p_write); /******************************************************************************* @@ -1060,7 +1060,7 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute); +[[nodiscard]] tGATT_STATUS GATTC_ExecuteWrite(tCONN_ID conn_id, bool is_execute); /******************************************************************************* * @@ -1075,7 +1075,7 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda, tBT_TRANSPORT * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t handle); +[[nodiscard]] tGATT_STATUS GATTC_SendHandleValueConfirm(tCONN_ID conn_id, uint16_t handle); /******************************************************************************* * @@ -1209,7 +1209,7 @@ void GATT_StartIf(tGATT_IF gatt_if); * Returns GATT_SUCCESS if disconnected. * ******************************************************************************/ -[[nodiscard]] tGATT_STATUS GATT_Disconnect(uint16_t conn_id); +[[nodiscard]] tGATT_STATUS GATT_Disconnect(tCONN_ID conn_id); /******************************************************************************* * @@ -1227,7 +1227,7 @@ void GATT_StartIf(tGATT_IF gatt_if); * Returns true the logical link information is found for conn_id * ******************************************************************************/ -[[nodiscard]] bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if, +[[nodiscard]] bool GATT_GetConnectionInfor(tCONN_ID conn_id, tGATT_IF* p_gatt_if, RawAddress& bd_addr, tBT_TRANSPORT* p_transport); /******************************************************************************* @@ -1247,7 +1247,7 @@ void GATT_StartIf(tGATT_IF gatt_if); * ******************************************************************************/ [[nodiscard]] bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, const RawAddress& bd_addr, - uint16_t* p_conn_id, tBT_TRANSPORT transport); + tCONN_ID* p_conn_id, tBT_TRANSPORT transport); /******************************************************************************* * diff --git a/system/stack/srvc/srvc_dis.cc b/system/stack/srvc/srvc_dis.cc index e4eff9fd16..402ec14feb 100644 --- a/system/stack/srvc/srvc_dis.cc +++ b/system/stack/srvc/srvc_dis.cc @@ -101,7 +101,7 @@ uint8_t dis_read_attr_value(uint8_t /* clcb_idx */, uint16_t /* handle */, * Returns void * ******************************************************************************/ -static void dis_gatt_c_read_dis_value_cmpl(uint16_t conn_id) { +static void dis_gatt_c_read_dis_value_cmpl(tCONN_ID conn_id) { tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); dis_cb.dis_read_uuid_idx = 0xff; @@ -143,7 +143,7 @@ static void dis_gatt_c_read_dis_value_cmpl(uint16_t conn_id) { * Returns void * ******************************************************************************/ -bool dis_gatt_c_read_dis_req(uint16_t conn_id) { +bool dis_gatt_c_read_dis_req(tCONN_ID conn_id) { tGATT_READ_PARAM param; memset(¶m, 0, sizeof(tGATT_READ_PARAM)); @@ -184,7 +184,7 @@ void dis_c_cmpl_cback(tSRVC_CLCB* p_clcb, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { uint16_t read_type; uint8_t *pp = NULL, *p_str; - uint16_t conn_id = p_clcb->conn_id; + tCONN_ID conn_id = p_clcb->conn_id; if (dis_cb.dis_read_uuid_idx >= (sizeof(dis_attr_uuid) / sizeof(dis_attr_uuid[0]))) { log::error("invalid dis_cb.dis_read_uuid_idx"); @@ -260,7 +260,7 @@ void dis_c_cmpl_cback(tSRVC_CLCB* p_clcb, tGATTC_OPTYPE op, tGATT_STATUS status, * ******************************************************************************/ bool DIS_ReadDISInfo(const RawAddress& peer_bda, tDIS_READ_CBACK* p_cback, tDIS_ATTR_MASK mask) { - uint16_t conn_id; + tCONN_ID conn_id; /* Initialize the DIS client if it hasn't been initialized already. */ srvc_eng_init(); diff --git a/system/stack/srvc/srvc_eng.cc b/system/stack/srvc/srvc_eng.cc index a9dfd5763c..c1d877dd8e 100644 --- a/system/stack/srvc/srvc_eng.cc +++ b/system/stack/srvc/srvc_eng.cc @@ -30,12 +30,12 @@ using base::StringPrintf; using namespace bluetooth; -static void srvc_eng_s_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +static void srvc_eng_s_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data); -static void srvc_eng_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, uint16_t conn_id, +static void srvc_eng_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); -static void srvc_eng_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +static void srvc_eng_c_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); static tGATT_CBACK srvc_gatt_cback = { @@ -91,7 +91,7 @@ static tSRVC_CLCB* srvc_eng_find_clcb_by_bd_addr(const RawAddress& bda) { * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(uint16_t conn_id) { +tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(tCONN_ID conn_id) { uint8_t i_clcb; tSRVC_CLCB* p_clcb = NULL; @@ -112,7 +112,7 @@ tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(uint16_t conn_id) { * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -static uint8_t srvc_eng_find_clcb_idx_by_conn_id(uint16_t conn_id) { +static uint8_t srvc_eng_find_clcb_idx_by_conn_id(tCONN_ID conn_id) { uint8_t i_clcb; tSRVC_CLCB* p_clcb = NULL; @@ -134,7 +134,7 @@ static uint8_t srvc_eng_find_clcb_idx_by_conn_id(uint16_t conn_id) { * block. * ******************************************************************************/ -static tSRVC_CLCB* srvc_eng_clcb_alloc(uint16_t conn_id, const RawAddress& bda) { +static tSRVC_CLCB* srvc_eng_clcb_alloc(tCONN_ID conn_id, const RawAddress& bda) { uint8_t i_clcb = 0; tSRVC_CLCB* p_clcb = NULL; @@ -158,7 +158,7 @@ static tSRVC_CLCB* srvc_eng_clcb_alloc(uint16_t conn_id, const RawAddress& bda) * Returns True the deallocation is successful * ******************************************************************************/ -static bool srvc_eng_clcb_dealloc(uint16_t conn_id) { +static bool srvc_eng_clcb_dealloc(tCONN_ID conn_id) { uint8_t i_clcb = 0; tSRVC_CLCB* p_clcb = NULL; @@ -222,7 +222,7 @@ static uint8_t srvc_eng_process_write_req(uint8_t /* clcb_idx */, tGATT_WRITE_RE * Returns void. * ******************************************************************************/ -static void srvc_eng_s_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, +static void srvc_eng_s_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { tGATT_STATUS status = GATT_INVALID_PDU; tGATTS_RSP rsp_msg; @@ -284,7 +284,7 @@ static void srvc_eng_s_request_cback(uint16_t conn_id, uint32_t trans_id, tGATTS * Returns void * ******************************************************************************/ -static void srvc_eng_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, +static void srvc_eng_c_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); @@ -309,7 +309,7 @@ static void srvc_eng_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STAT * Returns void * ******************************************************************************/ -static void srvc_eng_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, uint16_t conn_id, +static void srvc_eng_connect_cback(tGATT_IF /* gatt_if */, const RawAddress& bda, tCONN_ID conn_id, bool connected, tGATT_DISCONN_REASON /* reason */, tBT_TRANSPORT /* transport */) { log::verbose("from {} connected:{} conn_id={}", bda, connected, conn_id); @@ -357,7 +357,7 @@ bool srvc_eng_request_channel(const RawAddress& remote_bda, uint8_t srvc_id) { * Returns void * ******************************************************************************/ -void srvc_eng_release_channel(uint16_t conn_id) { +void srvc_eng_release_channel(tCONN_ID conn_id) { tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); if (p_clcb == NULL) { diff --git a/system/stack/srvc/srvc_eng_int.h b/system/stack/srvc/srvc_eng_int.h index 076eeb186a..6f8dde3d75 100644 --- a/system/stack/srvc/srvc_eng_int.h +++ b/system/stack/srvc/srvc_eng_int.h @@ -36,7 +36,7 @@ typedef struct { bool in_use; - uint16_t conn_id; + tCONN_ID conn_id; bool connected; RawAddress bda; uint32_t trans_id; @@ -57,8 +57,8 @@ typedef struct { /* Global GATT data */ extern tSRVC_ENG_CB srvc_eng_cb; -tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(uint16_t conn_id); +tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(tCONN_ID conn_id); -void srvc_eng_release_channel(uint16_t conn_id); +void srvc_eng_release_channel(tCONN_ID conn_id); bool srvc_eng_request_channel(const RawAddress& remote_bda, uint8_t srvc_id); #endif |