1 /*
2  * Copyright (C) 2021-2022 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 remote device , including common functions.
21  *
22  */
23 
24 /**
25  * @file classic_remote_device.h
26  *
27  * @brief Classic remote device common functions.
28  *
29  */
30 
31 #ifndef REMOTE_DEVICE_H
32 #define REMOTE_DEVICE_H
33 
34 #include <memory>
35 #include <string>
36 #include <vector>
37 
38 #include "base_def.h"
39 #include "bt_def.h"
40 #include "bt_uuid.h"
41 #include "classic_defs.h"
42 
43 namespace OHOS {
44 namespace bluetooth {
45 /**
46  * @brief Represents remote device.
47  *
48  */
49 class ClassicRemoteDevice {
50 public:
51     /**
52      * @brief A constructor used to create a <b>ClassicRemoteDevice</b> instance.
53      *
54      */
55     ClassicRemoteDevice();
56 
57     /**
58      * @brief A constructor used to create a <b>ClassicRemoteDevice</b> instance.
59      *
60      * @param addr Device address create an <b>ClassicRemoteDevice</b> instance.
61      */
62     explicit ClassicRemoteDevice(const std::string &addr);
63 
64     /**
65      * @brief A destructor used to delete the <b>ClassicRemoteDevice</b> instance.
66      *
67      */
68     ~ClassicRemoteDevice();
69 
70     /**
71      * @brief Get device type.
72      *
73      * @return Returns device type.
74      */
75     int GetDeviceType() const;
76 
77     /**
78      * @brief Get device address.
79      *
80      * @return Returns device address.
81      */
82     std::string GetAddress() const;
83 
84     /**
85      * @brief Get remote device name.
86      *
87      * @return Returns remote device name.
88      */
89     std::string GetRemoteName() const;
90 
91     /**
92      * @brief Get device alias name.
93      *
94      * @return Returns device alias name.
95      */
96     std::string GetAliasName() const;
97 
98     /**
99      * @brief Get device class.
100      *
101      * @return Returns device class.
102      */
103     int GetDeviceClass() const;
104 
105     /**
106      * @brief Get device uuids.
107      *
108      * @return Returns device uuids vector.
109      */
110     std::vector<Uuid> GetDeviceUuids() const;
111 
112     /**
113      * @brief Get acl connection handle.
114      *
115      * @return Returns acl connection handle;
116      */
117     int GetConnectionHandle() const;
118 
119     /**
120      * @brief Get paired status.
121      *
122      * @return Returns paired status.
123      */
124     int GetPairedStatus() const;
125 
126     /**
127      * @brief Get link key.
128      *
129      * @return Returns link key.
130      */
131     std::vector<uint8_t> GetLinkKey() const;
132 
133     /**
134      * @brief Get link key type.
135      *
136      * @return Returns link key type.
137      */
138     int GetLinkKeyType() const;
139 
140     /**
141      * @brief Get IO capability.
142      *
143      * @return Returns IO capability.
144      */
145     int GetIoCapability() const;
146 
147     /**
148      * @brief Get device flags.
149      *
150      * @return Returns flags.
151      */
152     uint8_t GetFlags() const;
153 
154     /**
155      * @brief Check if remote device already paired.
156      *
157      * @return Returns <b>true</b> if remote device already paired;
158      *         returns <b>false</b> if remote device not paired.
159      */
160     bool IsPaired() const;
161 
162     /**
163      * @brief Get pair confirm state.
164      *
165      * @return Returns pair confirm state.
166      */
167     int GetPairConfirmState() const;
168 
169     /**
170      * @brief Get pair confirm type.
171      *
172      * @return Returns pair confirm type.
173      */
174     int GetPairConfirmType() const;
175 
176     /**
177      * @brief Get battery level.
178      *
179      * @return Returns batteryLevel.
180      */
181     int GetBatteryLevel() const;
182 
183     /**
184      * @brief Set battery level.
185      *
186      * @param batteryLevel battery level.
187      */
188     void SetBatteryLevel(int batteryLevel);
189 
190     /**
191      * @brief set rssi value.
192      *
193      * @param rssi Rssi value.
194      */
195     void SetRssi(int rssi);
196 
197     /**
198      * @brief Set device type.
199      *
200      * @param type Device type.
201      */
202     void SetDeviceType(int type);
203 
204     /**
205      * @brief Set device address.
206      *
207      * @param addr Device address.
208      */
209     void SetAddress(const std::string &addr);
210 
211     /**
212      * @brief Set remote device name.
213      *
214      * @param name Device name.
215      */
216     void SetRemoteName(const std::string &name);
217 
218     /**
219      * @brief Set alias name.
220      *
221      * @param name Device alias name.
222      * @return Returns <b>true</b> if the operation is successful;
223      *         returns <b>false</b> if the operation fails.
224      */
225     bool SetAliasName(const std::string &name);
226 
227     /**
228      * @brief Set device class.
229      *
230      * @param deviceClass Device class.
231      */
232     void SetDeviceClass(int deviceClass);
233 
234     /**
235      * @brief Set bonded from local.
236      *
237      * @param flag Advertiser flag.
238      */
239     void SetBondedFromLocal(bool flag);
240 
241     /**
242      * @brief Set acl connect state.
243      *
244      * @param connectState Acl connect state.
245      */
246     void SetAclConnectState(int connectState);
247 
248     /**
249      * @brief Set device uuids.
250      *
251      * @param uuids Device uuids.
252      */
253     void SetDeviceUuids(const std::vector<Uuid> &uuids);
254 
255     /**
256      * @brief Set acl connection handle.
257      *
258      * @param handle Acl connection handle.
259      */
260     void SetConnectionHandle(int handle);
261 
262     /**
263      * @brief Set link key.
264      *
265      * @param linkKey Link key.
266      */
267     void SetLinkKey(const std::vector<uint8_t> &linkKey);
268 
269     /**
270      * @brief Set link key type.
271      *
272      * @param linkKey Link key type.
273      */
274     void SetLinkKeyType(int linkKeyType);
275 
276     /**
277      * @brief Set IO capability.
278      *
279      * @param io IO capability
280      */
281     void SetIoCapability(int io);
282 
283     /**
284      * @brief Set device flags.
285      *
286      * @param flags Device flags.
287      */
288     void SetFlags(uint8_t flags);
289 
290     /**
291      * @brief Set device manufacturer-specific data.
292      *
293      * @param data Manufacturer-specific data.
294      * @param length Data length.
295      */
296     void SetManufacturerSpecificData(const std::vector<uint8_t> &data);
297 
298     /**
299      * @brief Set device Tx power.
300      *
301      * @param power Device Tx power.
302      */
303     void SetTxPower(uint8_t power);
304 
305     /**
306      * @brief Set device URI.
307      *
308      * @param uri Device URI.
309      */
310     void SetURI(const std::string &uri);
311 
312     /**
313      * @brief Set pair confirm state.
314      *
315      * @param state Pair confirm state.
316      */
317     void SetPairConfirmState(int state);
318 
319     /**
320      * @brief Set pair confirm type.
321      *
322      * @param type Pair confirm type.
323      */
324     void SetPairConfirmType(int type);
325 
326     /**
327      * @brief Check if device acl connected.
328      *
329      * @return Returns <b>true</b> if device acl connected;
330      *         returns <b>false</b> if device does not acl connect.
331      */
332     bool IsAclConnected() const;
333 
334     /**
335      * @brief Check if device acl encrypted.
336      *
337      * @return Returns <b>true</b> if device acl encrypted;
338      *         returns <b>false</b> if device does not acl encrypted.
339      */
340     bool IsAclEncrypted() const;
341 
342     /**
343      * @brief Check if device was bonded from local.
344      *
345      * @return Returns <b>true</b> if device was bonded from local;
346      *         returns <b>false</b> if device was not bonded from local.
347      */
348     bool IsBondedFromLocal() const;
349 
350     /**
351      * @brief Delete link key.
352      *
353      */
354     void DeleteLinkKey();
355 
356     /**
357      * @brief Set paired status.
358      *
359      * @param status Paired status.
360      * @return Returns <b>true</b> if the operation is successful;
361      *         returns <b>false</b> if the operation fails.
362      */
363     bool SetPairedStatus(int status);
364 
365     /**
366      * @brief Save paired device info.
367      *
368      */
369     void SavePairedDeviceInfo();
370 
371     /**
372      * @brief Remote paired device info.
373      *
374      */
375     void RemotePairedInfo();
376 
377     void SetNameNeedGet(bool nameUnknowned);
378     bool GetNameNeedGet() const;
379     bool CheckCod(uint32_t cod) const;
380 
381 private:
382     bool bondedFromLocal_ {};
383     bool nameNeedGet_ {};
384     bool aclConnected_ {};
385     uint8_t flags_ {};
386     uint8_t txPower_ {};
387 
388     int cod_ {};
389     int rssi_ {};
390     int deviceType_ {REMOTE_TYPE_BREDR};
391     int connectionHandle_ {};
392     int pairState_ {};
393     int pairConfirmType_ {PAIR_CONFIRM_TYPE_INVALID};
394     int pairConfirmState_ {PAIR_CONFIRM_STATE_INVALID};
395     int linkKeyType_ {PAIR_INVALID_LINK_KEY_TYPE};
396     int ioCapability_ {};
397     int batteryLevel_ {};
398 
399     std::string macAddr_ {INVALID_MAC_ADDRESS};
400     std::string deviceName_ {INVALID_NAME};
401     std::string aliasName_ {INVALID_NAME};
402     std::string uri_ {};
403     std::vector<uint8_t> manuSpecData_ {};
404     std::vector<uint8_t> linkKey_ {};
405     std::vector<Uuid> uuids_ {};
406 
407     BT_DISALLOW_COPY_AND_ASSIGN(ClassicRemoteDevice);
408 };
409 }  // namespace bluetooth
410 }  // namespace OHOS
411 #endif  // REMOTE_DEVICE_H