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 #include "ndef_message.h" 23 24 namespace OHOS { 25 namespace NFC { 26 namespace TAG { 27 class BtData { 28 public: 29 bool isValid_ = false; 30 std::string name_ = ""; 31 std::string oobData_ = ""; 32 bool carrierActivating_ = false; 33 uint8_t transport_ = Bluetooth::GATT_TRANSPORT_TYPE_AUTO; 34 std::vector<Bluetooth::UUID> uuids_ {}; 35 Bluetooth::BluetoothDeviceClass btClass_ {}; 36 37 std::string macAddress_ = ""; 38 std::string macAddrOrg_ = ""; 39 std::string vendorSerialNum_ = ""; 40 std::string vendorPayload_ = ""; 41 }; 42 43 class NdefBtDataParser { 44 public: 45 NdefBtDataParser(); ~NdefBtDataParser()46 ~NdefBtDataParser() {} 47 static std::shared_ptr<BtData> CheckBtRecord(const std::string& msg); 48 static bool IsVendorPayloadValid(const std::string& payload); 49 50 private: 51 static std::shared_ptr<BtData> ParseBtRecord(const std::string& payload); 52 static std::shared_ptr<BtData> ParseBleRecord(const std::string& payload); 53 static std::vector<Bluetooth::UUID> GetUuidFromPayload(const std::string& payload, uint32_t& offset, 54 uint32_t type, uint32_t len); 55 static std::string GetDataFromPayload(const std::string& payload, uint32_t& offset, uint32_t datalen); 56 static std::string FormatBtMacAddr(const std::string& orgBtMac); 57 static std::string GetOrgBtMacFromPayload(const std::string& payload, uint32_t& offset); 58 static bool GetBtDevClass(const std::string& payload, uint32_t& offset, 59 Bluetooth::BluetoothDeviceClass& btClass); 60 static std::string RevertUuidStr(const std::string& uuid); 61 static Bluetooth::UUID FormatUuidTo128Bit(const std::string& uuid); 62 static std::shared_ptr<BtData> ParseBtHandoverSelect(std::shared_ptr<KITS::NdefMessage> &ndef); 63 64 const static int VENDOR_PAYLOAD_MAX_LEN = 0xFF; // vendor payload length is 1 byte 65 }; 66 } // namespace TAG 67 } // namespace NFC 68 } // namespace OHOS 69 #endif // NDEF_BT_DATA_PARSER_H