summaryrefslogtreecommitdiff
path: root/system/stack/include/rnr_interface.h
blob: d92be57b9a8216789e08b17ac62de3806a4e83ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright 2024 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 <cstdint>

#include "stack/include/bt_name.h"
#include "stack/include/btm_status.h"
#include "stack/include/hci_error_code.h"
#include "stack/include/security_client_callbacks.h"
#include "types/raw_address.h"

/* Structure returned with remote name request */
struct tBTM_REMOTE_DEV_NAME {
  RawAddress bd_addr;
  BD_NAME remote_bd_name;
  tBTM_STATUS btm_status;
  tHCI_STATUS hci_status;
};

typedef void(tBTM_NAME_CMPL_CB)(const tBTM_REMOTE_DEV_NAME*);

namespace bluetooth {
namespace stack {
namespace rnr {

class Interface {
public:
  virtual ~Interface() = default;

  /*******************************************************************************
   *
   * Function         BTM_SecAddRmtNameNotifyCallback
   *
   * Description      Any profile can register to be notified when name of the
   *                  remote device is resolved.
   *
   * Parameters       p_callback: Callback to add after each remote name
   *                  request has completed or timed out.
   *
   * Returns          true if registered OK, else false
   *
   ******************************************************************************/
  virtual bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback) = 0;

  /*******************************************************************************
   *
   * Function         BTM_SecDeleteRmtNameNotifyCallback
   *
   * Description      Any profile can deregister notification when a new Link Key
   *                  is generated per connection.
   *
   * Parameters       p_callback: Callback to remove after each remote name
   *                  request has completed or timed out.
   *
   * Returns          true if unregistered OK, else false
   *
   ******************************************************************************/
  virtual bool BTM_SecDeleteRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback) = 0;

  /*******************************************************************************
   *
   * Function         BTM_IsRemoteNameKnown
   *
   * Description      Look up the device record using the bluetooth device
   *                  address and if a record is found check if the name
   *                  has been acquired and cached.
   *
   * Parameters       bd_addr: Bluetooth device address
   *                  transport: Transport used to retrieve remote name
   *
   * Returns          true if name is cached, false otherwise
   *
   ******************************************************************************/
  virtual bool BTM_IsRemoteNameKnown(const RawAddress& bd_addr, tBT_TRANSPORT transport) = 0;

  /*******************************************************************************
   *
   * Function         BTM_ReadRemoteDeviceName
   *
   * Description      This function initiates a remote device HCI command to the
   *                  controller and calls the callback when the process has
   *                  completed.
   *
   * Parameters       bd_addr      - bluetooth device address of name to
   *                                    retrieve
   *                  p_callback            - callback function called when
   *                                    remote name is received or when procedure
   *                                    timed out.
   *                  transport       - transport used to query the remote name
   *
   * Returns          tBTM_STATUS::BTM_CMD_STARTED is returned if the request was
   *                                    successfully sent to HCI.
   *                  tBTM_STATUS::BTM_BUSY if already in progress
   *                  tBTM_STATUS::BTM_UNKNOWN_ADDR if device address is bad
   *                  tBTM_STATUS::BTM_NO_RESOURCES if could not allocate resources to start
   *                                   the command
   *                  tBTM_STATUS::BTM_WRONG_MODE if the device is not up.
   *
   ******************************************************************************/
  virtual tBTM_STATUS BTM_ReadRemoteDeviceName(const RawAddress& bd_addr,
                                               tBTM_NAME_CMPL_CB* p_callback,
                                               tBT_TRANSPORT transport) = 0;

  /*******************************************************************************
   *
   * Function         BTM_CancelRemoteDeviceName
   *
   * Description      This function initiates the cancel request for the outstanding
   *                  specified remote device.
   *
   * Parameters       None
   *
   * Returns          tBTM_STATUS::BTM_CMD_STARTED is returned if the request was
   *                                 successfully sent to HCI.
   *                  tBTM_STATUS::BTM_NO_RESOURCES if could not allocate resources to start
   *                                 the command
   *                  tBTM_STATUS::BTM_WRONG_MODE if there is not an active remote name
   *                                 request.
   *
   ******************************************************************************/
  virtual tBTM_STATUS BTM_CancelRemoteDeviceName() = 0;

  /*******************************************************************************
   *
   * Function         btm_process_remote_name
   *
   * Description      This function is called when a remote name is received from
   *                  the device. If remote names are cached, it updates the
   *                  inquiry database.
   *
   * Parameters       bd_addr      - bluetooth device address of name to
   *                                    retrieve
   *                  bd_name      - bluetooth device name
   *                  evt_len      - length of blueooth device name
   *                  hci_status   - Hci event status
   *
   * Returns          void
   *
   ******************************************************************************/
  virtual void btm_process_remote_name(const RawAddress* bd_addr, const BD_NAME bd_name,
                                       uint16_t evt_len, tHCI_STATUS hci_status) = 0;
};

}  // namespace rnr
}  // namespace stack
}  // namespace bluetooth

bluetooth::stack::rnr::Interface& get_stack_rnr_interface();