diff --git a/system/bta/dm/bta_dm_disc.cc b/system/bta/dm/bta_dm_disc.cc index 7d4762d6f6725e5230bdf24e11007b84719b26e4..c10a99a781ac43211ea030f7c82c6c45bb1ccbc9 100644 --- a/system/bta/dm/bta_dm_disc.cc +++ b/system/bta/dm/bta_dm_disc.cc @@ -24,20 +24,22 @@ #include <cstdint> -#include "bta/dm/bta_dm_int.h" -#include "bta/include/bta_api.h" +#include "bta/dm/bta_dm_disc.h" +#include "bta/dm/bta_dm_disc_int.h" #include "bta/include/bta_gatt_api.h" #include "bta/include/bta_sdp_api.h" #include "btif/include/btif_config.h" +#include "common/circular_buffer.h" #include "common/init_flags.h" +#include "common/strings.h" #include "device/include/interop.h" -#include "gd/common/circular_buffer.h" -#include "gd/common/strings.h" #include "include/bind_helpers.h" #include "main/shim/dumpsys.h" #include "os/log.h" +#include "osi/include/allocator.h" +#include "osi/include/fixed_queue.h" #include "osi/include/osi.h" // UNUSED_ATTR -#include "stack/btm/btm_int_types.h" +#include "stack/btm/btm_int_types.h" // TimestampedStringCircularBuffer #include "stack/btm/neighbor_inquiry.h" #include "stack/include/avrc_api.h" #include "stack/include/bt_dev_class.h" @@ -46,11 +48,10 @@ #include "stack/include/bt_uuid16.h" #include "stack/include/btm_client_interface.h" #include "stack/include/btm_log_history.h" -#include "stack/include/btm_sec_api.h" -#include "stack/include/gap_api.h" -#include "stack/include/gatt_api.h" +#include "stack/include/btm_sec_api.h" // BTM_IsRemoteNameKnown +#include "stack/include/gap_api.h" // GAP_BleReadPeerPrefConnParams #include "stack/include/sdp_status.h" -#include "stack/sdp/sdpint.h" +#include "stack/sdp/sdpint.h" // is_sdp_pbap_pce_disabled #include "types/raw_address.h" #ifdef TARGET_FLOSS diff --git a/system/bta/dm/bta_dm_disc_int.h b/system/bta/dm/bta_dm_disc_int.h new file mode 100644 index 0000000000000000000000000000000000000000..9ceba10072c1d521fd9a69f5c526157fba52b957 --- /dev/null +++ b/system/bta/dm/bta_dm_disc_int.h @@ -0,0 +1,193 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <base/strings/stringprintf.h> + +#include <string> + +#include "bta/include/bta_api.h" +#include "bta/sys/bta_sys.h" +#include "stack/btm/neighbor_inquiry.h" +#include "stack/include/bt_hdr.h" +#include "stack/include/sdp_status.h" +#include "stack/sdp/sdp_discovery_db.h" +#include "types/bluetooth/uuid.h" +#include "types/raw_address.h" + +#ifndef CASE_RETURN_TEXT +#define CASE_RETURN_TEXT(code) \ + case code: \ + return #code +#endif + +#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) + +/* DM search events */ +typedef enum : uint16_t { + /* DM search API events */ + BTA_DM_API_SEARCH_EVT = BTA_SYS_EVT_START(BTA_ID_DM_SEARCH), + BTA_DM_API_SEARCH_CANCEL_EVT, + BTA_DM_API_DISCOVER_EVT, + BTA_DM_INQUIRY_CMPL_EVT, + BTA_DM_REMT_NAME_EVT, + BTA_DM_SDP_RESULT_EVT, + BTA_DM_SEARCH_CMPL_EVT, + BTA_DM_DISCOVERY_RESULT_EVT, + BTA_DM_DISC_CLOSE_TOUT_EVT, +} tBTA_DM_EVT; + +inline std::string bta_dm_event_text(const tBTA_DM_EVT& event) { + switch (event) { + CASE_RETURN_TEXT(BTA_DM_API_SEARCH_EVT); + CASE_RETURN_TEXT(BTA_DM_API_SEARCH_CANCEL_EVT); + CASE_RETURN_TEXT(BTA_DM_API_DISCOVER_EVT); + CASE_RETURN_TEXT(BTA_DM_INQUIRY_CMPL_EVT); + CASE_RETURN_TEXT(BTA_DM_REMT_NAME_EVT); + CASE_RETURN_TEXT(BTA_DM_SDP_RESULT_EVT); + CASE_RETURN_TEXT(BTA_DM_SEARCH_CMPL_EVT); + CASE_RETURN_TEXT(BTA_DM_DISCOVERY_RESULT_EVT); + CASE_RETURN_TEXT(BTA_DM_DISC_CLOSE_TOUT_EVT); + default: + return base::StringPrintf("UNKNOWN[0x%04x]", event); + } +} + +/* data type for BTA_DM_API_SEARCH_EVT */ +typedef struct { + BT_HDR_RIGID hdr; + tBTA_SERVICE_MASK services; + tBTA_DM_SEARCH_CBACK* p_cback; +} tBTA_DM_API_SEARCH; + +/* data type for BTA_DM_API_DISCOVER_EVT */ +typedef struct { + BT_HDR_RIGID hdr; + RawAddress bd_addr; + tBTA_DM_SEARCH_CBACK* p_cback; + tBT_TRANSPORT transport; +} tBTA_DM_API_DISCOVER; + +typedef struct { + BT_HDR_RIGID hdr; +} tBTA_DM_API_DISCOVERY_CANCEL; + +typedef struct { + BT_HDR_RIGID hdr; + RawAddress bd_addr; + BD_NAME bd_name; /* Name of peer device. */ + tHCI_STATUS hci_status; +} tBTA_DM_REMOTE_NAME; + +/* data type for tBTA_DM_DISC_RESULT */ +typedef struct { + BT_HDR_RIGID hdr; + tBTA_DM_SEARCH result; +} tBTA_DM_DISC_RESULT; + +/* data type for BTA_DM_INQUIRY_CMPL_EVT */ +typedef struct { + BT_HDR_RIGID hdr; + uint8_t num; +} tBTA_DM_INQUIRY_CMPL; + +/* data type for BTA_DM_SDP_RESULT_EVT */ +typedef struct { + BT_HDR_RIGID hdr; + tSDP_RESULT sdp_result; +} tBTA_DM_SDP_RESULT; + +typedef struct { + BT_HDR_RIGID hdr; + bool enable; +} tBTA_DM_API_BLE_FEATURE; + +/* union of all data types */ +typedef union { + /* GKI event buffer header */ + BT_HDR_RIGID hdr; + + tBTA_DM_API_SEARCH search; + + tBTA_DM_API_DISCOVER discover; + + tBTA_DM_REMOTE_NAME remote_name_msg; + + tBTA_DM_DISC_RESULT disc_result; + + tBTA_DM_INQUIRY_CMPL inq_cmpl; + + tBTA_DM_SDP_RESULT sdp_event; + +} tBTA_DM_MSG; + +/* DM search state */ +typedef enum { + + BTA_DM_SEARCH_IDLE, + BTA_DM_SEARCH_ACTIVE, + BTA_DM_SEARCH_CANCELLING, + BTA_DM_DISCOVER_ACTIVE + +} tBTA_DM_STATE; + +inline std::string bta_dm_state_text(const tBTA_DM_STATE& state) { + switch (state) { + CASE_RETURN_TEXT(BTA_DM_SEARCH_IDLE); + CASE_RETURN_TEXT(BTA_DM_SEARCH_ACTIVE); + CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCELLING); + CASE_RETURN_TEXT(BTA_DM_DISCOVER_ACTIVE); + default: + return base::StringPrintf("UNKNOWN[%d]", state); + } +} +#undef CASE_RETURN_TEXT + +/* DM search control block */ +typedef struct { + tBTA_DM_SEARCH_CBACK* p_search_cback; + tBTM_INQ_INFO* p_btm_inq_info; + tBTA_SERVICE_MASK services; + tBTA_SERVICE_MASK services_to_search; + tBTA_SERVICE_MASK services_found; + tSDP_DISCOVERY_DB* p_sdp_db; + tBTA_DM_STATE state; + RawAddress peer_bdaddr; + bool name_discover_done; + BD_NAME peer_name; + alarm_t* search_timer; + uint8_t service_index; + tBTA_DM_MSG* p_pending_search; + fixed_queue_t* pending_discovery_queue; + bool wait_disc; + bool sdp_results; + bluetooth::Uuid uuid; + uint8_t peer_scn; + tBT_TRANSPORT transport; + tBTA_DM_SEARCH_CBACK* p_scan_cback; + tBTA_DM_SEARCH_CBACK* p_csis_scan_cback; + tGATT_IF client_if; + uint8_t uuid_to_search; + bool gatt_disc_active; + uint16_t conn_id; + alarm_t* gatt_close_timer; /* GATT channel close delay timer */ + RawAddress pending_close_bda; /* pending GATT channel remote device address */ + +} tBTA_DM_SEARCH_CB; + +extern const uint32_t bta_service_id_to_btm_srv_id_lkup_tbl[]; +extern const uint16_t bta_service_id_to_uuid_lkup_tbl[]; diff --git a/system/bta/dm/bta_dm_int.h b/system/bta/dm/bta_dm_int.h index 62066e901835c8f5f2a76c2f3cd17b4fb520f111..14b81476d4f92ed1d8afef9bac0c2364ca82ecfb 100644 --- a/system/bta/dm/bta_dm_int.h +++ b/system/bta/dm/bta_dm_int.h @@ -56,108 +56,6 @@ #define BTA_DM_MSG_LEN 50 -#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) - -/* DM search events */ -typedef enum : uint16_t { - /* DM search API events */ - BTA_DM_API_SEARCH_EVT = BTA_SYS_EVT_START(BTA_ID_DM_SEARCH), - BTA_DM_API_SEARCH_CANCEL_EVT, - BTA_DM_API_DISCOVER_EVT, - BTA_DM_INQUIRY_CMPL_EVT, - BTA_DM_REMT_NAME_EVT, - BTA_DM_SDP_RESULT_EVT, - BTA_DM_SEARCH_CMPL_EVT, - BTA_DM_DISCOVERY_RESULT_EVT, - BTA_DM_DISC_CLOSE_TOUT_EVT, -} tBTA_DM_EVT; - -inline std::string bta_dm_event_text(const tBTA_DM_EVT& event) { - switch (event) { - CASE_RETURN_TEXT(BTA_DM_API_SEARCH_EVT); - CASE_RETURN_TEXT(BTA_DM_API_SEARCH_CANCEL_EVT); - CASE_RETURN_TEXT(BTA_DM_API_DISCOVER_EVT); - CASE_RETURN_TEXT(BTA_DM_INQUIRY_CMPL_EVT); - CASE_RETURN_TEXT(BTA_DM_REMT_NAME_EVT); - CASE_RETURN_TEXT(BTA_DM_SDP_RESULT_EVT); - CASE_RETURN_TEXT(BTA_DM_SEARCH_CMPL_EVT); - CASE_RETURN_TEXT(BTA_DM_DISCOVERY_RESULT_EVT); - CASE_RETURN_TEXT(BTA_DM_DISC_CLOSE_TOUT_EVT); - default: - return base::StringPrintf("UNKNOWN[0x%04x]", event); - } -} - -/* data type for BTA_DM_API_SEARCH_EVT */ -typedef struct { - BT_HDR_RIGID hdr; - tBTA_SERVICE_MASK services; - tBTA_DM_SEARCH_CBACK* p_cback; -} tBTA_DM_API_SEARCH; - -/* data type for BTA_DM_API_DISCOVER_EVT */ -typedef struct { - BT_HDR_RIGID hdr; - RawAddress bd_addr; - tBTA_DM_SEARCH_CBACK* p_cback; - tBT_TRANSPORT transport; -} tBTA_DM_API_DISCOVER; - -typedef struct { - BT_HDR_RIGID hdr; -} tBTA_DM_API_DISCOVERY_CANCEL; - - -typedef struct { - BT_HDR_RIGID hdr; - RawAddress bd_addr; - BD_NAME bd_name; /* Name of peer device. */ - tHCI_STATUS hci_status; -} tBTA_DM_REMOTE_NAME; - -/* data type for tBTA_DM_DISC_RESULT */ -typedef struct { - BT_HDR_RIGID hdr; - tBTA_DM_SEARCH result; -} tBTA_DM_DISC_RESULT; - -/* data type for BTA_DM_INQUIRY_CMPL_EVT */ -typedef struct { - BT_HDR_RIGID hdr; - uint8_t num; -} tBTA_DM_INQUIRY_CMPL; - -/* data type for BTA_DM_SDP_RESULT_EVT */ -typedef struct { - BT_HDR_RIGID hdr; - tSDP_RESULT sdp_result; -} tBTA_DM_SDP_RESULT; - - -typedef struct { - BT_HDR_RIGID hdr; - bool enable; -} tBTA_DM_API_BLE_FEATURE; - -/* union of all data types */ -typedef union { - /* GKI event buffer header */ - BT_HDR_RIGID hdr; - - tBTA_DM_API_SEARCH search; - - tBTA_DM_API_DISCOVER discover; - - tBTA_DM_REMOTE_NAME remote_name_msg; - - tBTA_DM_DISC_RESULT disc_result; - - tBTA_DM_INQUIRY_CMPL inq_cmpl; - - tBTA_DM_SDP_RESULT sdp_event; - -} tBTA_DM_MSG; - #define BTA_DM_NUM_PEER_DEVICE 7 typedef enum : uint8_t { @@ -339,60 +237,8 @@ typedef struct { alarm_t* switch_delay_timer; } tBTA_DM_CB; -/* DM search state */ -typedef enum { - - BTA_DM_SEARCH_IDLE, - BTA_DM_SEARCH_ACTIVE, - BTA_DM_SEARCH_CANCELLING, - BTA_DM_DISCOVER_ACTIVE - -} tBTA_DM_STATE; - -inline std::string bta_dm_state_text(const tBTA_DM_STATE& state) { - switch (state) { - CASE_RETURN_TEXT(BTA_DM_SEARCH_IDLE); - CASE_RETURN_TEXT(BTA_DM_SEARCH_ACTIVE); - CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCELLING); - CASE_RETURN_TEXT(BTA_DM_DISCOVER_ACTIVE); - default: - return base::StringPrintf("UNKNOWN[%d]", state); - } -} #undef CASE_RETURN_TEXT -/* DM search control block */ -typedef struct { - tBTA_DM_SEARCH_CBACK* p_search_cback; - tBTM_INQ_INFO* p_btm_inq_info; - tBTA_SERVICE_MASK services; - tBTA_SERVICE_MASK services_to_search; - tBTA_SERVICE_MASK services_found; - tSDP_DISCOVERY_DB* p_sdp_db; - tBTA_DM_STATE state; - RawAddress peer_bdaddr; - bool name_discover_done; - BD_NAME peer_name; - alarm_t* search_timer; - uint8_t service_index; - tBTA_DM_MSG* p_pending_search; - fixed_queue_t* pending_discovery_queue; - bool wait_disc; - bool sdp_results; - bluetooth::Uuid uuid; - uint8_t peer_scn; - tBT_TRANSPORT transport; - tBTA_DM_SEARCH_CBACK* p_scan_cback; - tBTA_DM_SEARCH_CBACK* p_csis_scan_cback; - tGATT_IF client_if; - uint8_t uuid_to_search; - bool gatt_disc_active; - uint16_t conn_id; - alarm_t* gatt_close_timer; /* GATT channel close delay timer */ - RawAddress pending_close_bda; /* pending GATT channel remote device address */ - -} tBTA_DM_SEARCH_CB; - /* DI control block */ typedef struct { uint8_t di_num; /* total local DI record number */ diff --git a/system/bta/test/bta_disc_test.cc b/system/bta/test/bta_disc_test.cc index e37631ebf029212360ee6060bdf4e86fc2de431c..2dbac0af0d44755dca52b10d89206980af5b27b4 100644 --- a/system/bta/test/bta_disc_test.cc +++ b/system/bta/test/bta_disc_test.cc @@ -22,7 +22,7 @@ #include <memory> #include "bta/dm/bta_dm_disc.h" -#include "bta/dm/bta_dm_int.h" +#include "bta/dm/bta_dm_disc_int.h" #include "stack/btm/neighbor_inquiry.h" #include "stack/include/gatt_api.h" #include "test/common/main_handler.h" diff --git a/system/bta/test/bta_dm_test.cc b/system/bta/test/bta_dm_test.cc index 5708538d271f86dd038a1219442f8b4b65808317..7c943752348ca629cd6acc6b699812a642b7de37 100644 --- a/system/bta/test/bta_dm_test.cc +++ b/system/bta/test/bta_dm_test.cc @@ -22,6 +22,7 @@ #include <string> #include "bta/dm/bta_dm_disc.h" +#include "bta/dm/bta_dm_disc_int.h" #include "bta/dm/bta_dm_int.h" #include "bta/dm/bta_dm_sec_int.h" #include "bta/hf_client/bta_hf_client_int.h" diff --git a/system/bta/test/bta_sdp_test.cc b/system/bta/test/bta_sdp_test.cc index 96754d8f2b96408b75f8cbf49bbfa45421f56e16..7a8c036c149e3911cfb777f8d8f4726b56b4f0dd 100644 --- a/system/bta/test/bta_sdp_test.cc +++ b/system/bta/test/bta_sdp_test.cc @@ -19,7 +19,7 @@ #include <string> -#include "bta/dm/bta_dm_int.h" +#include "bta/dm/bta_dm_disc_int.h" #include "bta/test/bta_base_test.h" #include "osi/include/allocator.h" #include "test/common/main_handler.h" diff --git a/system/test/mock/mock_bta_dm_act.h b/system/test/mock/mock_bta_dm_act.h index 9dd162cb60d536ee6db25bfaa0e34b1d06c59948..1450c0bd5479f83ce7c5d3c5bc191ed9de0ad239 100644 --- a/system/test/mock/mock_bta_dm_act.h +++ b/system/test/mock/mock_bta_dm_act.h @@ -27,7 +27,7 @@ // Original included files, if any #include <cstdint> -#include "bta/dm/bta_dm_int.h" +#include "bta/dm/bta_dm_disc_int.h" #include "bta/dm/bta_dm_sec_int.h" #include "types/raw_address.h"