| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 1 | /* | 
|  | 2 | // Copyright (c) 2018 Intel Corporation | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #pragma once | 
|  | 18 | #include "channel_layer.hpp" | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 19 | #include "ipmid/api-types.hpp" | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 20 |  | 
|  | 21 | #include <boost/interprocess/sync/file_lock.hpp> | 
|  | 22 | #include <boost/interprocess/sync/named_recursive_mutex.hpp> | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 23 | #include <nlohmann/json.hpp> | 
|  | 24 | #include <sdbusplus/bus.hpp> | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 25 |  | 
|  | 26 | #include <cstdint> | 
|  | 27 | #include <ctime> | 
| Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 28 | #include <variant> | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 29 |  | 
|  | 30 | namespace ipmi | 
|  | 31 | { | 
|  | 32 |  | 
|  | 33 | using Json = nlohmann::json; | 
|  | 34 |  | 
| Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 35 | using DbusVariant = std::variant<std::vector<std::string>, std::string, bool>; | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 36 |  | 
|  | 37 | using DbusChObjProperties = std::vector<std::pair<std::string, DbusVariant>>; | 
|  | 38 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 39 | static constexpr const char* ipmiChannelMutex = "ipmi_channel_mutex"; | 
|  | 40 | static constexpr const char* ipmiChMutexCleanupLockFile = | 
| Patrick Williams | 0284491 | 2025-03-20 20:11:10 -0400 | [diff] [blame] | 41 | "/run/ipmi/ipmi_channel_mutex_cleanup"; | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 42 |  | 
| Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 43 | /** @struct ChannelAccessData | 
|  | 44 | * | 
|  | 45 | *  Structure to store both non-volatile and volatile channel access information | 
|  | 46 | *  as used by IPMI specification (refer spec sec 22.22 to 22.24) | 
|  | 47 | */ | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 48 | struct ChannelAccessData | 
|  | 49 | { | 
|  | 50 | ChannelAccess chNonVolatileData; | 
|  | 51 | ChannelAccess chVolatileData; | 
|  | 52 | }; | 
|  | 53 |  | 
| Johnathan Mantey | 4c0435a | 2018-12-11 13:17:55 -0800 | [diff] [blame] | 54 | /** @struct ChannelProperties | 
| Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 55 | * | 
|  | 56 | *  Structure for channel information - base structure to get all information | 
|  | 57 | * about the channel.(refer spec sec 22.22 to 22.24) | 
|  | 58 | */ | 
| Johnathan Mantey | 4c0435a | 2018-12-11 13:17:55 -0800 | [diff] [blame] | 59 | struct ChannelProperties | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 60 | { | 
|  | 61 | std::string chName; | 
|  | 62 | uint8_t chID; | 
|  | 63 | bool isChValid; | 
|  | 64 | uint8_t activeSessCount; | 
|  | 65 | ChannelInfo chInfo; | 
|  | 66 | ChannelAccessData chAccess; | 
| Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 67 | size_t maxTransferSize; | 
| Johnathan Mantey | fd61fc3 | 2021-04-08 11:05:38 -0700 | [diff] [blame] | 68 | bool isManagementNIC; | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 69 | }; | 
|  | 70 |  | 
|  | 71 | class ChannelConfig; | 
|  | 72 |  | 
|  | 73 | ChannelConfig& getChannelConfigObject(); | 
|  | 74 |  | 
|  | 75 | class ChannelConfig | 
|  | 76 | { | 
|  | 77 | public: | 
|  | 78 | ChannelConfig(const ChannelConfig&) = delete; | 
|  | 79 | ChannelConfig& operator=(const ChannelConfig&) = delete; | 
|  | 80 | ChannelConfig(ChannelConfig&&) = delete; | 
|  | 81 | ChannelConfig& operator=(ChannelConfig&&) = delete; | 
|  | 82 |  | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 83 | ~ChannelConfig(); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 84 | ChannelConfig(); | 
|  | 85 |  | 
|  | 86 | /** @brief determines valid channel | 
|  | 87 | * | 
|  | 88 | *  @param[in] chNum - channel number | 
|  | 89 | * | 
|  | 90 | *  @return true if valid, false otherwise | 
|  | 91 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 92 | bool isValidChannel(const uint8_t chNum); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 93 |  | 
|  | 94 | /** @brief determines valid authentication type | 
|  | 95 | * | 
|  | 96 | *  @param[in] chNum - channel number | 
|  | 97 | *  @param[in] authType - authentication type | 
|  | 98 | * | 
|  | 99 | *  @return true if valid, false otherwise | 
|  | 100 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 101 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 102 |  | 
| Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 103 | /** @brief function to get channel name from channel number | 
|  | 104 | * | 
|  | 105 | *  @param[in] chNum - channel number index | 
|  | 106 | * | 
|  | 107 | *  @return network channel interface name | 
|  | 108 | */ | 
|  | 109 | std::string getChannelName(const uint8_t chNum); | 
|  | 110 |  | 
| Vernon Mauery | 735ee95 | 2019-02-15 13:38:52 -0800 | [diff] [blame] | 111 | /** @brief function to get channel number from channel name | 
|  | 112 | * | 
|  | 113 | *  @param[in] chName - channel name | 
|  | 114 | * | 
|  | 115 | *  @return network channel interface number | 
|  | 116 | */ | 
|  | 117 |  | 
|  | 118 | uint8_t getChannelByName(const std::string& chName) | 
|  | 119 | { | 
|  | 120 | return convertToChannelNumberFromChannelName(chName); | 
|  | 121 | } | 
|  | 122 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 123 | /** @brief determines supported session type of a channel | 
|  | 124 | * | 
|  | 125 | *  @param[in] chNum - channel number | 
|  | 126 | * | 
|  | 127 | *  @return EChannelSessSupported - supported session type | 
|  | 128 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 129 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 130 |  | 
|  | 131 | /** @brief determines number of active sessions on a channel | 
|  | 132 | * | 
|  | 133 | *  @param[in] chNum - channel number | 
|  | 134 | * | 
|  | 135 | *  @return numer of active sessions | 
|  | 136 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 137 | int getChannelActiveSessions(const uint8_t chNum); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 138 |  | 
| Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 139 | /** @brief determines maximum transfer size for a channel | 
|  | 140 | * | 
|  | 141 | *  @param[in] chNum - channel number | 
|  | 142 | * | 
|  | 143 | *  @return maximum bytes that can be transferred on this channel | 
|  | 144 | */ | 
|  | 145 | size_t getChannelMaxTransferSize(uint8_t chNum); | 
|  | 146 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 147 | /** @brief provides channel info details | 
|  | 148 | * | 
|  | 149 | *  @param[in] chNum - channel number | 
|  | 150 | *  @param[out] chInfo - channel info details | 
|  | 151 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 152 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 153 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 154 | Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 155 |  | 
|  | 156 | /** @brief provides channel access data | 
|  | 157 | * | 
|  | 158 | *  @param[in] chNum - channel number | 
|  | 159 | *  @param[out] chAccessData - channel access data | 
|  | 160 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 161 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 162 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 163 | Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 164 |  | 
|  | 165 | /** @brief to set channel access data | 
|  | 166 | * | 
|  | 167 | *  @param[in] chNum - channel number | 
|  | 168 | *  @param[in] chAccessData - channel access data | 
|  | 169 | *  @param[in] setFlag - flag to indicate updatable fields | 
|  | 170 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 171 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 172 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 173 | Cc setChannelAccessData(const uint8_t chNum, | 
|  | 174 | const ChannelAccess& chAccessData, | 
|  | 175 | const uint8_t setFlag); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 176 |  | 
|  | 177 | /** @brief to get channel access data persistent data | 
|  | 178 | * | 
|  | 179 | *  @param[in] chNum - channel number | 
|  | 180 | *  @param[out] chAccessData - channel access data | 
|  | 181 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 182 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 183 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 184 | Cc getChannelAccessPersistData(const uint8_t chNum, | 
|  | 185 | ChannelAccess& chAccessData); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 186 |  | 
|  | 187 | /** @brief to set channel access data persistent data | 
|  | 188 | * | 
|  | 189 | *  @param[in] chNum - channel number | 
|  | 190 | *  @param[in] chAccessData - channel access data | 
|  | 191 | *  @param[in] setFlag - flag to indicate updatable fields | 
|  | 192 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 193 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 194 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 195 | Cc setChannelAccessPersistData(const uint8_t chNum, | 
|  | 196 | const ChannelAccess& chAccessData, | 
|  | 197 | const uint8_t setFlag); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 198 |  | 
|  | 199 | /** @brief provides supported authentication type for the channel | 
|  | 200 | * | 
|  | 201 | *  @param[in] chNum - channel number | 
|  | 202 | *  @param[out] authTypeSupported - supported authentication type | 
|  | 203 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 204 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 205 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 206 | Cc getChannelAuthTypeSupported(const uint8_t chNum, | 
|  | 207 | uint8_t& authTypeSupported); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 208 |  | 
|  | 209 | /** @brief provides enabled authentication type for the channel | 
|  | 210 | * | 
|  | 211 | *  @param[in] chNum - channel number | 
|  | 212 | *  @param[in] priv - privilege | 
|  | 213 | *  @param[out] authType - enabled authentication type | 
|  | 214 | * | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 215 | *  @return ccSuccess for success, others for failure. | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 216 | */ | 
| NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 217 | Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, | 
|  | 218 | EAuthType& authType); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 219 |  | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 220 | /** @brief conver to channel privilege from system privilege | 
|  | 221 | * | 
|  | 222 | *  @param[in] value - privilege value | 
|  | 223 | * | 
|  | 224 | *  @return Channel privilege | 
|  | 225 | */ | 
|  | 226 | CommandPrivilege convertToPrivLimitIndex(const std::string& value); | 
|  | 227 |  | 
|  | 228 | /** @brief function to write persistent channel configuration to config file | 
|  | 229 | * | 
|  | 230 | *  @return 0 for success, -errno for failure. | 
|  | 231 | */ | 
|  | 232 | int writeChannelPersistData(); | 
|  | 233 |  | 
|  | 234 | /** @brief function to write volatile channel configuration to config file | 
|  | 235 | * | 
|  | 236 | *  @return 0 for success, -errno for failure. | 
|  | 237 | */ | 
|  | 238 | int writeChannelVolatileData(); | 
|  | 239 |  | 
| Johnathan Mantey | fd61fc3 | 2021-04-08 11:05:38 -0700 | [diff] [blame] | 240 | /** @brief Returns the IPMI channel ID authorized to push IPMI privilege | 
|  | 241 | * changes to phosphor-user-manager. Any channel access changes made on | 
|  | 242 | * any other channel are ignored. | 
|  | 243 | * | 
|  | 244 | *  @return IPMI channel ID as defined in channel_config.json | 
|  | 245 | */ | 
|  | 246 | uint8_t getManagementNICID(); | 
|  | 247 |  | 
| Johnathan Mantey | 2dfe7f8 | 2018-12-11 13:53:33 -0800 | [diff] [blame] | 248 | private: | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 249 | uint32_t signalFlag = 0; | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 250 | std::unique_ptr<boost::interprocess::named_recursive_mutex> channelMutex{ | 
|  | 251 | nullptr}; | 
| Johnathan Mantey | 4c0435a | 2018-12-11 13:17:55 -0800 | [diff] [blame] | 252 | std::array<ChannelProperties, maxIpmiChannels> channelData; | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 253 | std::time_t nvFileLastUpdatedTime; | 
|  | 254 | std::time_t voltFileLastUpdatedTime; | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 255 | boost::interprocess::file_lock mutexCleanupLock; | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 256 | sdbusplus::bus_t bus; | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 257 | bool signalHndlrObjectState = false; | 
|  | 258 | boost::interprocess::file_lock sigHndlrLock; | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 259 |  | 
|  | 260 | /** @brief function to initialize persistent channel configuration | 
|  | 261 | * | 
|  | 262 | */ | 
|  | 263 | void initChannelPersistData(); | 
|  | 264 |  | 
|  | 265 | /** @brief function to set default channel configuration based on channel | 
|  | 266 | * number | 
|  | 267 | * | 
|  | 268 | *  @param[in] chNum - channel number | 
|  | 269 | *  @param[in] chName - channel name | 
|  | 270 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 271 | void setDefaultChannelConfig(const uint8_t chNum, | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 272 | const std::string& chName); | 
|  | 273 |  | 
|  | 274 | /** @brief function to load all channel configuration | 
|  | 275 | * | 
|  | 276 | *  @return 0 for success, -errno for failure. | 
|  | 277 | */ | 
|  | 278 | int loadChannelConfig(); | 
|  | 279 |  | 
|  | 280 | /** @brief function to read persistent channel data | 
|  | 281 | * | 
|  | 282 | *  @return 0 for success, -errno for failure. | 
|  | 283 | */ | 
|  | 284 | int readChannelPersistData(); | 
|  | 285 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 286 | /** @brief function to read volatile channel data | 
|  | 287 | * | 
|  | 288 | *  @return 0 for success, -errno for failure. | 
|  | 289 | */ | 
|  | 290 | int readChannelVolatileData(); | 
|  | 291 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 292 | /** @brief function to check and reload persistent channel data | 
|  | 293 | * | 
|  | 294 | *  @return 0 for success, -errno for failure. | 
|  | 295 | */ | 
|  | 296 | int checkAndReloadNVData(); | 
|  | 297 |  | 
|  | 298 | /** @brief function to check and reload volatile channel data | 
|  | 299 | * | 
|  | 300 | *  @return 0 for success, -errno for failure. | 
|  | 301 | */ | 
|  | 302 | int checkAndReloadVolatileData(); | 
|  | 303 |  | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 304 | /** @brief function to sync channel privilege with system network channel | 
|  | 305 | * privilege | 
|  | 306 | * | 
|  | 307 | *  @return 0 for success, -errno for failure. | 
|  | 308 | */ | 
|  | 309 | int syncNetworkChannelConfig(); | 
|  | 310 |  | 
|  | 311 | /** @brief function to set D-Bus property value | 
|  | 312 | * | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 313 | *  @param[in] service - service name | 
|  | 314 | *  @param[in] objPath - object path | 
|  | 315 | *  @param[in] interface - interface | 
|  | 316 | *  @param[in] property - property name | 
|  | 317 | *  @param[in] value - property value | 
|  | 318 | * | 
|  | 319 | *  @return 0 for success, -errno for failure. | 
|  | 320 | */ | 
| Johnathan Mantey | f92261d | 2018-12-10 15:49:34 -0800 | [diff] [blame] | 321 | int setDbusProperty(const std::string& service, const std::string& objPath, | 
| AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 322 | const std::string& interface, | 
|  | 323 | const std::string& property, const DbusVariant& value); | 
|  | 324 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 325 | /** @brief function to read json config file | 
|  | 326 | * | 
|  | 327 | *  @param[in] configFile - configuration file name | 
|  | 328 | * | 
|  | 329 | *  @return Json object | 
|  | 330 | */ | 
|  | 331 | Json readJsonFile(const std::string& configFile); | 
|  | 332 |  | 
|  | 333 | /** @brief function to write json config file | 
|  | 334 | * | 
|  | 335 | *  @param[in] configFile - configuration file name | 
|  | 336 | *  @param[in] jsonData - json object | 
|  | 337 | * | 
|  | 338 | *  @return 0 for success, -errno for failure. | 
|  | 339 | */ | 
|  | 340 | int writeJsonFile(const std::string& configFile, const Json& jsonData); | 
|  | 341 |  | 
|  | 342 | /** @brief function to convert system access mode to Channel access mode | 
|  | 343 | * type | 
|  | 344 | * | 
|  | 345 | *  @param[in] mode - access mode in string | 
|  | 346 | * | 
|  | 347 | *  @return Channel access mode. | 
|  | 348 | */ | 
|  | 349 | EChannelAccessMode convertToAccessModeIndex(const std::string& mode); | 
|  | 350 |  | 
|  | 351 | /** @brief function to convert access mode value to string | 
|  | 352 | * | 
|  | 353 | *  @param[in] value - acess mode value | 
|  | 354 | * | 
|  | 355 | *  @return access mode in string | 
|  | 356 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 357 | std::string convertToAccessModeString(const uint8_t value); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 358 |  | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 359 | /** @brief function to convert privilege value to string | 
|  | 360 | * | 
|  | 361 | *  @param[in] value - privilege value | 
|  | 362 | * | 
|  | 363 | *  @return privilege in string | 
|  | 364 | */ | 
| Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 365 | std::string convertToPrivLimitString(const uint8_t value); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 366 |  | 
|  | 367 | /** @brief function to convert session support string to value type | 
|  | 368 | * | 
|  | 369 | *  @param[in] value - session support type in string | 
|  | 370 | * | 
|  | 371 | *  @return support session type | 
|  | 372 | */ | 
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 373 | EChannelSessSupported convertToSessionSupportIndex( | 
|  | 374 | const std::string& value); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 375 |  | 
|  | 376 | /** @brief function to convert medium type string to value type | 
|  | 377 | * | 
|  | 378 | *  @param[in] value - medium type in string | 
|  | 379 | * | 
|  | 380 | *  @return channel medium type | 
|  | 381 | */ | 
|  | 382 | EChannelMediumType convertToMediumTypeIndex(const std::string& value); | 
|  | 383 |  | 
|  | 384 | /** @brief function to convert protocol type string to value type | 
|  | 385 | * | 
|  | 386 | *  @param[in] value - protocol type in string | 
|  | 387 | * | 
|  | 388 | *  @return channel protocol  type | 
|  | 389 | */ | 
|  | 390 | EChannelProtocolType convertToProtocolTypeIndex(const std::string& value); | 
| Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame] | 391 |  | 
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 392 | /** @brief function to convert channel name to the IPMI channel number. | 
| Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame] | 393 | * | 
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 394 | *  @param[in] chName - the channel name defined in the JSON input file | 
|  | 395 | *  (i.e. LAN1) | 
| Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame] | 396 | * | 
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 397 | *  @return IPMI channel number | 
| Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame] | 398 | */ | 
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 399 | int convertToChannelNumberFromChannelName(const std::string& chName); | 
| Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame] | 400 |  | 
|  | 401 | /** @brief function to handle Channel access property update through the | 
|  | 402 | * D-Bus handler. | 
|  | 403 | * | 
|  | 404 | *  @param[in] path - D-Bus path to the network element (i.e. eth0) | 
|  | 405 | *  @param[in] chProperties - D-Bus channel properties | 
|  | 406 | */ | 
|  | 407 | void processChAccessPropChange(const std::string& path, | 
|  | 408 | const DbusChObjProperties& chProperties); | 
| Johnathan Mantey | 2dfe7f8 | 2018-12-11 13:53:33 -0800 | [diff] [blame] | 409 |  | 
|  | 410 | /** @brief function to retrieve last modification time for the named file | 
|  | 411 | * | 
|  | 412 | *  @param[in] fileName - the name of the file for which to acquire | 
|  | 413 | *  timestamp data | 
|  | 414 | * | 
|  | 415 | *  @return time the file was last modified | 
|  | 416 | */ | 
|  | 417 | std::time_t getUpdatedFileTime(const std::string& fileName); | 
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 418 |  | 
|  | 419 | /** @brief function to convert the DBus path to a network channel name | 
|  | 420 | * | 
|  | 421 | *  @param[in] path - The DBus path to the device | 
|  | 422 | * | 
|  | 423 | *  @return network channel name (i.e. eth0) | 
|  | 424 | */ | 
|  | 425 | std::string getChannelNameFromPath(const std::string& path); | 
| AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 426 | }; | 
|  | 427 |  | 
|  | 428 | } // namespace ipmi |