• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <bluetooth/log.h>
20 
21 #include <string>
22 
23 #include "bta/include/bta_api.h"
24 #include "macros.h"
25 #include "stack/btm/neighbor_inquiry.h"
26 #include "types/raw_address.h"
27 
28 /* DM search events */
29 typedef enum : uint16_t {
30   /* DM search API events */
31   BTA_DM_API_SEARCH_EVT,
32   BTA_DM_API_SEARCH_CANCEL_EVT,
33   BTA_DM_INQUIRY_CMPL_EVT,
34   BTA_DM_REMT_NAME_EVT,
35   BTA_DM_SEARCH_CMPL_EVT,
36 } tBTA_DM_DEV_SEARCH_EVT;
37 
bta_dm_event_text(const tBTA_DM_DEV_SEARCH_EVT & event)38 inline std::string bta_dm_event_text(const tBTA_DM_DEV_SEARCH_EVT& event) {
39   switch (event) {
40     CASE_RETURN_TEXT(BTA_DM_API_SEARCH_EVT);
41     CASE_RETURN_TEXT(BTA_DM_API_SEARCH_CANCEL_EVT);
42     CASE_RETURN_TEXT(BTA_DM_INQUIRY_CMPL_EVT);
43     CASE_RETURN_TEXT(BTA_DM_REMT_NAME_EVT);
44     CASE_RETURN_TEXT(BTA_DM_SEARCH_CMPL_EVT);
45   }
46 }
47 
48 /* data type for BTA_DM_API_SEARCH_EVT */
49 typedef struct {
50   tBTA_DM_SEARCH_CBACK* p_cback;
51 } tBTA_DM_API_SEARCH;
52 
53 typedef struct {
54   RawAddress bd_addr;
55   BD_NAME bd_name; /* Name of peer device. */
56   tHCI_STATUS hci_status;
57 } tBTA_DM_REMOTE_NAME;
58 
59 using tBTA_DM_SEARCH_MSG = std::variant<tBTA_DM_API_SEARCH, tBTA_DM_REMOTE_NAME>;
60 
61 /* DM search state */
62 typedef enum {
63   BTA_DM_SEARCH_IDLE,
64   BTA_DM_SEARCH_ACTIVE,
65   BTA_DM_SEARCH_CANCELLING,
66 } tBTA_DM_DEVICE_SEARCH_STATE;
67 
bta_dm_state_text(const tBTA_DM_DEVICE_SEARCH_STATE & state)68 inline std::string bta_dm_state_text(const tBTA_DM_DEVICE_SEARCH_STATE& state) {
69   switch (state) {
70     CASE_RETURN_TEXT(BTA_DM_SEARCH_IDLE);
71     CASE_RETURN_TEXT(BTA_DM_SEARCH_ACTIVE);
72     CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCELLING);
73   }
74 }
75 
76 /* DM search control block */
77 typedef struct {
78   tBTA_DM_SEARCH_CBACK* p_device_search_cback;
79   tBTM_INQ_INFO* p_btm_inq_info;
80   /* This covers device search state. That is scanning through android Settings
81    * to discover LE and Classic devices. Runs Name discovery on Inquiry Results
82    */
83   tBTA_DM_DEVICE_SEARCH_STATE search_state;
84   bool name_discover_done;
85   /* peer address used for name discovery */
86   RawAddress peer_bdaddr;
87   BD_NAME peer_name;
88   std::unique_ptr<tBTA_DM_SEARCH_MSG> p_pending_search;
89   tBTA_DM_SEARCH_CBACK* p_csis_scan_cback;
90 } tBTA_DM_SEARCH_CB;
91 
92 namespace std {
93 template <>
94 struct formatter<tBTA_DM_DEV_SEARCH_EVT> : enum_formatter<tBTA_DM_DEV_SEARCH_EVT> {};
95 template <>
96 struct formatter<tBTA_DM_DEVICE_SEARCH_STATE> : enum_formatter<tBTA_DM_DEVICE_SEARCH_STATE> {};
97 }  // namespace std
98