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