1 /*
2  * Copyright 2024 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 #pragma once
17 
18 #include <cstdint>
19 
20 #include "stack/include/bt_name.h"
21 #include "stack/include/btm_status.h"
22 #include "stack/include/hci_error_code.h"
23 #include "stack/include/security_client_callbacks.h"
24 #include "types/raw_address.h"
25 
26 /* Structure returned with remote name request */
27 struct tBTM_REMOTE_DEV_NAME {
28   RawAddress bd_addr;
29   BD_NAME remote_bd_name;
30   tBTM_STATUS btm_status;
31   tHCI_STATUS hci_status;
32 };
33 
34 typedef void(tBTM_NAME_CMPL_CB)(const tBTM_REMOTE_DEV_NAME*);
35 
36 namespace bluetooth {
37 namespace stack {
38 namespace rnr {
39 
40 class Interface {
41 public:
42   virtual ~Interface() = default;
43 
44   /*******************************************************************************
45    *
46    * Function         BTM_SecAddRmtNameNotifyCallback
47    *
48    * Description      Any profile can register to be notified when name of the
49    *                  remote device is resolved.
50    *
51    * Parameters       p_callback: Callback to add after each remote name
52    *                  request has completed or timed out.
53    *
54    * Returns          true if registered OK, else false
55    *
56    ******************************************************************************/
57   virtual bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback) = 0;
58 
59   /*******************************************************************************
60    *
61    * Function         BTM_SecDeleteRmtNameNotifyCallback
62    *
63    * Description      Any profile can deregister notification when a new Link Key
64    *                  is generated per connection.
65    *
66    * Parameters       p_callback: Callback to remove after each remote name
67    *                  request has completed or timed out.
68    *
69    * Returns          true if unregistered OK, else false
70    *
71    ******************************************************************************/
72   virtual bool BTM_SecDeleteRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback) = 0;
73 
74   /*******************************************************************************
75    *
76    * Function         BTM_IsRemoteNameKnown
77    *
78    * Description      Look up the device record using the bluetooth device
79    *                  address and if a record is found check if the name
80    *                  has been acquired and cached.
81    *
82    * Parameters       bd_addr: Bluetooth device address
83    *                  transport: Transport used to retrieve remote name
84    *
85    * Returns          true if name is cached, false otherwise
86    *
87    ******************************************************************************/
88   virtual bool BTM_IsRemoteNameKnown(const RawAddress& bd_addr, tBT_TRANSPORT transport) = 0;
89 
90   /*******************************************************************************
91    *
92    * Function         BTM_ReadRemoteDeviceName
93    *
94    * Description      This function initiates a remote device HCI command to the
95    *                  controller and calls the callback when the process has
96    *                  completed.
97    *
98    * Parameters       bd_addr      - bluetooth device address of name to
99    *                                    retrieve
100    *                  p_callback            - callback function called when
101    *                                    remote name is received or when procedure
102    *                                    timed out.
103    *                  transport       - transport used to query the remote name
104    *
105    * Returns          tBTM_STATUS::BTM_CMD_STARTED is returned if the request was
106    *                                    successfully sent to HCI.
107    *                  tBTM_STATUS::BTM_BUSY if already in progress
108    *                  tBTM_STATUS::BTM_UNKNOWN_ADDR if device address is bad
109    *                  tBTM_STATUS::BTM_NO_RESOURCES if could not allocate resources to start
110    *                                   the command
111    *                  tBTM_STATUS::BTM_WRONG_MODE if the device is not up.
112    *
113    ******************************************************************************/
114   virtual tBTM_STATUS BTM_ReadRemoteDeviceName(const RawAddress& bd_addr,
115                                                tBTM_NAME_CMPL_CB* p_callback,
116                                                tBT_TRANSPORT transport) = 0;
117 
118   /*******************************************************************************
119    *
120    * Function         BTM_CancelRemoteDeviceName
121    *
122    * Description      This function initiates the cancel request for the outstanding
123    *                  specified remote device.
124    *
125    * Parameters       None
126    *
127    * Returns          tBTM_STATUS::BTM_CMD_STARTED is returned if the request was
128    *                                 successfully sent to HCI.
129    *                  tBTM_STATUS::BTM_NO_RESOURCES if could not allocate resources to start
130    *                                 the command
131    *                  tBTM_STATUS::BTM_WRONG_MODE if there is not an active remote name
132    *                                 request.
133    *
134    ******************************************************************************/
135   virtual tBTM_STATUS BTM_CancelRemoteDeviceName() = 0;
136 
137   /*******************************************************************************
138    *
139    * Function         btm_process_remote_name
140    *
141    * Description      This function is called when a remote name is received from
142    *                  the device. If remote names are cached, it updates the
143    *                  inquiry database.
144    *
145    * Parameters       bd_addr      - bluetooth device address of name to
146    *                                    retrieve
147    *                  bd_name      - bluetooth device name
148    *                  evt_len      - length of blueooth device name
149    *                  hci_status   - Hci event status
150    *
151    * Returns          void
152    *
153    ******************************************************************************/
154   virtual void btm_process_remote_name(const RawAddress* bd_addr, const BD_NAME bd_name,
155                                        uint16_t evt_len, tHCI_STATUS hci_status) = 0;
156 };
157 
158 }  // namespace rnr
159 }  // namespace stack
160 }  // namespace bluetooth
161 
162 bluetooth::stack::rnr::Interface& get_stack_rnr_interface();
163