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 #ifndef BLE_UTILS_H 17 #define BLE_UTILS_H 18 19 #include <cstring> 20 #include <vector> 21 22 #include "ble_defs.h" 23 24 /* 25 * @brief The bluetooth system. 26 */ 27 namespace OHOS { 28 namespace bluetooth { 29 /** 30 * @brief BLE Utils. 31 */ 32 class BleUtils { 33 public: 34 /** 35 * @brief Convert int to hex string 36 * 37 * @param [in] int vector value 38 * @return hex string. 39 */ 40 static std::string ConvertIntToHexString(const std::vector<uint8_t> &key); 41 42 /** 43 * @brief Convert int to hex string 44 * 45 * @param [in] int value 46 * @return hex string. 47 */ 48 static std::string IntToHexString(uint8_t value); 49 50 /** 51 * @brief Convert hex string to int 52 * 53 * @param [in] hex string 54 * @param [out] int vector value 55 */ 56 static void ConvertHexStringToInt(const std::string &str, std::vector<uint8_t> &key); 57 58 /** 59 * @brief Generate 16 hex uint8_t vector 60 * 61 * @param [out] int vector value 62 */ 63 static void Rand16hex(std::vector<uint8_t> &key); 64 65 /** 66 * @brief Get random address 67 * 68 * @param [out] uint8_t value 69 * @param [in] bool true:non res pri addr;false:static address 70 */ 71 static void GetRandomAddress(std::vector<uint8_t> &addr, bool isNonResPriAddr); 72 73 private: 74 const static uint8_t HEX_FORMAT_SIZE = 3; 75 const static uint8_t HEX = 16; 76 }; 77 } // namespace bluetooth 78 } // namespace OHOS 79 #endif // BLE_UTILS_H