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