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