• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef NDEF_BT_DATA_PARSER_H
16 #define NDEF_BT_DATA_PARSER_H
17 
18 #include <string>
19 #include "bluetooth_def.h"
20 #include "bluetooth_device_class.h"
21 #include "uuid.h"
22 
23 namespace OHOS {
24 namespace NFC {
25 namespace TAG {
26 class BtData {
27 public:
28     bool isValid_ = false;
29     std::string name_ = "";
30     std::string oobData_ = "";
31     bool carrierActivating_ = false;
32     uint8_t transport_ = Bluetooth::GATT_TRANSPORT_TYPE_AUTO;
33     std::vector<Bluetooth::UUID> uuids_ {};
34     Bluetooth::BluetoothDeviceClass btClass_ {};
35 
36     std::string macAddress_ = "";
37     std::string macAddrOrg_ = "";
38     std::string vendorSerialNum_ = "";
39     std::string vendorPayload_ = "";
40 };
41 
42 class NdefBtDataParser {
43 public:
44     NdefBtDataParser();
~NdefBtDataParser()45     ~NdefBtDataParser() {}
46     static std::shared_ptr<BtData> CheckBtRecord(const std::string& msg);
47 
48 private:
49     static std::shared_ptr<BtData> ParseBtRecord(const std::string& payload);
50     static std::shared_ptr<BtData> ParseBleRecord(const std::string& payload);
51     static std::vector<Bluetooth::UUID> GetUuidFromPayload(const std::string& payload, uint32_t& offset,
52                                                            uint32_t type, uint32_t len);
53     static std::string GetDataFromPayload(const std::string& payload, uint32_t& offset, uint32_t datalen);
54     static std::string FormatBtMacAddr(const std::string& orgBtMac);
55     static std::string GetOrgBtMacFromPayload(const std::string& payload, uint32_t& offset);
56     static bool GetBtDevClass(const std::string& payload, uint32_t& offset,
57                               Bluetooth::BluetoothDeviceClass& btClass);
58     static std::string RevertUuidStr(const std::string& uuid);
59     static Bluetooth::UUID FormatUuidTo128Bit(const std::string& uuid);
60 };
61 } // namespace TAG
62 } // namespace NFC
63 } // namespace OHOS
64 #endif // NDEF_BT_DATA_PARSER_H