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_CONFIG_H 17 #define BLE_CONFIG_H 18 19 #include <cstring> 20 #include <vector> 21 22 #include "adapter_device_config.h" 23 #include "adapter_device_info.h" 24 25 /* 26 * @brief The Bluetooth subsystem. 27 */ 28 namespace OHOS { 29 namespace bluetooth { 30 /** 31 * @brief BLE config. 32 */ 33 class BleConfig { 34 public: 35 static BleConfig &GetInstance(); 36 37 bool LoadConfigInfo() const; 38 bool Save() const; 39 40 std::string GetLocalAddress() const; 41 std::string GetLocalName() const; 42 int GetIoCapability() const; 43 std::string GetLoaclPasskey() const; 44 int GetBleRoles() const; 45 int GetBleModel1Level() const; 46 int GetBleModel2Level() const; 47 bool GetBleSecurity() const; 48 int GetBleScanMode() const; 49 int GetAppearance() const; 50 int GetBleLocalAddrType() const; 51 int GetBleAddrType() const; 52 53 bool SetLocalAddress(const std::string &addr) const; 54 bool SetLocalName(const std::string &name) const; 55 bool SetBleRoles(uint8_t roles) const; 56 bool SetPasskey(const std::string &passkey) const; 57 bool SetBleModel1Level(int level) const; 58 bool SetBleModel2Level(int level) const; 59 bool SetBleSecurity(bool security) const; 60 bool SetBleScanMode(int scanmode) const; 61 bool SetBleLocalAddrType(int localAddrType) const; 62 63 /// local 64 bool SetLocalIdentityAddr(const std::string &addr) const; 65 bool SetLocalIrk(const std::string &irk) const; 66 bool SetLocalLtk(const std::string §ion, const std::string <k) const; 67 bool SetLocalKeySize(const std::string §ion, const std::string &keysize) const; 68 bool SetLocalEdivRand(const std::string §ion, const std::string &ediv, const std::string &rand) const; 69 bool SetLocalCsrk(const std::string §ion, const std::string &csrk) const; 70 bool SetLocalSignCounter(const std::string §ion, uint32_t signCounter) const; 71 72 std::string GetLocalIrk() const; 73 std::string GetLocalLtk(const std::string §ion) const; 74 std::string GetLocalEdiv(const std::string §ion) const; 75 std::string GetLocalRand(const std::string §ion) const; 76 std::string GetLocalCsrk(const std::string §ion) const; 77 uint32_t GetLocalSignCounter(const std::string §ion) const; 78 79 /// peer 80 bool SetPeerKeyType(const std::string §ion, const std::string &keytype) const; 81 bool SetPeerLtk(const std::string §ion, const std::string <k) const; 82 bool SetPeerKeySize(const std::string §ion, const std::string &keysize) const; 83 bool SetPeerEdivRand(const std::string §ion, const std::string &ediv, const std::string &rand) const; 84 bool SetPeerIdentityAddr(const std::string §ion, uint8_t type, const std::string &peerAddress) const; 85 bool SetPeerIrk(const std::string §ion, const std::string &irk) const; 86 bool SetPeerCsrk(const std::string §ion, const std::string &csrk) const; 87 bool SetPeerSignCounter(const std::string §ion, uint32_t signCounter) const; 88 89 std::string GetPeerLtk(const std::string §ion) const; 90 std::string GetPeerEdiv(const std::string §ion) const; 91 std::string GetPeerRand(const std::string §ion) const; 92 std::string GetPeerIdentityAddr(const std::string §ion) const; 93 std::string GetPeerIrk(const std::string §ion) const; 94 std::string GetPeerCsrk(const std::string §ion) const; 95 uint32_t GetPeerSignCounter(const std::string §ion) const; 96 97 /// Api for get paired device info. 98 std::string GetPeerName(const std::string &subSection) const; 99 std::string GetPeerAlias(const std::string &subSection) const; 100 int GetPeerDeviceType(const std::string &subSection) const; 101 int GetPeerDeviceIoCapability(const std::string &subSection) const; 102 int GetPeerAddressType(const std::string &subSection) const; 103 104 bool SetPeerName(const std::string &subSection, const std::string &name) const; 105 bool SetPeerDeviceType(const std::string &subSection, const int type) const; 106 bool SetPeerDeviceIoCapability(const std::string &subSection, const int io) const; 107 bool SetPeerAddressType(const std::string &subSection, const int type) const; 108 bool RemovePairedDevice(const std::string &subSection) const; 109 110 std::vector<std::string> GetPairedAddrList() const; 111 112 private: 113 /** 114 * @brief Constructor. 115 */ 116 BleConfig(); 117 118 /** 119 * @brief Destructor. 120 */ 121 ~BleConfig(); 122 /** 123 * @brief Constructor. 124 */ 125 BleConfig(BleConfig &) = delete; 126 127 /** 128 * @brief Constructor. 129 */ 130 BleConfig &operator=(const BleConfig &) = delete; 131 /** 132 * @brief Ble config single instance. 133 */ 134 IAdapterDeviceConfig *config_ = nullptr; 135 }; 136 } // namespace bluetooth 137 } // namespace OHOS 138 139 #endif // BLE_CONFIG_H 140