• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BLE advertiser, peripheral deviceand central manager functions,
21  *  including scan settings and filters, advertising settings and data etc.
22  *
23  * @since 6
24  */
25 
26 /**
27  * @file ble_data.cpp
28  *
29  * @brief Ble data class.
30  *
31  * @since 6
32  */
33 
34 #ifndef BLE_SERVICE_DATA_H
35 #define BLE_SERVICE_DATA_H
36 
37 #include <cstddef>
38 #include <cstdint>
39 #include <map>
40 #include <vector>
41 #include <functional>
42 #include "bt_def.h"
43 #include "bt_uuid.h"
44 #include "cstdint"
45 #include "iosfwd"
46 #include "raw_address.h"
47 #include "string"
48 #include "utility"
49 
50 namespace OHOS {
51 namespace bluetooth {
52 /**
53  * @brief Represents scan settings.
54  *
55  * @since 6
56  */
57 class BleScanSettingsImpl {
58 public:
59     /**
60      * @brief A constructor used to create a <b>BleScanSettingsInternal</b> instance.
61      *
62      * @since 6
63      */
BleScanSettingsImpl()64     BleScanSettingsImpl(){};
65 
66     /**
67      * @brief A destructor used to delete the <b>BleScanSettingsInternal</b> instance.
68      *
69      * @since 6
70      */
~BleScanSettingsImpl()71     ~BleScanSettingsImpl(){};
72 
73     /**
74      * @brief Set report delay time.
75      *
76      * @param reportDelayMillis Report delay time.
77      * @since 6
78      */
79     void SetReportDelay(long reportDelayMillis = 0);
80 
81     /**
82      * @brief Get report delay time.
83      *
84      * @return Report delay time.
85      * @since 6
86      */
87     long GetReportDelayMillisValue() const;
88 
89     /**
90      * @brief Set scan mode.
91      *
92      * @param scanMode Scan mode.
93      * @since 6
94      */
95     void SetScanMode(int scanMode);
96 
97     /**
98      * @brief Get scan mode.
99      *
100      * @return Scan mode.
101      * @since 6
102      */
103     int GetScanMode() const;
104 
105     /**
106      * @brief Set legacy flag.
107      *
108      * @param legacy Legacy flag.
109      * @since 6
110      */
111     void SetLegacy(bool legacy);
112 
113     /**
114      * @brief Get legacy flag.
115      *
116      * @return Legacy flag.
117      * @since 6
118      */
119     bool GetLegacy() const;
120 
121     /**
122      * @brief Set phy value.
123      *
124      * @param phy Phy value.
125      * @since 6
126      */
127     void SetPhy(int phy);
128 
129     /**
130      * @brief Get phy value.
131      *
132      * @return Phy value.
133      * @since 6
134      */
135     int GetPhy() const;
136 
137     bool operator == (const BleScanSettingsImpl &rhs) const
138     {
139         return (legacy_ == rhs.GetLegacy()) &&
140                (phy_ == rhs.GetPhy()) &&
141                (reportDelayMillis_ == rhs.GetReportDelayMillisValue()) &&
142                (scanMode_ == rhs.GetScanMode());
143     }
144 
145 private:
146     /// delay millistime
147     long reportDelayMillis_ = 0;
148     int scanMode_ = SCAN_MODE_LOW_POWER;
149     bool legacy_ = true;
150     int phy_ = PHY_LE_1M;
151 };
152 
153 /**
154  * @brief Represents advertise settings.
155  *
156  * @since 6
157  */
158 class BleAdvertiserSettingsImpl {
159 public:
160     /**
161      * @brief A constructor used to create a <b>BleAdvertiseSettingsInternal</b> instance.
162      *
163      * @since 6
164      */
BleAdvertiserSettingsImpl()165     BleAdvertiserSettingsImpl(){};
166 
167     /**
168      * @brief A destructor used to delete the <b>BleAdvertiseSettingsInternal</b> instance.
169      *
170      * @since 6
171      */
~BleAdvertiserSettingsImpl()172     ~BleAdvertiserSettingsImpl(){};
173 
174     /**
175      * @brief Check if device service is connectable.
176      *
177      * @return Returns <b>true</b> if device service is connectable;
178      *         returns <b>false</b> if device service is not connectable.
179      * @since 6
180      */
181     bool IsConnectable() const;
182 
183     /**
184      * @brief Set connectable.
185      *
186      * @param connectable Whether it is connectable.
187      * @since 6
188      */
189     void SetConnectable(bool connectable);
190     /**
191      * @brief Check if advertiser is legacy mode.
192      *
193      * @return Returns <b>true</b> if advertiser is legacy mode;
194      *         returns <b>false</b> if advertiser is not legacy mode.
195      * @since 6
196      */
197     bool IsLegacyMode() const;
198 
199     /**
200      * @brief Set legacyMode.
201      *
202      * @param connectable Whether it is legacyMode.
203      * @since 6
204      */
205     void SetLegacyMode(bool legacyMode);
206 
207     /**
208      * @brief Get advertise interval.
209      *
210      * @return Returns advertise interval.
211      * @since 6
212      */
213     int GetInterval() const;
214 
215     /**
216      * @brief Set advertise interval.
217      *
218      * @param interval Advertise interval.
219      * @since 6
220      */
221     void SetInterval(int interval = BLE_ADV_DEFAULT_INTERVAL);
222 
223     /**
224      * @brief Get advertiser Tx power.
225      *
226      * @return Returns advertiser Tx power.
227      * @since 6
228      */
229     int8_t GetTxPower() const;
230 
231     /**
232      * @brief Set advertiser Tx power.
233      *
234      * @param txPower Advertiser Tx power.
235      * @since 6
236      */
237     void SetTxPower(int8_t txPower);
238 
239     /**
240      * @brief Get primary phy.
241      *
242      * @return Returns primary phy.
243      * @since 6
244      */
245     int GetPrimaryPhy() const;
246 
247     /**
248      * @brief Set primary phy.
249      *
250      * @param primaryPhy Primary phy.
251      * @since 6
252      */
253     void SetPrimaryPhy(int primaryPhy);
254 
255     /**
256      * @brief Get second phy.
257      *
258      * @return Returns primary phy.
259      * @since 6
260      */
261     int GetSecondaryPhy() const;
262 
263     /**
264      * @brief Set second phy.
265      *
266      * @param secondaryPhy Second phy.
267      * @since 6
268      */
269     void SetSecondaryPhy(int secondaryPhy);
270 
271     /**
272      * @brief Get own address.
273      *
274      * @return Returns own address.
275      * @since 6
276      */
277     std::array<uint8_t, RawAddress::BT_ADDRESS_BYTE_LEN> GetOwnAddr() const;
278 
279     /**
280      * @brief Set own address.
281      *
282      * @param addr Own address.
283      * @since 6
284      */
285     void SetOwnAddr(const std::array<uint8_t, RawAddress::BT_ADDRESS_BYTE_LEN>& addr);
286 
287     /**
288      * @brief Get own address type.
289      *
290      * @return Returns own address type.
291      * @since 6
292      */
293     int8_t GetOwnAddrType() const;
294 
295     /**
296      * @brief Set own address type.
297      *
298      * @param addrType Own address type.
299      * @since 6
300      */
301     void SetOwnAddrType(int8_t addrType);
302 
303 private:
304     /// Advertising interval.
305     int interval_ = BLE_ADV_DEFAULT_INTERVAL;
306     /// Advertising connectable.
307     bool connectable_ = true;
308     /// Advertising txPower.
309     int8_t txPower_ = BLE_ADV_TX_POWER_MEDIUM_VALUE;
310     /// Advertising legacyMode.
311     bool legacyMode_ = true;
312     /// Advertising primaryPhy.
313     int primaryPhy_ = BLE_ADVERTISEMENT_PHY_1M;
314     /// Advertising secondaryPhy.
315     int secondaryPhy_ = BLE_ADVERTISEMENT_PHY_1M;
316     /// Own address.
317     std::array<uint8_t, RawAddress::BT_ADDRESS_BYTE_LEN> ownAddr_ = {};
318     /// Own address type.
319     int8_t ownAddrType_ = -1;
320 };
321 
322 /**
323  * @brief Represents scan filter.
324  *
325  */
326 class BleScanFilterImpl {
327 public:
BleScanFilterImpl()328     BleScanFilterImpl() {}
~BleScanFilterImpl()329     ~BleScanFilterImpl() {}
330 
331     /**
332      * @brief Set device id.
333      *
334      * @param deviceId filter device id.
335      */
336     void SetDeviceId(const std::string &deviceId);
337 
338     /**
339      * @brief Get filter device id.
340      *
341      * @return Returns filter device id.
342      */
343     std::string GetDeviceId() const;
344 
345     void SetName(const std::string &name);
346 
347     std::string GetName() const;
348 
349     void SetServiceUuid(const Uuid &serviceUuid);
350 
351     bool HasServiceUuid() const;
352 
353     Uuid GetServiceUuid() const;
354 
355     void SetServiceUuidMask(const Uuid &serviceUuidMask);
356 
357     bool HasServiceUuidMask() const;
358 
359     Uuid GetServiceUuidMask() const;
360 
361     void SetServiceSolicitationUuid(const Uuid &serviceSolicitationUuid);
362 
363     bool HasSolicitationUuid() const;
364 
365     Uuid GetServiceSolicitationUuid() const;
366 
367     void SetServiceSolicitationUuidMask(const Uuid &serviceSolicitationUuidMask);
368 
369     bool HasSolicitationUuidMask() const;
370 
371     Uuid GetServiceSolicitationUuidMask() const;
372 
373     void SetServiceData(const std::vector<uint8_t> &serviceData);
374 
375     std::vector<uint8_t> GetServiceData() const;
376 
377     void SetServiceDataMask(const std::vector<uint8_t> &serviceDataMask);
378 
379     std::vector<uint8_t> GetServiceDataMask() const;
380 
381     void SetManufacturerId(uint16_t manufacturerId);
382 
383     uint16_t GetManufacturerId() const;
384 
385     void SetManufactureData(const std::vector<uint8_t> &manufactureData);
386 
387     std::vector<uint8_t> GetManufactureData() const;
388 
389     void SetManufactureDataMask(const std::vector<uint8_t> &manufactureDataMask);
390 
391     std::vector<uint8_t> GetManufactureDataMask() const;
392 
393     void SetClientId(int clientId);
394 
395     int GetClientId() const;
396 
397     void SetFiltIndex(uint8_t filtIndex);
398 
399     uint8_t GetFiltIndex() const;
400 
401     void SetFilterAction(uint8_t action);
402 
403     uint8_t GetFilterAction() const;
404 
405 private:
406     std::string deviceId_;
407     std::string name_;
408 
409     Uuid serviceUuid_;
410     Uuid serviceUuidMask_;
411     Uuid serviceSolicitationUuid_;
412     Uuid serviceSolicitationUuidMask_;
413     bool hasServiceUuid_ = false;
414     bool hasServiceUuidMask_ = false;
415     bool hasSolicitationUuid_ = false;
416     bool hasSolicitationUuidMask_ = false;
417 
418     std::vector<uint8_t> serviceData_;
419     std::vector<uint8_t> serviceDataMask_;
420 
421     uint16_t manufacturerId_ = 0;
422     std::vector<uint8_t> manufactureData_;
423     std::vector<uint8_t> manufactureDataMask_;
424 
425     int clientId_ = 0;
426     uint8_t filtIndex_ = 0;
427     uint8_t action_ = -1;
428 };
429 
430 /**
431  * @brief Represents advertise data.
432  *
433  * @since 6
434  */
435 class BleAdvertiserDataImpl {
436 public:
437     /**
438      * @brief A constructor used to create a <b>BleAdvertiseDataInternal</b> instance.
439      *
440      * @since 6
441      */
442     BleAdvertiserDataImpl();
443 
444     /**
445      * @brief A destructor used to delete the <b>BleAdvertiseDataInternal</b> instance.
446      *
447      * @since 6
448      */
~BleAdvertiserDataImpl()449     ~BleAdvertiserDataImpl()
450     {}
451 
452     /**
453      * @brief Add manufacture data.
454      *
455      * @param manufacturerId Manufacture Id which addad data.
456      * @param data Manufacture data
457      * @since 6
458      */
459     int AddManufacturerData(uint16_t manufacturerId, const std::string &data);
460 
461     /**
462      * @brief Add service data.
463      *
464      * @param uuid Uuid of service data.
465      * @param data Service data.
466      * @since 6
467      */
468     void AddServiceData(const Uuid &uuid, const std::string &data);
469 
470     /**
471      * @brief Add characteristic value.
472      *
473      * @param adtype Type of the field.
474      * @param data Field data.
475      * @since 6
476      */
477     void AddCharacteristicValue(uint8_t adtype, const std::string &data);
478 
479     /**
480      * @brief Add service uuid.
481      *
482      * @param uuid Service uuid.
483      * @since 6
484      */
485     void AddServiceUuid(const Uuid &uuid);
486 
487     /**
488      * @brief Set device appearance.
489      *
490      * @param appearance Device appearance.
491      * @since 6
492      */
493     void SetAppearance(uint16_t appearance);
494 
495     /**
496      * @brief Set complete services.
497      *
498      * @param uuid Service uuid.
499      * @since 6
500      */
501     void SetCompleteServices(const Uuid &uuid);
502 
503     /**
504      * @brief Set advertiser flag.
505      *
506      * @param flag Advertiser flag.
507      * @since 6
508      */
509     void SetFlags(uint8_t flag);
510 
511     /**
512      * @brief Get advertiser flag.
513      *
514      * @return flag Advertiser flag.
515      * @since 6
516      */
517     uint8_t GetFlags() const;
518 
519     /**
520      * @brief Set manufacture data.
521      *
522      * @param data Manufacture data.
523      * @since 6
524      */
525     void SetManufacturerData(const std::string &data);
526 
527     /**
528      * @brief Set device name.
529      *
530      * @param name Device name.
531      * @since 6
532      */
533     void SetDeviceName(const std::string &name);
534 
535     /**
536      * @brief Set Tx power level.
537      *
538      * @param txPowerLevel Tx power level.
539      * @since 6
540      */
541     void SetTxPowerLevel(uint8_t txPowerLevel);
542 
543     /**
544      * @brief Add service data.
545      *
546      * @param data Service data.
547      * @since 6
548      */
549     void AddData(std::string data);
550 
551     /**
552      * @brief Set advertiser data packet.
553      *
554      * @return Returns advertiser data packet.
555      * @since 1.0
556      * @version 1.0
557      */
558     void SetPayload(const std::string &payload);
559     /**
560      * @brief Get advertiser data packet.
561      *
562      * @return Returns advertiser data packet.
563      * @since 6
564      */
565     std::string GetPayload() const;
566 
567 private:
568     /// Advertiser data packet
569     std::string payload_ {};
570     uint8_t advFlag_ {};
571 
572     /**
573      * @brief Set advertiser data long name.
574      *
575      * @param name Bluetooth device name.
576      * @since 6
577      */
578     void SetLongName(const std::string &name);
579 
580     /**
581      * @brief Set advertiser data short name
582      *
583      * @param name Bluetooth device name.
584      * @since 6
585      */
586     void SetShortName(const std::string &name);
587 };
588 
589 /**
590  * @brief Parse advertisement parameter .
591  *
592  * @since 6
593  */
594 struct BlePeripheralDeviceParseAdvData {
595     uint8_t *payload = nullptr;
596     size_t length = 0;
597 };
598 /**
599  * @brief Represents peripheral device.
600  *
601  * @since 6
602  */
603 class BlePeripheralDevice {
604 public:
605     /**
606      * @brief A constructor used to create a <b>BlePeripheralDevice</b> instance.
607      *
608      * @since 6
609      */
610     BlePeripheralDevice();
611 
612     /**
613      * @brief A destructor used to delete the <b>BlePeripheralDevice</b> instance.
614      *
615      * @since 6
616      */
617     ~BlePeripheralDevice();
618 
619     /**
620      * @brief Get device address.
621      *
622      * @return Returns device address.
623      * @since 6
624      */
625     RawAddress GetRawAddress() const;
626 
627     /**
628      * @brief Get device Appearance.
629      *
630      * @return Returns device Appearance.
631      * @since 6
632      */
633     uint16_t GetAppearance() const;
634 
635     /**
636      * @brief Get Manufacturer Data.
637      *
638      * @return Returns Manufacturer Data.
639      * @since 6
640      */
641     std::map<uint16_t, std::string> GetManufacturerData() const;
642 
643     /**
644      * @brief Get device Name.
645      *
646      * @return Returns device Name.
647      * @since 6
648      */
649     std::string GetName() const;
650 
651     /**
652      * @brief Get device RSSI.
653      *
654      * @return Returns device RSSI.
655      * @since 6
656      */
657     int8_t GetRSSI() const;
658 
659     /**
660      * @brief Get service Data.
661      *
662      * @return Returns service data.
663      * @since 6
664      */
665     std::vector<std::string> GetServiceData() const;
666 
667     /**
668      * @brief Get Service Data.
669      *
670      * @param index Service data index.
671      * @return Returns service data.
672      * @since 6
673      */
674     std::string GetServiceData(int index) const;
675 
676     /**
677      * @brief Get service data UUID.
678      *
679      * @return Returns service data UUID.
680      * @since 6
681      */
682     std::vector<Uuid> GetServiceDataUUID() const;
683 
684     /**
685      * @brief Get service data UUID.
686      *
687      * @param index Service data index.
688      * @return Returns service data UUID.
689      * @since 6
690      */
691     Uuid GetServiceDataUUID(int index) const;
692 
693     /**
694      * @brief Get serviceU UUID.
695      *
696      * @return Returns service UUID.
697      * @since 6
698      */
699     std::vector<Uuid> GetServiceUUID() const;
700 
701     /**
702      * @brief Get service UUID.
703      *
704      * @param index Service UUID index.
705      * @return Return service UUID.
706      * @since 6
707      */
708     Uuid GetServiceUUID(int index) const;
709 
710     /**
711      * @brief Get advertiser data packet.
712      *
713      * @return Returns advertiser data packet.
714      * @since 6
715      */
716     uint8_t *GetPayload() const;
717 
718     /**
719      * @brief Get advertising packet length.
720      *
721      * @return Returns advertising packet length.
722      * @since 6
723      */
724     size_t GetPayloadLen() const;
725 
726     /**
727      * @brief Get address type.
728      *
729      * @return Returns address type.
730      * @since 6
731      */
732     int GetAddressType() const;
733 
734     /**
735      * @brief Set address type.
736      *
737      * @param type Address type.
738      * @since 6
739      */
740     void SetAddressType(int type);
741     /**
742      * @brief Check if include manufacture data.
743      *
744      * @return Returns <b>true</b> if include manufacture data;
745      *         returns <b>false</b> if do not include manufacture data.
746      * @since 6
747      */
748     bool IsManufacturerData() const;
749 
750     /**
751      * @brief Check if include device rssi.
752      *
753      * @return Returns <b>true</b> if include device rssi;
754      *         returns <b>false</b> if do not include device rssi.
755      * @since 6
756      */
757     bool IsRSSI() const;
758 
759     /**
760      * @brief Check if include service data.
761      *
762      * @return Returns <b>true</b> if include service data;
763      *         returns <b>false</b> if do not include service data.
764      * @since 6
765      */
766     bool IsServiceData() const;
767 
768     /**
769      * @brief Check if include service UUID.
770      *
771      * @return Returns <b>true</b> if include service UUID;
772      *         returns <b>false</b> if do not include service UUID.
773      * @since 6
774      */
775     bool IsServiceUUID() const;
776 
777     bool IsName(void) const;
778 
779     /**
780      * @brief set device address.
781      *
782      * @param address device address.
783      * @since 6
784      */
785     void SetAddress(const RawAddress &address);
786 
787     /**
788      * @brief set rssi value.
789      *
790      * @param rssi rssi value.
791      * @since 6
792      */
793     void SetRSSI(int8_t rssi);
794 
795     /**
796      * @brief set rssi value.
797      *
798      * @param [in] rssi value.
799      */
800     bool IsConnectable() const;
801 
802     /**
803      * @brief set rssi value.
804      *
805      * @param [in] rssi value.
806      */
807     void SetConnectable(bool connectable);
808 
809     /**
810      * @brief Parse advertisement data.
811      *
812      * @param payload Advertisement packet.
813      * @param totalLen Advertisement packet total len.
814      * @since 6
815      */
816     void ParseAdvertiserment(BlePeripheralDeviceParseAdvData &parseAdvData);
817 
818     /**
819      * @brief Build advertisement data.
820      *
821      * @param advType Advertisement packet type.
822      * @param payload Advertisement packet.
823      * @param length Advertisement packet len.
824      *
825      * @since 6
826      */
827     void BuildAdvertiserData(uint8_t advType, BlePeripheralDeviceParseAdvData &parseAdvData);
828 
829     /**
830      * @brief Set service uuid 16 bit data.
831      *
832      * @param payload Advertisement packet.
833      * @param total_len Advertisement packet len.
834      * @since 6
835      */
836     void SetServiceUUID16Bits(BlePeripheralDeviceParseAdvData &parseAdvData);
837 
838     /**
839      * @brief Set service uuid 32 bit data.
840      *
841      * @param payload Advertisement packet.
842      * @param total_len Advertisement packet len.
843      * @since 6
844      */
845     void SetServiceUUID32Bits(BlePeripheralDeviceParseAdvData &parseAdvData);
846 
847     /**
848      * @brief Set service uuid 128 bit data.
849      *
850      * @param payload Advertisement packet.
851      * @param total_len Advertisement packet len.
852      * @since 6
853      */
854     void SetServiceUUID128Bits(const BlePeripheralDeviceParseAdvData &parseAdvData);
855 
856     /**
857      * @brief Set service data uuid 16 bit data.
858      *
859      * @param payload Advertisement packet.
860      * @param total_len Advertisement packet len.
861      * @since 6
862      */
863     void SetServiceDataUUID16Bits(BlePeripheralDeviceParseAdvData &parseAdvData);
864 
865     /**
866      * @brief Set service data uuid 32 bit data.
867      *
868      * @param payload Advertisement packet.
869      * @param total_len Advertisement packet len.
870      * @since 6
871      */
872     void SetServiceDataUUID32Bits(BlePeripheralDeviceParseAdvData &parseAdvData);
873 
874     /**
875      * @brief Set service data uuid 128 bit data.
876      *
877      * @param payload Advertisement packet.
878      * @param total_len Advertisement packet len.
879      * @since 6
880      */
881     void SetServiceDataUUID128Bits(BlePeripheralDeviceParseAdvData &parseAdvData);
882 
883     /**
884      * @brief Set device name.
885      *
886      * @param name Device name.
887      * @since 6
888      */
889     void SetName(const std::string &name);
890 
891     /**
892      * @brief Set device roles.
893      *
894      * @param roles Device roles.
895      * @since 6
896      */
897     void SetRoles(uint8_t roles);
898 
899     /**
900      * @brief Set bonded from local.
901      *
902      * @param flag Advertiser flag.
903      * @since 6
904      */
905     void SetBondedFromLocal(bool flag);
906 
907     /**
908      * @brief Set acl connect state.
909      *
910      * @param connectState Acl connect state.
911      * @since 6
912      */
913     void SetAclConnectState(int connectState);
914 
915     /**
916      * @brief Set acl connection handle.
917      *
918      * @param handle Acl connection handle.
919      * @since 6
920      */
921     void SetConnectionHandle(int handle);
922 
923     /**
924      * @brief Check if device acl connected.
925      *
926      * @return Returns <b>true</b> if device acl connected;
927      *         returns <b>false</b> if device does not acl connect.
928      * @since 6
929      */
930     bool IsAclConnected() const;
931 
932     /**
933      * @brief Check if device acl Encrypted.
934      *
935      * @return Returns <b>true</b> if device acl Encrypted;
936      *         returns <b>false</b> if device does not acl Encrypt.
937      * @since 6
938      */
939     bool IsAclEncrypted() const;
940 
941     /**
942      * @brief Check if device was bonded from local.
943      *
944      * @return Returns <b>true</b> if device was bonded from local;
945      *         returns <b>false</b> if device was not bonded from local.
946      * @since 6
947      */
948     bool IsBondedFromLocal() const;
949 
950     /**
951      * @brief Get acl connection handle.
952      *
953      * @return Returns acl connection handle;
954      * @since 6
955      */
956     int GetConnectionHandle() const;
957 
958     /**
959      * @brief Get device type.
960      *
961      * @return Returns device type.
962      * @since 6
963      */
964     uint8_t GetDeviceType() const;
965 
966     /**
967      * @brief Get advertising flag.
968      *
969      * @return Returns advertising flag.
970      * @since 6
971      */
972     uint8_t GetAdFlag() const;
973 
974     /**
975      * @brief Get paired status.
976      *
977      * @return Returns paired status.
978      * @since 6
979      */
980     uint8_t GetPairedStatus() const;
981 
982     /**
983      * @brief Set paired status.
984      *
985      * @param status Paired status.
986      * @return Returns <b>true</b> if the operation is successful;
987      *         returns <b>false</b> if the operation fails.
988      * @since 6
989      */
990     bool SetPairedStatus(uint8_t status);
991 
992     /**
993      * @brief Set alias name.
994      *
995      * @param name Device alias name.
996      * @since 6
997      */
998     void SetAliasName(const std::string &name);
999 
1000     /**
1001      * @brief Get alias name.
1002      *
1003      * @return Returns alias name.
1004      * @since 6
1005      */
1006     std::string GetAliasName() const;
1007 
1008     /**
1009      * @brief Set IO capability.
1010      *
1011      * @param io IO capability
1012      * @since 6
1013      */
1014     void SetIoCapability(uint8_t io);
1015 
1016     /**
1017      * @brief Get IO capability.
1018      *
1019      * @return Returns IO capability.
1020      * @since 6
1021      */
1022     uint8_t GetIoCapability() const;
1023 
1024     /**
1025      * @brief Set device type.
1026      *
1027      * @param type Device type.
1028      * @since 6
1029      */
1030     void SetDeviceType(uint8_t type);
1031 
1032     /**
1033      * @brief Set manufacturer data.
1034      *
1035      * @param manufacturerData Manufacturer data.
1036      * @since 6
1037      */
1038     void SetManufacturerData(std::string manufacturerData);
1039 
1040 private:
1041     /**
1042      * @brief Set advertising flag.
1043      *
1044      * @param adFlag Advertising flag.
1045      * @since 6
1046      */
1047     void SetAdFlag(uint8_t adFlag);
1048 
1049     /**
1050      * @brief Set appearance.
1051      *
1052      * @param appearance Appearance.
1053      * @since 6
1054      */
1055     void SetAppearance(uint16_t appearance);
1056 
1057     /**
1058      * @brief Set service data UUID.
1059      *
1060      * @param uuid Service data UUID.
1061      * @since 6
1062      */
1063     void SetServiceDataUUID(Uuid uuid, std::string data);
1064 
1065     /**
1066      * @brief Set service  UUID.
1067      *
1068      * @param serviceUUID Service  UUID.
1069      * @since 6
1070      */
1071     void SetServiceUUID(Uuid serviceUUID);
1072     /**
1073      * @brief Set TX power.
1074      *
1075      * @param txPower TX power.
1076      * @since 6
1077      */
1078     void SetTXPower(int8_t txPower);
1079 
1080     /// include appearance?
1081     bool isAppearance_ = false;
1082     /// include Manufacturer Data?
1083     bool isManufacturerData_ = false;
1084     /// include device name?
1085     bool isName_ = false;
1086     /// include rssi value?
1087     bool isRSSI_ = false;
1088     /// include service data?
1089     bool isServiceData_ = false;
1090     /// include service uuid?
1091     bool isServiceUUID_ = false;
1092     /// include tx power?
1093     bool isTXPower_ = false;
1094     /// peer roles
1095     uint8_t roles_ = 0;
1096     /// device address
1097     RawAddress address_ = RawAddress("00:00:00:00:00:00");
1098     /// device address
1099     RawAddress currentAddr_ = RawAddress("00:00:00:00:00:00");
1100     /// advertising flag
1101     uint8_t adFlag_ = 0;
1102     /// appearance
1103     uint16_t appearance_ = 0;
1104     /// manufacturer Data
1105     std::map<uint16_t, std::string> manufacturerData_ {};
1106     /// device name
1107     std::string name_ {};
1108     /// rssi value
1109     int8_t rssi_ = 0;
1110     /// service uuid
1111     std::vector<Uuid> serviceUUIDs_ {};
1112     /// tx power
1113     int8_t txPower_ {};
1114     /// service data
1115     std::vector<std::string> serviceData_ {};
1116     /// service data uuid
1117     std::vector<Uuid> serviceDataUUIDs_ {};
1118     /// address type
1119     uint8_t addressType_ = BLE_ADDR_TYPE_RANDOM;
1120     int aclConnected_ = 0;
1121     int connectionHandle_ = 0;
1122     bool bondFlag_ = false;
1123     uint8_t pairState_ {};
1124     uint8_t ioCapability_ {};
1125     std::string aliasName_ {};
1126     bool connectable_ = true;
1127     uint8_t* payload_ {};
1128     size_t payloadLen_ = 0;
1129 };
1130 
1131 /**
1132  * @brief Represents scan result.
1133  *
1134  * @since 6
1135  */
1136 class BleScanResultImpl {
1137 public:
1138     /**
1139      * @brief A constructor used to create a <b>BleScanResultInternal</b> instance.
1140      *
1141      * @since 6
1142      */
BleScanResultImpl()1143     BleScanResultImpl() : peripheralDevice_()
1144     {}
1145 
1146     /**
1147      * @brief A destructor used to delete the <b>BleScanResultInternal</b> instance.
1148      *
1149      * @since 6
1150      */
~BleScanResultImpl()1151     ~BleScanResultImpl()
1152     {}
1153 
1154     /**
1155      * @brief Get peripheral device.
1156      *
1157      * @return Returns peripheral device pointer.
1158      * @since 6
1159      */
1160     BlePeripheralDevice GetPeripheralDevice() const;
1161 
1162     /**
1163      * @brief Set peripheral device.
1164      *
1165      * @param dev Peripheral device.
1166      * @since 6
1167      */
1168     void SetPeripheralDevice(const BlePeripheralDevice &dev);
1169 
1170     /**
1171      * @brief Get service uuids.
1172      *
1173      * @return Returns service uuids.
1174      * @since 6
1175      */
GetServiceUuids()1176     std::vector<Uuid> GetServiceUuids() const
1177     {
1178         return serviceUuids_;
1179     }
1180 
1181     /**
1182      * @brief Get manufacture data.
1183      *
1184      * @return Returns manufacture data.
1185      * @since 6
1186      */
GetManufacturerData()1187     std::map<uint16_t, std::string> GetManufacturerData() const
1188     {
1189         return manufacturerSpecificData_;
1190     }
1191 
1192     /**
1193      * @brief Get service data.
1194      *
1195      * @return Returns service data.
1196      * @since 6
1197      */
GetServiceData()1198     std::map<Uuid, std::string> GetServiceData() const
1199     {
1200         return serviceData_;
1201     }
1202 
1203     /**
1204      * @brief Get peer device rssi.
1205      *
1206      * @return Returns peer device rssi.
1207      * @since 6
1208      */
GetRssi()1209     int8_t GetRssi() const
1210     {
1211         return rssi_;
1212     }
1213 
1214     /**
1215      * @brief Check if device is connectable.
1216      *
1217      * @return Returns <b>true</b> if device is connectable;
1218      *         returns <b>false</b> if device is not connectable.
1219      * @since 6
1220      */
IsConnectable()1221     bool IsConnectable() const
1222     {
1223         return connectable_;
1224     }
1225 
1226     /**
1227      * @brief Get advertiser flag.
1228      *
1229      * @return Returns advertiser flag.
1230      * @since 6
1231      */
GetAdvertiseFlag()1232     uint8_t GetAdvertiseFlag() const
1233     {
1234         return advertiseFlag_;
1235     }
1236 
1237     /**
1238      * @brief Add manufacture data.
1239      *
1240      * @param manufacturerId Manufacture Id which addad data.
1241      * @since 6
1242      */
AddManufacturerData(uint16_t manufacturerId,std::string data)1243     void AddManufacturerData(uint16_t manufacturerId, std::string data)
1244     {
1245         manufacturerSpecificData_.insert(std::make_pair(manufacturerId, data));
1246     }
1247 
1248     /**
1249      * @brief Add service data.
1250      *
1251      * @param uuid Uuid of service data.
1252      * @param serviceData Service data.
1253      * @since 6
1254      */
AddServiceData(Uuid uuid,std::string serviceData)1255     void AddServiceData(Uuid uuid, std::string serviceData)
1256     {
1257         serviceData_.insert(std::make_pair(uuid, serviceData));
1258     }
1259 
1260     /**
1261      * @brief Add service uuid.
1262      *
1263      * @param serviceUuid Service uuid.
1264      * @since 6
1265      */
AddServiceUuid(const Uuid & serviceUuid)1266     void AddServiceUuid(const Uuid &serviceUuid)
1267     {
1268         serviceUuids_.push_back(serviceUuid);
1269     }
1270 
1271     /**
1272      * @brief Set peripheral device.
1273      *
1274      * @param device Remote device.
1275      * @since 6
1276      */
SetPeripheralDevice(const RawAddress & device)1277     void SetPeripheralDevice(const RawAddress &device)
1278     {
1279         addr_ = device;
1280     }
1281 
1282     /**
1283      * @brief Set peer device rssi.
1284      *
1285      * @param rssi Peer device rssi.
1286      * @since 6
1287      */
SetRssi(int8_t rssi)1288     void SetRssi(int8_t rssi)
1289     {
1290         rssi_ = rssi;
1291     }
1292 
1293     /**
1294      * @brief Set connectable.
1295      *
1296      * @param connectable Whether it is connectable.
1297      * @since 6
1298      */
SetConnectable(bool connectable)1299     void SetConnectable(bool connectable)
1300     {
1301         connectable_ = connectable;
1302     }
1303 
1304     /**
1305      * @brief Set advertiser flag.
1306      *
1307      * @param flag Advertiser flag.
1308      * @since 6
1309      */
SetAdvertiseFlag(uint8_t flag)1310     void SetAdvertiseFlag(uint8_t flag)
1311     {
1312         advertiseFlag_ = flag;
1313     }
1314 
1315 private:
1316     /// scan device results
1317     BlePeripheralDevice peripheralDevice_;
1318     std::vector<Uuid> serviceUuids_ {};
1319     std::map<uint16_t, std::string> manufacturerSpecificData_ {};
1320     std::map<Uuid, std::string> serviceData_ {};
1321     RawAddress addr_ {};
1322     int8_t rssi_ {};
1323     bool connectable_ {};
1324     uint8_t advertiseFlag_ {};
1325 };
1326 
1327 struct BleActiveDeviceInfoImpl {
1328     std::vector<int8_t> deviceId;
1329     int32_t status;
1330     int32_t timeOut;
1331 };
1332 
1333 struct BleLpDeviceParamSetImpl {
1334     BleScanSettingsImpl scanSettingImpl;
1335     std::vector<BleScanFilterImpl> scanFliterImpls;
1336     BleAdvertiserSettingsImpl advSettingsImpl;
1337     BleAdvertiserDataImpl advDataImpl;
1338     BleAdvertiserDataImpl respDataImpl;
1339     std::vector<BleActiveDeviceInfoImpl> activeDeviceInfoImpls;
1340     int32_t advHandle;
1341     int32_t duration;
1342     int32_t deliveryMode;
1343     uint32_t fieldValidFlagBit;
1344 };
1345 
1346 struct FilterIdxInfo {
1347     FilterIdxInfo() = default;
FilterIdxInfoFilterIdxInfo1348     FilterIdxInfo(int pid, int uid, const Uuid &uuid) : pid(pid), uid(uid), uuid(uuid) {}
1349     bool operator == (const FilterIdxInfo &info) const
1350     {
1351         if (pid == info.pid && uid == info.uid && uuid == info.uuid) {
1352             return true;
1353         }
1354         return false;
1355     }
1356 
1357     int32_t pid = 0;
1358     int32_t uid = 0;
1359     Uuid uuid;
1360 };
1361 
1362 }  // namespace bluetooth
1363 }  // namespace OHOS
1364 #endif  /// BLE_SERVICE_DATA_H
1365