1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines basic adapter for classic adapter and ble adapter.
21  *
22  * @since 6
23  */
24 
25 /**
26  * @file interface_adapter.h
27  *
28  * @brief basic adapter interface.
29  *
30  * @since 6
31  */
32 
33 #ifndef INTERFACE_ADAPTER_H
34 #define INTERFACE_ADAPTER_H
35 
36 #include <string>
37 #include <vector>
38 
39 #include "bt_def.h"
40 #include "bt_uuid.h"
41 #include "raw_address.h"
42 
43 /**
44  * @brief bluetooth adapter name Define
45  */
46 const std::string ADAPTER_NAME_CLASSIC = "ClassicAdapter";
47 const std::string ADAPTER_NAME_BLE = "BleAdapter";
48 
49 /**
50  * @brief forward declaration for class Context in namespace utility
51  */
52 namespace utility {
53 class Context;
54 }
55 
56 namespace OHOS {
57 namespace bluetooth {
58 /**
59  * @brief Represents basic adapter for classic and ble, including the common functions.
60  *
61  * @since 6
62  */
63 class IAdapter {
64 public:
65     /**
66      * @brief A destructor used to delete the <b>IAdapter</b> instance.
67      *
68      * @since 6
69      */
70     virtual ~IAdapter() = default;
71 
72     /// gap
73     /**
74      * @brief Get local device address.
75      *
76      * @return Returns local device address.
77      * @since 6
78      */
79     virtual std::string GetLocalAddress() const = 0;
80 
81     /**
82      * @brief Get local device name.
83      *
84      * @return Returns local device name.
85      * @since 6
86      */
87     virtual std::string GetLocalName() const = 0;
88 
89     /**
90      * @brief Set local device name.
91      *
92      * @return Returns <b>true</b> if the operation is successful;
93      *         returns <b>false</b> if the operation fails.
94      * @since 6
95      */
96     virtual bool SetLocalName(const std::string &name) const = 0;
97 
98     /**
99      * @brief Set local device bondable mode.
100      *
101      * @return Returns <b>true</b> if the operation is successful;
102      *         returns <b>false</b> if the operation fails.
103      * @since 6
104      */
105     virtual bool SetBondableMode(int mode) const = 0;
106 
107     /**
108      * @brief Get local device bondable mode.
109      *
110      * @return Returns local device bondable mode.
111      * @since 6
112      */
113     virtual int GetBondableMode() const = 0;
114 
115     /// remote device information
116     /**
117      * @brief Get remote device type.
118      *
119      * @param device Remote device address.
120      * @return Returns remote device type.
121      * @since 6
122      */
123     virtual int GetDeviceType(const RawAddress &device) const = 0;
124 
125     /**
126      * @brief Get remote device name.
127      *
128      * @param device Remote device address.
129      * @return Returns remote device name.
130      * @since 6
131      */
132     virtual std::string GetDeviceName(const RawAddress &device) const = 0;
133 
134     /**
135      * @brief Get remote device uuids.
136      *
137      * @param device Remote device address.
138      * @return Returns remote device uuids vector.
139      * @since 6
140      */
141     virtual std::vector<Uuid> GetDeviceUuids(const RawAddress &device) const = 0;
142 
143     /// pair
144     /**
145      * @brief Get paired devices.
146      *
147      * @return Returns paired devices vector.
148      * @since 6
149      */
150     virtual std::vector<RawAddress> GetPairedDevices() const = 0;
151 
152     /**
153      * @brief Get remote device uuids.
154      *
155      * @param device Remote device address.
156      * @return Returns <b>true</b> if the operation is successful;
157      *         returns <b>false</b> if the operation fails.
158      * @since 6
159      */
160     virtual bool StartPair(const RawAddress &device) = 0;
161 
162     /**
163      * @brief Check if device was bonded from local.
164      *
165      * @param device Remote device address.
166      * @return Returns <b>true</b> if device was bonded from local;
167      *         returns <b>false</b> if device was not bonded from local.
168      * @since 6
169      */
170     virtual bool IsBondedFromLocal(const RawAddress &device) const = 0;
171 
172     /**
173      * @brief Cancel pair operation.
174      *
175      * @param device Remote device address.
176      * @return Returns <b>true</b> if the operation is successful;
177      *         returns <b>false</b> if the operation fails.
178      * @since 6
179      */
180     virtual bool CancelPairing(const RawAddress &device) = 0;
181 
182     /**
183      * @brief Remove pair.
184      *
185      * @param device Remote device address.
186      * @return Returns <b>true</b> if the operation is successful;
187      *         returns <b>false</b> if the operation fails.
188      * @since 6
189      */
190     virtual bool RemovePair(const RawAddress &device) = 0;
191 
192     /**
193      * @brief Remove all pairs.
194      *
195      * @return Returns <b>true</b> if the operation is successful;
196      *         returns <b>false</b> if the operation fails.
197      * @since 6
198      */
199     virtual bool RemoveAllPairs() = 0;
200 
201     /**
202      * @brief Get device pair state.
203      *
204      * @param device Remote device address.
205      * @return Returns device pair state.
206      * @since 6
207      */
208     virtual int GetPairState(const RawAddress &device) const = 0;
209 
210     /**
211      * @brief Set device pairing confirmation.
212      *
213      * @param device Remote device address.
214      * @param accept Set gap accept flag.
215      * @return Returns <b>true</b> if the operation is successful;
216      *         returns <b>false</b> if the operation fails.
217      * @since 6
218      */
219     virtual bool SetDevicePairingConfirmation(const RawAddress &device, bool accept) const = 0;
220 
221     /**
222      * @brief Set device pair passkey.
223      *
224      * @param device Remote device address.
225      * @param passkey Device passkey.
226      * @param accept Set gap accept flag.
227      * @return Returns <b>true</b> if the operation is successful;
228      *         returns <b>false</b> if the operation fails.
229      * @since 6
230      */
231     virtual bool SetDevicePasskey(const RawAddress &device, int passkey, bool accept) const = 0;
232 
233     /**
234      * @brief Check device pair request reply.
235      *
236      * @param device Remote device address.
237      * @param accept Set gap accept flag.
238      * @return Returns <b>true</b> if the operation is successful;
239      *         returns <b>false</b> if the operation fails.
240      * @since 6
241      */
242     virtual bool PairRequestReply(const RawAddress &device, bool accept) const = 0;
243 
244     /// other
245     /**
246      * @brief Check if device acl connected.
247      *
248      * @param device Remote device address.
249      * @return Returns <b>true</b> if device acl connected;
250      *         returns <b>false</b> if device does not acl connect.
251      * @since 6
252      */
253     virtual bool IsAclConnected(const RawAddress &device) const = 0;
254 
255     /**
256      * @brief Check if device acl Encrypted.
257      *
258      * @param device Remote device address.
259      * @return Returns <b>true</b> if device acl Encrypted;
260      *         returns <b>false</b> if device does not acl Encrypt.
261      * @since 6
262      */
263     virtual bool IsAclEncrypted(const RawAddress &device) const = 0;
264 
265     /**
266      * @brief Get utility::Context pointer for adapter.
267      *
268      * @return Returns the pointer for adapter.
269      * @since 6
270      */
271     virtual utility::Context *GetContext() = 0;
272 };
273 }  // namespace bluetooth
274 }  // namespace OHOS
275 
276 #endif  // INTERFACE_ADAPTER_H