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 | #include "channel_mgmt.hpp" |
| 18 | |
| 19 | #include "apphandler.hpp" |
| 20 | |
| 21 | #include <sys/stat.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | #include <boost/interprocess/sync/scoped_lock.hpp> |
| 25 | #include <cerrno> |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 26 | #include <exception> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 27 | #include <experimental/filesystem> |
| 28 | #include <fstream> |
| 29 | #include <phosphor-logging/log.hpp> |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 30 | #include <sdbusplus/bus/match.hpp> |
| 31 | #include <sdbusplus/server/object.hpp> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 32 | #include <unordered_map> |
| 33 | |
| 34 | namespace ipmi |
| 35 | { |
| 36 | |
William A. Kennington III | dfad486 | 2018-11-19 17:45:35 -0800 | [diff] [blame] | 37 | namespace variant_ns = sdbusplus::message::variant_ns; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 38 | using namespace phosphor::logging; |
| 39 | |
| 40 | static constexpr const char* channelAccessDefaultFilename = |
| 41 | "/usr/share/ipmi-providers/channel_access.json"; |
| 42 | static constexpr const char* channelConfigDefaultFilename = |
| 43 | "/usr/share/ipmi-providers/channel_config.json"; |
| 44 | static constexpr const char* channelNvDataFilename = |
| 45 | "/var/lib/ipmi/channel_access_nv.json"; |
| 46 | static constexpr const char* channelVolatileDataFilename = |
| 47 | "/run/ipmi/channel_access_volatile.json"; |
| 48 | |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 49 | // TODO: Get the service name dynamically.. |
| 50 | static constexpr const char* networkIntfServiceName = |
| 51 | "xyz.openbmc_project.Network"; |
| 52 | static constexpr const char* networkIntfObjectBasePath = |
| 53 | "/xyz/openbmc_project/network"; |
| 54 | static constexpr const char* networkChConfigIntfName = |
| 55 | "xyz.openbmc_project.Channel.ChannelAccess"; |
| 56 | static constexpr const char* privilegePropertyString = "MaxPrivilege"; |
| 57 | static constexpr const char* dBusPropertiesInterface = |
| 58 | "org.freedesktop.DBus.Properties"; |
| 59 | static constexpr const char* propertiesChangedSignal = "PropertiesChanged"; |
| 60 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 61 | // STRING DEFINES: Should sync with key's in JSON |
| 62 | static constexpr const char* nameString = "name"; |
| 63 | static constexpr const char* isValidString = "is_valid"; |
| 64 | static constexpr const char* activeSessionsString = "active_sessions"; |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 65 | static constexpr const char* maxTransferSizeString = "max_transfer_size"; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 66 | static constexpr const char* channelInfoString = "channel_info"; |
| 67 | static constexpr const char* mediumTypeString = "medium_type"; |
| 68 | static constexpr const char* protocolTypeString = "protocol_type"; |
| 69 | static constexpr const char* sessionSupportedString = "session_supported"; |
| 70 | static constexpr const char* isIpmiString = "is_ipmi"; |
| 71 | static constexpr const char* authTypeSupportedString = "auth_type_supported"; |
| 72 | static constexpr const char* accessModeString = "access_mode"; |
| 73 | static constexpr const char* userAuthDisabledString = "user_auth_disabled"; |
| 74 | static constexpr const char* perMsgAuthDisabledString = "per_msg_auth_disabled"; |
| 75 | static constexpr const char* alertingDisabledString = "alerting_disabled"; |
| 76 | static constexpr const char* privLimitString = "priv_limit"; |
| 77 | static constexpr const char* authTypeEnabledString = "auth_type_enabled"; |
| 78 | |
| 79 | // Default values |
| 80 | static constexpr const char* defaultChannelName = "RESERVED"; |
| 81 | static constexpr const uint8_t defaultMediumType = |
| 82 | static_cast<uint8_t>(EChannelMediumType::reserved); |
| 83 | static constexpr const uint8_t defaultProtocolType = |
| 84 | static_cast<uint8_t>(EChannelProtocolType::reserved); |
| 85 | static constexpr const uint8_t defaultSessionSupported = |
| 86 | static_cast<uint8_t>(EChannelSessSupported::none); |
| 87 | static constexpr const uint8_t defaultAuthType = |
| 88 | static_cast<uint8_t>(EAuthType::none); |
| 89 | static constexpr const bool defaultIsIpmiState = false; |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 90 | static constexpr size_t smallChannelSize = 64; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 91 | |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 92 | std::unique_ptr<sdbusplus::bus::match_t> chPropertiesSignal(nullptr); |
| 93 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 94 | // String mappings use in JSON config file |
| 95 | static std::unordered_map<std::string, EChannelMediumType> mediumTypeMap = { |
| 96 | {"reserved", EChannelMediumType::reserved}, |
| 97 | {"ipmb", EChannelMediumType::ipmb}, |
| 98 | {"icmb-v1.0", EChannelMediumType::icmbV10}, |
| 99 | {"icmb-v0.9", EChannelMediumType::icmbV09}, |
| 100 | {"lan-802.3", EChannelMediumType::lan8032}, |
| 101 | {"serial", EChannelMediumType::serial}, |
| 102 | {"other-lan", EChannelMediumType::otherLan}, |
| 103 | {"pci-smbus", EChannelMediumType::pciSmbus}, |
| 104 | {"smbus-v1.0", EChannelMediumType::smbusV11}, |
| 105 | {"smbus-v2.0", EChannelMediumType::smbusV20}, |
| 106 | {"usb-1x", EChannelMediumType::usbV1x}, |
| 107 | {"usb-2x", EChannelMediumType::usbV2x}, |
| 108 | {"system-interface", EChannelMediumType::systemInterface}, |
| 109 | {"oem", EChannelMediumType::oem}, |
| 110 | {"unknown", EChannelMediumType::unknown}}; |
| 111 | |
ssekar | f4b2b09 | 2018-07-25 18:49:08 +0530 | [diff] [blame] | 112 | static std::unordered_map<EInterfaceIndex, std::string> interfaceMap = { |
Richard Marian Thomaiyar | 43cb128 | 2018-12-08 17:22:53 +0530 | [diff] [blame] | 113 | {interfaceKCS, "SMS"}, |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 114 | {interfaceLAN1, "eth0"}, |
ssekar | f4b2b09 | 2018-07-25 18:49:08 +0530 | [diff] [blame] | 115 | {interfaceUnknown, "unknown"}}; |
| 116 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 117 | static std::unordered_map<std::string, EChannelProtocolType> protocolTypeMap = { |
| 118 | {"na", EChannelProtocolType::na}, |
| 119 | {"ipmb-1.0", EChannelProtocolType::ipmbV10}, |
| 120 | {"icmb-2.0", EChannelProtocolType::icmbV11}, |
| 121 | {"reserved", EChannelProtocolType::reserved}, |
| 122 | {"ipmi-smbus", EChannelProtocolType::ipmiSmbus}, |
| 123 | {"kcs", EChannelProtocolType::kcs}, |
| 124 | {"smic", EChannelProtocolType::smic}, |
| 125 | {"bt-10", EChannelProtocolType::bt10}, |
| 126 | {"bt-15", EChannelProtocolType::bt15}, |
| 127 | {"tmode", EChannelProtocolType::tMode}, |
| 128 | {"oem", EChannelProtocolType::oem}}; |
| 129 | |
| 130 | static std::array<std::string, 4> accessModeList = { |
| 131 | "disabled", "pre-boot", "always_available", "shared"}; |
| 132 | |
| 133 | static std::array<std::string, 4> sessionSupportList = { |
| 134 | "session-less", "single-session", "multi-session", "session-based"}; |
| 135 | |
| 136 | static std::array<std::string, PRIVILEGE_OEM + 1> privList = { |
| 137 | "priv-reserved", "priv-callback", "priv-user", |
| 138 | "priv-operator", "priv-admin", "priv-oem"}; |
| 139 | |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 140 | std::string getNetIntfFromPath(const std::string& path) |
| 141 | { |
| 142 | std::size_t pos = path.find(networkIntfObjectBasePath); |
| 143 | if (pos == std::string::npos) |
| 144 | { |
| 145 | log<level::ERR>("Invalid interface path.", |
| 146 | entry("PATH:%s", path.c_str())); |
| 147 | throw std::invalid_argument("Invalid interface path"); |
| 148 | } |
| 149 | std::string intfName = |
| 150 | path.substr(pos + strlen(networkIntfObjectBasePath) + 1); |
| 151 | return intfName; |
| 152 | } |
| 153 | |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 154 | void ChannelConfig::processChAccessPropChange( |
| 155 | const std::string& path, const DbusChObjProperties& chProperties) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 156 | { |
| 157 | // Get interface name from path. ex: '/xyz/openbmc_project/network/eth0' |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 158 | std::string channelName; |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 159 | try |
| 160 | { |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 161 | channelName = getNetIntfFromPath(path); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 162 | } |
| 163 | catch (const std::invalid_argument& e) |
| 164 | { |
| 165 | log<level::ERR>("Exception: ", entry("MSG: %s", e.what())); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | // Get the MaxPrivilege property value from the signal |
| 170 | std::string intfPrivStr; |
| 171 | std::string propName; |
| 172 | for (const auto& prop : chProperties) |
| 173 | { |
| 174 | if (prop.first == privilegePropertyString) |
| 175 | { |
| 176 | propName = privilegePropertyString; |
William A. Kennington III | dfad486 | 2018-11-19 17:45:35 -0800 | [diff] [blame] | 177 | intfPrivStr = variant_ns::get<std::string>(prop.second); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if (propName != privilegePropertyString) |
| 183 | { |
| 184 | log<level::ERR>("Unknown signal caught."); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | if (intfPrivStr.empty()) |
| 189 | { |
| 190 | log<level::ERR>("Invalid privilege string.", |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 191 | entry("INTF:%s", channelName.c_str())); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
| 195 | uint8_t intfPriv = 0; |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 196 | try |
| 197 | { |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 198 | intfPriv = static_cast<uint8_t>(convertToPrivLimitIndex(intfPrivStr)); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 199 | } |
| 200 | catch (const std::invalid_argument& e) |
| 201 | { |
| 202 | log<level::ERR>("Exception: ", entry("MSG: %s", e.what())); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 207 | channelLock{*channelMutex}; |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 208 | uint8_t chNum = 0; |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 209 | // Get the channel number based on the channel name. |
| 210 | for (chNum = 0; chNum < maxIpmiChannels; chNum++) |
| 211 | { |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 212 | if (channelData[chNum].chName == channelName) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 213 | { |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | if (chNum >= maxIpmiChannels) |
| 218 | { |
| 219 | log<level::ERR>("Invalid interface in signal path"); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | // skip updating the values, if this property change originated from IPMI. |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 224 | if (signalFlag & (1 << chNum)) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 225 | { |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 226 | signalFlag &= ~(1 << chNum); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 227 | log<level::DEBUG>("Request originated from IPMI so ignoring signal"); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // Update both volatile & Non-volatile, if there is mismatch. |
| 232 | // as property change other than IPMI, has to update both volatile & |
| 233 | // non-volatile data. |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 234 | checkAndReloadVolatileData(); |
| 235 | checkAndReloadNVData(); |
| 236 | if (channelData[chNum].chAccess.chNonVolatileData.privLimit != intfPriv) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 237 | { |
| 238 | // Update NV data |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 239 | channelData[chNum].chAccess.chNonVolatileData.privLimit = intfPriv; |
| 240 | if (writeChannelPersistData() != 0) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 241 | { |
| 242 | log<level::ERR>("Failed to update the persist data file"); |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | // Update Volatile data |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 247 | if (channelData[chNum].chAccess.chVolatileData.privLimit != intfPriv) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 248 | { |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 249 | channelData[chNum].chAccess.chVolatileData.privLimit = intfPriv; |
| 250 | if (writeChannelVolatileData() != 0) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 251 | { |
| 252 | log<level::ERR>("Failed to update the volatile data file"); |
| 253 | return; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return; |
| 259 | } |
| 260 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 261 | ChannelConfig& getChannelConfigObject() |
| 262 | { |
| 263 | static ChannelConfig channelConfig; |
| 264 | return channelConfig; |
| 265 | } |
| 266 | |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 267 | ChannelConfig::~ChannelConfig() |
| 268 | { |
| 269 | if (signalHndlrObjectState) |
| 270 | { |
| 271 | chPropertiesSignal.reset(); |
| 272 | sigHndlrLock.unlock(); |
| 273 | } |
| 274 | } |
| 275 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 276 | ChannelConfig::ChannelConfig() : bus(ipmid_get_sd_bus_connection()) |
| 277 | { |
| 278 | std::ofstream mutexCleanUpFile; |
| 279 | mutexCleanUpFile.open(ipmiChMutexCleanupLockFile, |
| 280 | std::ofstream::out | std::ofstream::app); |
| 281 | if (!mutexCleanUpFile.good()) |
| 282 | { |
| 283 | log<level::DEBUG>("Unable to open mutex cleanup file"); |
| 284 | return; |
| 285 | } |
| 286 | mutexCleanUpFile.close(); |
| 287 | mutexCleanupLock = |
| 288 | boost::interprocess::file_lock(ipmiChMutexCleanupLockFile); |
| 289 | if (mutexCleanupLock.try_lock()) |
| 290 | { |
| 291 | boost::interprocess::named_recursive_mutex::remove(ipmiChannelMutex); |
| 292 | channelMutex = |
| 293 | std::make_unique<boost::interprocess::named_recursive_mutex>( |
| 294 | boost::interprocess::open_or_create, ipmiChannelMutex); |
| 295 | mutexCleanupLock.lock_sharable(); |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | mutexCleanupLock.lock_sharable(); |
| 300 | channelMutex = |
| 301 | std::make_unique<boost::interprocess::named_recursive_mutex>( |
| 302 | boost::interprocess::open_or_create, ipmiChannelMutex); |
| 303 | } |
| 304 | |
| 305 | initChannelPersistData(); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 306 | |
| 307 | sigHndlrLock = boost::interprocess::file_lock(channelNvDataFilename); |
| 308 | // Register it for single object and single process either netipimd / |
| 309 | // host-ipmid |
| 310 | if (chPropertiesSignal == nullptr && sigHndlrLock.try_lock()) |
| 311 | { |
| 312 | log<level::DEBUG>("Registering channel signal handler."); |
| 313 | chPropertiesSignal = std::make_unique<sdbusplus::bus::match_t>( |
| 314 | bus, |
| 315 | sdbusplus::bus::match::rules::path_namespace( |
| 316 | networkIntfObjectBasePath) + |
| 317 | sdbusplus::bus::match::rules::type::signal() + |
| 318 | sdbusplus::bus::match::rules::member(propertiesChangedSignal) + |
| 319 | sdbusplus::bus::match::rules::interface( |
| 320 | dBusPropertiesInterface) + |
| 321 | sdbusplus::bus::match::rules::argN(0, networkChConfigIntfName), |
| 322 | [&](sdbusplus::message::message& msg) { |
| 323 | DbusChObjProperties props; |
| 324 | std::string iface; |
| 325 | std::string path = msg.get_path(); |
| 326 | msg.read(iface, props); |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 327 | processChAccessPropChange(path, props); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 328 | }); |
| 329 | signalHndlrObjectState = true; |
| 330 | } |
| 331 | } |
| 332 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 333 | bool ChannelConfig::isValidChannel(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 334 | { |
| 335 | if (chNum > maxIpmiChannels) |
| 336 | { |
| 337 | log<level::DEBUG>("Invalid channel ID - Out of range"); |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | if (channelData[chNum].isChValid == false) |
| 342 | { |
| 343 | log<level::DEBUG>("Channel is not valid"); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 344 | } |
| 345 | |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 346 | return channelData[chNum].isChValid; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | EChannelSessSupported |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 350 | ChannelConfig::getChannelSessionSupport(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 351 | { |
| 352 | EChannelSessSupported chSessSupport = |
| 353 | (EChannelSessSupported)channelData[chNum].chInfo.sessionSupported; |
| 354 | return chSessSupport; |
| 355 | } |
| 356 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 357 | bool ChannelConfig::isValidAuthType(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 358 | const EAuthType& authType) |
| 359 | { |
| 360 | if ((authType < EAuthType::md2) || (authType > EAuthType::oem)) |
| 361 | { |
| 362 | log<level::DEBUG>("Invalid authentication type"); |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | uint8_t authTypeSupported = channelData[chNum].chInfo.authTypeSupported; |
| 367 | if (!(authTypeSupported & (1 << static_cast<uint8_t>(authType)))) |
| 368 | { |
| 369 | log<level::DEBUG>("Authentication type is not supported."); |
| 370 | return false; |
| 371 | } |
| 372 | |
| 373 | return true; |
| 374 | } |
| 375 | |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 376 | std::string ChannelConfig::getChannelName(const uint8_t chNum) |
| 377 | { |
| 378 | return channelData[chNum].chName; |
| 379 | } |
| 380 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 381 | int ChannelConfig::getChannelActiveSessions(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 382 | { |
| 383 | // TODO: TEMPORARY FIX |
| 384 | // Channels active session count is managed separatly |
| 385 | // by monitoring channel session which includes LAN and |
| 386 | // RAKP layer changes. This will be updated, once the |
| 387 | // authentication part is implemented. |
| 388 | return channelData[chNum].activeSessCount; |
| 389 | } |
| 390 | |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 391 | size_t ChannelConfig::getChannelMaxTransferSize(uint8_t chNum) |
| 392 | { |
| 393 | return channelData[chNum].maxTransferSize; |
| 394 | } |
| 395 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 396 | ipmi_ret_t ChannelConfig::getChannelInfo(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 397 | ChannelInfo& chInfo) |
| 398 | { |
| 399 | if (!isValidChannel(chNum)) |
| 400 | { |
| 401 | log<level::DEBUG>("Invalid channel"); |
| 402 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 403 | } |
| 404 | |
| 405 | std::copy_n(reinterpret_cast<uint8_t*>(&channelData[chNum].chInfo), |
| 406 | sizeof(channelData[chNum].chInfo), |
| 407 | reinterpret_cast<uint8_t*>(&chInfo)); |
| 408 | |
| 409 | return IPMI_CC_OK; |
| 410 | } |
| 411 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 412 | ipmi_ret_t ChannelConfig::getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 413 | ChannelAccess& chAccessData) |
| 414 | { |
| 415 | if (!isValidChannel(chNum)) |
| 416 | { |
| 417 | log<level::DEBUG>("Invalid channel"); |
| 418 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 419 | } |
| 420 | |
| 421 | if (getChannelSessionSupport(chNum) == EChannelSessSupported::none) |
| 422 | { |
| 423 | log<level::DEBUG>("Session-less channel doesn't have access data."); |
| 424 | return IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL; |
| 425 | } |
| 426 | |
| 427 | if (checkAndReloadVolatileData() != 0) |
| 428 | { |
| 429 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 430 | } |
| 431 | |
| 432 | std::copy_n( |
| 433 | reinterpret_cast<uint8_t*>(&channelData[chNum].chAccess.chVolatileData), |
| 434 | sizeof(channelData[chNum].chAccess.chVolatileData), |
| 435 | reinterpret_cast<uint8_t*>(&chAccessData)); |
| 436 | |
| 437 | return IPMI_CC_OK; |
| 438 | } |
| 439 | |
| 440 | ipmi_ret_t |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 441 | ChannelConfig::setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 442 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 443 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 444 | { |
| 445 | if (!isValidChannel(chNum)) |
| 446 | { |
| 447 | log<level::DEBUG>("Invalid channel"); |
| 448 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 449 | } |
| 450 | |
| 451 | if (getChannelSessionSupport(chNum) == EChannelSessSupported::none) |
| 452 | { |
| 453 | log<level::DEBUG>("Session-less channel doesn't have access data."); |
| 454 | return IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL; |
| 455 | } |
| 456 | |
Richard Marian Thomaiyar | 9341160 | 2019-01-29 10:56:57 +0530 | [diff] [blame] | 457 | if (((setFlag & setAccessMode) && |
| 458 | (!isValidAccessMode(chAccessData.accessMode))) || |
| 459 | ((setFlag & setPrivLimit) && |
| 460 | (!isValidPrivLimit(chAccessData.privLimit)))) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 461 | { |
Richard Marian Thomaiyar | 9341160 | 2019-01-29 10:56:57 +0530 | [diff] [blame] | 462 | log<level::DEBUG>("Invalid access mode / privilege limit specified"); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 463 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 464 | } |
| 465 | |
| 466 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 467 | channelLock{*channelMutex}; |
| 468 | |
| 469 | if (checkAndReloadVolatileData() != 0) |
| 470 | { |
| 471 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 472 | } |
| 473 | |
| 474 | if (setFlag & setAccessMode) |
| 475 | { |
| 476 | channelData[chNum].chAccess.chVolatileData.accessMode = |
| 477 | chAccessData.accessMode; |
| 478 | } |
| 479 | if (setFlag & setUserAuthEnabled) |
| 480 | { |
| 481 | channelData[chNum].chAccess.chVolatileData.userAuthDisabled = |
| 482 | chAccessData.userAuthDisabled; |
| 483 | } |
| 484 | if (setFlag & setMsgAuthEnabled) |
| 485 | { |
| 486 | channelData[chNum].chAccess.chVolatileData.perMsgAuthDisabled = |
| 487 | chAccessData.perMsgAuthDisabled; |
| 488 | } |
| 489 | if (setFlag & setAlertingEnabled) |
| 490 | { |
| 491 | channelData[chNum].chAccess.chVolatileData.alertingDisabled = |
| 492 | chAccessData.alertingDisabled; |
| 493 | } |
| 494 | if (setFlag & setPrivLimit) |
| 495 | { |
| 496 | channelData[chNum].chAccess.chVolatileData.privLimit = |
| 497 | chAccessData.privLimit; |
| 498 | } |
| 499 | |
| 500 | // Write Volatile data to file |
| 501 | if (writeChannelVolatileData() != 0) |
| 502 | { |
| 503 | log<level::DEBUG>("Failed to update the channel volatile data"); |
| 504 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 505 | } |
| 506 | return IPMI_CC_OK; |
| 507 | } |
| 508 | |
| 509 | ipmi_ret_t |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 510 | ChannelConfig::getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 511 | ChannelAccess& chAccessData) |
| 512 | { |
| 513 | if (!isValidChannel(chNum)) |
| 514 | { |
| 515 | log<level::DEBUG>("Invalid channel"); |
| 516 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 517 | } |
| 518 | |
| 519 | if (getChannelSessionSupport(chNum) == EChannelSessSupported::none) |
| 520 | { |
| 521 | log<level::DEBUG>("Session-less channel doesn't have access data."); |
| 522 | return IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL; |
| 523 | } |
| 524 | |
| 525 | if (checkAndReloadNVData() != 0) |
| 526 | { |
| 527 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 528 | } |
| 529 | |
| 530 | std::copy_n(reinterpret_cast<uint8_t*>( |
| 531 | &channelData[chNum].chAccess.chNonVolatileData), |
| 532 | sizeof(channelData[chNum].chAccess.chNonVolatileData), |
| 533 | reinterpret_cast<uint8_t*>(&chAccessData)); |
| 534 | |
| 535 | return IPMI_CC_OK; |
| 536 | } |
| 537 | |
| 538 | ipmi_ret_t ChannelConfig::setChannelAccessPersistData( |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 539 | const uint8_t chNum, const ChannelAccess& chAccessData, |
| 540 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 541 | { |
| 542 | if (!isValidChannel(chNum)) |
| 543 | { |
| 544 | log<level::DEBUG>("Invalid channel"); |
| 545 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 546 | } |
| 547 | |
| 548 | if (getChannelSessionSupport(chNum) == EChannelSessSupported::none) |
| 549 | { |
| 550 | log<level::DEBUG>("Session-less channel doesn't have access data."); |
| 551 | return IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL; |
| 552 | } |
| 553 | |
Richard Marian Thomaiyar | 9341160 | 2019-01-29 10:56:57 +0530 | [diff] [blame] | 554 | if (((setFlag & setAccessMode) && |
| 555 | (!isValidAccessMode(chAccessData.accessMode))) || |
| 556 | ((setFlag & setPrivLimit) && |
| 557 | (!isValidPrivLimit(chAccessData.privLimit)))) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 558 | { |
Richard Marian Thomaiyar | 9341160 | 2019-01-29 10:56:57 +0530 | [diff] [blame] | 559 | log<level::DEBUG>("Invalid access mode / privilege limit specified"); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 560 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 561 | } |
| 562 | |
| 563 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 564 | channelLock{*channelMutex}; |
| 565 | |
| 566 | if (checkAndReloadNVData() != 0) |
| 567 | { |
| 568 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 569 | } |
| 570 | |
| 571 | if (setFlag & setAccessMode) |
| 572 | { |
| 573 | channelData[chNum].chAccess.chNonVolatileData.accessMode = |
| 574 | chAccessData.accessMode; |
| 575 | } |
| 576 | if (setFlag & setUserAuthEnabled) |
| 577 | { |
| 578 | channelData[chNum].chAccess.chNonVolatileData.userAuthDisabled = |
| 579 | chAccessData.userAuthDisabled; |
| 580 | } |
| 581 | if (setFlag & setMsgAuthEnabled) |
| 582 | { |
| 583 | channelData[chNum].chAccess.chNonVolatileData.perMsgAuthDisabled = |
| 584 | chAccessData.perMsgAuthDisabled; |
| 585 | } |
| 586 | if (setFlag & setAlertingEnabled) |
| 587 | { |
| 588 | channelData[chNum].chAccess.chNonVolatileData.alertingDisabled = |
| 589 | chAccessData.alertingDisabled; |
| 590 | } |
| 591 | if (setFlag & setPrivLimit) |
| 592 | { |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 593 | // Send Update to network channel config interfaces over dbus |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 594 | std::string privStr = convertToPrivLimitString(chAccessData.privLimit); |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 595 | std::string networkIntfObj = std::string(networkIntfObjectBasePath) + |
| 596 | "/" + channelData[chNum].chName; |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 597 | try |
| 598 | { |
Johnathan Mantey | f92261d | 2018-12-10 15:49:34 -0800 | [diff] [blame] | 599 | if (0 != setDbusProperty(networkIntfServiceName, networkIntfObj, |
| 600 | networkChConfigIntfName, |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 601 | privilegePropertyString, privStr)) |
| 602 | { |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 603 | log<level::DEBUG>( |
| 604 | "Network interface does not exist", |
| 605 | entry("INTERFACE:%s", channelData[chNum].chName.c_str())); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 606 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 607 | } |
| 608 | } |
| 609 | catch (const sdbusplus::exception::SdBusError& e) |
| 610 | { |
| 611 | log<level::ERR>("Exception: Network interface does not exist"); |
| 612 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 613 | } |
| 614 | signalFlag |= (1 << chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 615 | channelData[chNum].chAccess.chNonVolatileData.privLimit = |
| 616 | chAccessData.privLimit; |
| 617 | } |
| 618 | |
| 619 | // Write persistent data to file |
| 620 | if (writeChannelPersistData() != 0) |
| 621 | { |
| 622 | log<level::DEBUG>("Failed to update the presist data file"); |
| 623 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 624 | } |
| 625 | return IPMI_CC_OK; |
| 626 | } |
| 627 | |
| 628 | ipmi_ret_t |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 629 | ChannelConfig::getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 630 | uint8_t& authTypeSupported) |
| 631 | { |
| 632 | if (!isValidChannel(chNum)) |
| 633 | { |
| 634 | log<level::DEBUG>("Invalid channel"); |
| 635 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 636 | } |
| 637 | |
| 638 | authTypeSupported = channelData[chNum].chInfo.authTypeSupported; |
| 639 | return IPMI_CC_OK; |
| 640 | } |
| 641 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 642 | ipmi_ret_t ChannelConfig::getChannelEnabledAuthType(const uint8_t chNum, |
| 643 | const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 644 | EAuthType& authType) |
| 645 | { |
| 646 | if (!isValidChannel(chNum)) |
| 647 | { |
| 648 | log<level::DEBUG>("Invalid channel"); |
| 649 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 650 | } |
| 651 | |
| 652 | if (getChannelSessionSupport(chNum) == EChannelSessSupported::none) |
| 653 | { |
| 654 | log<level::DEBUG>("Sessionless channel doesn't have access data."); |
| 655 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 656 | } |
| 657 | |
| 658 | if (!isValidPrivLimit(priv)) |
| 659 | { |
| 660 | log<level::DEBUG>("Invalid privilege specified."); |
| 661 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 662 | } |
| 663 | |
| 664 | // TODO: Hardcoded for now. Need to implement. |
| 665 | authType = EAuthType::none; |
| 666 | |
| 667 | return IPMI_CC_OK; |
| 668 | } |
| 669 | |
| 670 | std::time_t ChannelConfig::getUpdatedFileTime(const std::string& fileName) |
| 671 | { |
| 672 | struct stat fileStat; |
| 673 | if (stat(fileName.c_str(), &fileStat) != 0) |
| 674 | { |
| 675 | log<level::DEBUG>("Error in getting last updated time stamp"); |
| 676 | return -EIO; |
| 677 | } |
| 678 | return fileStat.st_mtime; |
| 679 | } |
| 680 | |
| 681 | EChannelAccessMode |
| 682 | ChannelConfig::convertToAccessModeIndex(const std::string& mode) |
| 683 | { |
| 684 | auto iter = std::find(accessModeList.begin(), accessModeList.end(), mode); |
| 685 | if (iter == accessModeList.end()) |
| 686 | { |
| 687 | log<level::ERR>("Invalid access mode.", |
| 688 | entry("MODE_STR=%s", mode.c_str())); |
| 689 | throw std::invalid_argument("Invalid access mode."); |
| 690 | } |
| 691 | |
| 692 | return static_cast<EChannelAccessMode>( |
| 693 | std::distance(accessModeList.begin(), iter)); |
| 694 | } |
| 695 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 696 | std::string ChannelConfig::convertToAccessModeString(const uint8_t value) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 697 | { |
| 698 | if (accessModeList.size() <= value) |
| 699 | { |
| 700 | log<level::ERR>("Invalid access mode.", entry("MODE_IDX=%d", value)); |
| 701 | throw std::invalid_argument("Invalid access mode."); |
| 702 | } |
| 703 | |
| 704 | return accessModeList.at(value); |
| 705 | } |
| 706 | |
| 707 | CommandPrivilege |
| 708 | ChannelConfig::convertToPrivLimitIndex(const std::string& value) |
| 709 | { |
| 710 | auto iter = std::find(privList.begin(), privList.end(), value); |
| 711 | if (iter == privList.end()) |
| 712 | { |
| 713 | log<level::ERR>("Invalid privilege.", |
| 714 | entry("PRIV_STR=%s", value.c_str())); |
| 715 | throw std::invalid_argument("Invalid privilege."); |
| 716 | } |
| 717 | |
| 718 | return static_cast<CommandPrivilege>(std::distance(privList.begin(), iter)); |
| 719 | } |
| 720 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 721 | std::string ChannelConfig::convertToPrivLimitString(const uint8_t value) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 722 | { |
| 723 | if (privList.size() <= value) |
| 724 | { |
| 725 | log<level::ERR>("Invalid privilege.", entry("PRIV_IDX=%d", value)); |
| 726 | throw std::invalid_argument("Invalid privilege."); |
| 727 | } |
| 728 | |
| 729 | return privList.at(value); |
| 730 | } |
| 731 | |
| 732 | EChannelSessSupported |
| 733 | ChannelConfig::convertToSessionSupportIndex(const std::string& value) |
| 734 | { |
| 735 | auto iter = |
| 736 | std::find(sessionSupportList.begin(), sessionSupportList.end(), value); |
| 737 | if (iter == sessionSupportList.end()) |
| 738 | { |
| 739 | log<level::ERR>("Invalid session supported.", |
| 740 | entry("SESS_STR=%s", value.c_str())); |
| 741 | throw std::invalid_argument("Invalid session supported."); |
| 742 | } |
| 743 | |
| 744 | return static_cast<EChannelSessSupported>( |
| 745 | std::distance(sessionSupportList.begin(), iter)); |
| 746 | } |
| 747 | |
| 748 | EChannelMediumType |
| 749 | ChannelConfig::convertToMediumTypeIndex(const std::string& value) |
| 750 | { |
| 751 | std::unordered_map<std::string, EChannelMediumType>::iterator it = |
| 752 | mediumTypeMap.find(value); |
| 753 | if (it == mediumTypeMap.end()) |
| 754 | { |
| 755 | log<level::ERR>("Invalid medium type.", |
| 756 | entry("MEDIUM_STR=%s", value.c_str())); |
| 757 | throw std::invalid_argument("Invalid medium type."); |
| 758 | } |
| 759 | |
| 760 | return static_cast<EChannelMediumType>(it->second); |
| 761 | } |
| 762 | |
| 763 | EChannelProtocolType |
| 764 | ChannelConfig::convertToProtocolTypeIndex(const std::string& value) |
| 765 | { |
| 766 | std::unordered_map<std::string, EChannelProtocolType>::iterator it = |
| 767 | protocolTypeMap.find(value); |
| 768 | if (it == protocolTypeMap.end()) |
| 769 | { |
| 770 | log<level::ERR>("Invalid protocol type.", |
| 771 | entry("PROTO_STR=%s", value.c_str())); |
| 772 | throw std::invalid_argument("Invalid protocol type."); |
| 773 | } |
| 774 | |
| 775 | return static_cast<EChannelProtocolType>(it->second); |
| 776 | } |
| 777 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 778 | uint8_t ChannelConfig::convertToChannelIndexNumber(const uint8_t chNum) |
ssekar | f4b2b09 | 2018-07-25 18:49:08 +0530 | [diff] [blame] | 779 | { |
| 780 | |
| 781 | // TODO: There is limitation in current design. we cannot detect exact |
| 782 | // LAN interface(eth0 or eth1) so Implementation may be updated |
| 783 | // when there is any design update to figure out all the interfaces |
| 784 | // independently based on the message. |
| 785 | |
| 786 | static uint8_t curChannel = 0xFF; |
| 787 | |
| 788 | if (curChannel == 0xFF) |
| 789 | { |
| 790 | auto it = interfaceMap.find(getInterfaceIndex()); |
| 791 | if (it == interfaceMap.end()) |
| 792 | { |
| 793 | log<level::ERR>("Invalid Interface type ", |
| 794 | entry("InterfaceIndex: %d", getInterfaceIndex())); |
| 795 | throw std::invalid_argument("Invalid interface type."); |
| 796 | } |
| 797 | |
| 798 | for (auto& channel : channelData) |
| 799 | { |
| 800 | std::string& interfaceName = it->second; |
| 801 | if (channel.chName == interfaceName) |
| 802 | { |
| 803 | curChannel = channel.chID; |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | } |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 808 | return ((chNum == currentChNum) ? curChannel : chNum); |
ssekar | f4b2b09 | 2018-07-25 18:49:08 +0530 | [diff] [blame] | 809 | } |
| 810 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 811 | Json ChannelConfig::readJsonFile(const std::string& configFile) |
| 812 | { |
| 813 | std::ifstream jsonFile(configFile); |
| 814 | if (!jsonFile.good()) |
| 815 | { |
| 816 | log<level::ERR>("JSON file not found"); |
| 817 | return nullptr; |
| 818 | } |
| 819 | |
| 820 | Json data = nullptr; |
| 821 | try |
| 822 | { |
| 823 | data = Json::parse(jsonFile, nullptr, false); |
| 824 | } |
| 825 | catch (Json::parse_error& e) |
| 826 | { |
| 827 | log<level::DEBUG>("Corrupted channel config.", |
| 828 | entry("MSG: %s", e.what())); |
| 829 | throw std::runtime_error("Corrupted channel config file"); |
| 830 | } |
| 831 | |
| 832 | return data; |
| 833 | } |
| 834 | |
| 835 | int ChannelConfig::writeJsonFile(const std::string& configFile, |
| 836 | const Json& jsonData) |
| 837 | { |
| 838 | std::ofstream jsonFile(configFile); |
| 839 | if (!jsonFile.good()) |
| 840 | { |
| 841 | log<level::ERR>("JSON file not found"); |
| 842 | return -EIO; |
| 843 | } |
| 844 | |
| 845 | // Write JSON to file |
| 846 | jsonFile << jsonData; |
| 847 | |
| 848 | jsonFile.flush(); |
| 849 | return 0; |
| 850 | } |
| 851 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 852 | void ChannelConfig::setDefaultChannelConfig(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 853 | const std::string& chName) |
| 854 | { |
| 855 | channelData[chNum].chName = chName; |
| 856 | channelData[chNum].chID = chNum; |
| 857 | channelData[chNum].isChValid = false; |
| 858 | channelData[chNum].activeSessCount = 0; |
| 859 | |
| 860 | channelData[chNum].chInfo.mediumType = defaultMediumType; |
| 861 | channelData[chNum].chInfo.protocolType = defaultProtocolType; |
| 862 | channelData[chNum].chInfo.sessionSupported = defaultSessionSupported; |
| 863 | channelData[chNum].chInfo.isIpmi = defaultIsIpmiState; |
| 864 | channelData[chNum].chInfo.authTypeSupported = defaultAuthType; |
| 865 | } |
| 866 | |
| 867 | int ChannelConfig::loadChannelConfig() |
| 868 | { |
| 869 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 870 | channelLock{*channelMutex}; |
| 871 | |
| 872 | Json data = readJsonFile(channelConfigDefaultFilename); |
Johnathan Mantey | e5c4f1d | 2018-12-10 16:24:26 -0800 | [diff] [blame^] | 873 | if (data.empty()) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 874 | { |
| 875 | log<level::DEBUG>("Error in opening IPMI Channel data file"); |
| 876 | return -EIO; |
| 877 | } |
| 878 | |
| 879 | try |
| 880 | { |
| 881 | // Fill in global structure |
| 882 | for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++) |
| 883 | { |
| 884 | std::fill(reinterpret_cast<uint8_t*>(&channelData[chNum]), |
| 885 | reinterpret_cast<uint8_t*>(&channelData[chNum]) + |
| 886 | sizeof(ChannelData), |
| 887 | 0); |
| 888 | std::string chKey = std::to_string(chNum); |
| 889 | Json jsonChData = data[chKey].get<Json>(); |
| 890 | if (jsonChData.is_null()) |
| 891 | { |
| 892 | log<level::WARNING>( |
| 893 | "Channel not configured so loading default.", |
| 894 | entry("CHANNEL_NUM:%d", chNum)); |
| 895 | // If user didn't want to configure specific channel (say |
| 896 | // reserved channel), then load that index with default values. |
| 897 | std::string chName(defaultChannelName); |
| 898 | setDefaultChannelConfig(chNum, chName); |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | std::string chName = jsonChData[nameString].get<std::string>(); |
| 903 | channelData[chNum].chName = chName; |
| 904 | channelData[chNum].chID = chNum; |
| 905 | channelData[chNum].isChValid = |
| 906 | jsonChData[isValidString].get<bool>(); |
| 907 | channelData[chNum].activeSessCount = |
| 908 | jsonChData.value(activeSessionsString, 0); |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 909 | channelData[chNum].maxTransferSize = |
| 910 | jsonChData.value(maxTransferSizeString, smallChannelSize); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 911 | Json jsonChInfo = jsonChData[channelInfoString].get<Json>(); |
| 912 | if (jsonChInfo.is_null()) |
| 913 | { |
| 914 | log<level::ERR>("Invalid/corrupted channel config file"); |
| 915 | return -EBADMSG; |
| 916 | } |
| 917 | else |
| 918 | { |
| 919 | std::string medTypeStr = |
| 920 | jsonChInfo[mediumTypeString].get<std::string>(); |
| 921 | channelData[chNum].chInfo.mediumType = static_cast<uint8_t>( |
| 922 | convertToMediumTypeIndex(medTypeStr)); |
| 923 | std::string protoTypeStr = |
| 924 | jsonChInfo[protocolTypeString].get<std::string>(); |
| 925 | channelData[chNum].chInfo.protocolType = |
| 926 | static_cast<uint8_t>( |
| 927 | convertToProtocolTypeIndex(protoTypeStr)); |
| 928 | std::string sessStr = |
| 929 | jsonChInfo[sessionSupportedString].get<std::string>(); |
| 930 | channelData[chNum].chInfo.sessionSupported = |
| 931 | static_cast<uint8_t>( |
| 932 | convertToSessionSupportIndex(sessStr)); |
| 933 | channelData[chNum].chInfo.isIpmi = |
| 934 | jsonChInfo[isIpmiString].get<bool>(); |
| 935 | channelData[chNum].chInfo.authTypeSupported = |
| 936 | defaultAuthType; |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | catch (const Json::exception& e) |
| 942 | { |
| 943 | log<level::DEBUG>("Json Exception caught.", entry("MSG:%s", e.what())); |
| 944 | return -EBADMSG; |
| 945 | } |
| 946 | catch (const std::invalid_argument& e) |
| 947 | { |
| 948 | log<level::ERR>("Corrupted config.", entry("MSG:%s", e.what())); |
| 949 | return -EBADMSG; |
| 950 | } |
| 951 | |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | int ChannelConfig::readChannelVolatileData() |
| 956 | { |
| 957 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 958 | channelLock{*channelMutex}; |
| 959 | |
| 960 | Json data = readJsonFile(channelVolatileDataFilename); |
| 961 | if (data == nullptr) |
| 962 | { |
| 963 | log<level::DEBUG>("Error in opening IPMI Channel data file"); |
| 964 | return -EIO; |
| 965 | } |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 966 | try |
| 967 | { |
| 968 | // Fill in global structure |
| 969 | for (auto it = data.begin(); it != data.end(); ++it) |
| 970 | { |
| 971 | std::string chKey = it.key(); |
| 972 | uint8_t chNum = std::stoi(chKey, nullptr, 10); |
| 973 | if ((chNum < 0) || (chNum > maxIpmiChannels)) |
| 974 | { |
| 975 | log<level::DEBUG>( |
| 976 | "Invalid channel access entry in config file"); |
| 977 | throw std::out_of_range("Out of range - channel number"); |
| 978 | } |
| 979 | Json jsonChData = it.value(); |
| 980 | if (!jsonChData.is_null()) |
| 981 | { |
| 982 | std::string accModeStr = |
| 983 | jsonChData[accessModeString].get<std::string>(); |
| 984 | channelData[chNum].chAccess.chVolatileData.accessMode = |
| 985 | static_cast<uint8_t>(convertToAccessModeIndex(accModeStr)); |
| 986 | channelData[chNum].chAccess.chVolatileData.userAuthDisabled = |
| 987 | jsonChData[userAuthDisabledString].get<bool>(); |
| 988 | channelData[chNum].chAccess.chVolatileData.perMsgAuthDisabled = |
| 989 | jsonChData[perMsgAuthDisabledString].get<bool>(); |
| 990 | channelData[chNum].chAccess.chVolatileData.alertingDisabled = |
| 991 | jsonChData[alertingDisabledString].get<bool>(); |
| 992 | std::string privStr = |
| 993 | jsonChData[privLimitString].get<std::string>(); |
| 994 | channelData[chNum].chAccess.chVolatileData.privLimit = |
| 995 | static_cast<uint8_t>(convertToPrivLimitIndex(privStr)); |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | log<level::ERR>( |
| 1000 | "Invalid/corrupted volatile channel access file", |
| 1001 | entry("FILE: %s", channelVolatileDataFilename)); |
| 1002 | throw std::runtime_error( |
| 1003 | "Corrupted volatile channel access file"); |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | catch (const Json::exception& e) |
| 1008 | { |
| 1009 | log<level::DEBUG>("Json Exception caught.", entry("MSG:%s", e.what())); |
| 1010 | throw std::runtime_error("Corrupted volatile channel access file"); |
| 1011 | } |
| 1012 | catch (const std::invalid_argument& e) |
| 1013 | { |
| 1014 | log<level::ERR>("Corrupted config.", entry("MSG:%s", e.what())); |
| 1015 | throw std::runtime_error("Corrupted volatile channel access file"); |
| 1016 | } |
| 1017 | |
| 1018 | // Update the timestamp |
| 1019 | voltFileLastUpdatedTime = getUpdatedFileTime(channelVolatileDataFilename); |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | int ChannelConfig::readChannelPersistData() |
| 1024 | { |
| 1025 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 1026 | channelLock{*channelMutex}; |
| 1027 | |
| 1028 | Json data = readJsonFile(channelNvDataFilename); |
| 1029 | if (data == nullptr) |
| 1030 | { |
| 1031 | log<level::DEBUG>("Error in opening IPMI Channel data file"); |
| 1032 | return -EIO; |
| 1033 | } |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 1034 | try |
| 1035 | { |
| 1036 | // Fill in global structure |
| 1037 | for (auto it = data.begin(); it != data.end(); ++it) |
| 1038 | { |
| 1039 | std::string chKey = it.key(); |
| 1040 | uint8_t chNum = std::stoi(chKey, nullptr, 10); |
| 1041 | if ((chNum < 0) || (chNum > maxIpmiChannels)) |
| 1042 | { |
| 1043 | log<level::DEBUG>( |
| 1044 | "Invalid channel access entry in config file"); |
| 1045 | throw std::out_of_range("Out of range - channel number"); |
| 1046 | } |
| 1047 | Json jsonChData = it.value(); |
| 1048 | if (!jsonChData.is_null()) |
| 1049 | { |
| 1050 | std::string accModeStr = |
| 1051 | jsonChData[accessModeString].get<std::string>(); |
| 1052 | channelData[chNum].chAccess.chNonVolatileData.accessMode = |
| 1053 | static_cast<uint8_t>(convertToAccessModeIndex(accModeStr)); |
| 1054 | channelData[chNum].chAccess.chNonVolatileData.userAuthDisabled = |
| 1055 | jsonChData[userAuthDisabledString].get<bool>(); |
| 1056 | channelData[chNum] |
| 1057 | .chAccess.chNonVolatileData.perMsgAuthDisabled = |
| 1058 | jsonChData[perMsgAuthDisabledString].get<bool>(); |
| 1059 | channelData[chNum].chAccess.chNonVolatileData.alertingDisabled = |
| 1060 | jsonChData[alertingDisabledString].get<bool>(); |
| 1061 | std::string privStr = |
| 1062 | jsonChData[privLimitString].get<std::string>(); |
| 1063 | channelData[chNum].chAccess.chNonVolatileData.privLimit = |
| 1064 | static_cast<uint8_t>(convertToPrivLimitIndex(privStr)); |
| 1065 | } |
| 1066 | else |
| 1067 | { |
| 1068 | log<level::ERR>("Invalid/corrupted nv channel access file", |
| 1069 | entry("FILE:%s", channelNvDataFilename)); |
| 1070 | throw std::runtime_error("Corrupted nv channel access file"); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | catch (const Json::exception& e) |
| 1075 | { |
| 1076 | log<level::DEBUG>("Json Exception caught.", entry("MSG:%s", e.what())); |
| 1077 | throw std::runtime_error("Corrupted nv channel access file"); |
| 1078 | } |
| 1079 | catch (const std::invalid_argument& e) |
| 1080 | { |
| 1081 | log<level::ERR>("Corrupted config.", entry("MSG: %s", e.what())); |
| 1082 | throw std::runtime_error("Corrupted nv channel access file"); |
| 1083 | } |
| 1084 | |
| 1085 | // Update the timestamp |
| 1086 | nvFileLastUpdatedTime = getUpdatedFileTime(channelNvDataFilename); |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | int ChannelConfig::writeChannelVolatileData() |
| 1091 | { |
| 1092 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 1093 | channelLock{*channelMutex}; |
| 1094 | Json outData; |
| 1095 | |
| 1096 | try |
| 1097 | { |
| 1098 | for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++) |
| 1099 | { |
| 1100 | if (getChannelSessionSupport(chNum) != EChannelSessSupported::none) |
| 1101 | { |
| 1102 | Json jsonObj; |
| 1103 | std::string chKey = std::to_string(chNum); |
| 1104 | std::string accModeStr = convertToAccessModeString( |
| 1105 | channelData[chNum].chAccess.chVolatileData.accessMode); |
| 1106 | jsonObj[accessModeString] = accModeStr; |
| 1107 | jsonObj[userAuthDisabledString] = |
| 1108 | channelData[chNum].chAccess.chVolatileData.userAuthDisabled; |
| 1109 | jsonObj[perMsgAuthDisabledString] = |
| 1110 | channelData[chNum] |
| 1111 | .chAccess.chVolatileData.perMsgAuthDisabled; |
| 1112 | jsonObj[alertingDisabledString] = |
| 1113 | channelData[chNum].chAccess.chVolatileData.alertingDisabled; |
| 1114 | std::string privStr = convertToPrivLimitString( |
| 1115 | channelData[chNum].chAccess.chVolatileData.privLimit); |
| 1116 | jsonObj[privLimitString] = privStr; |
| 1117 | |
| 1118 | outData[chKey] = jsonObj; |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | catch (const std::invalid_argument& e) |
| 1123 | { |
| 1124 | log<level::ERR>("Corrupted config.", entry("MSG: %s", e.what())); |
| 1125 | return -EINVAL; |
| 1126 | } |
| 1127 | |
| 1128 | if (writeJsonFile(channelVolatileDataFilename, outData) != 0) |
| 1129 | { |
| 1130 | log<level::DEBUG>("Error in write JSON data to file"); |
| 1131 | return -EIO; |
| 1132 | } |
| 1133 | |
| 1134 | // Update the timestamp |
| 1135 | voltFileLastUpdatedTime = getUpdatedFileTime(channelVolatileDataFilename); |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | int ChannelConfig::writeChannelPersistData() |
| 1140 | { |
| 1141 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 1142 | channelLock{*channelMutex}; |
| 1143 | Json outData; |
| 1144 | |
| 1145 | try |
| 1146 | { |
| 1147 | for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++) |
| 1148 | { |
| 1149 | if (getChannelSessionSupport(chNum) != EChannelSessSupported::none) |
| 1150 | { |
| 1151 | Json jsonObj; |
| 1152 | std::string chKey = std::to_string(chNum); |
| 1153 | std::string accModeStr = convertToAccessModeString( |
| 1154 | channelData[chNum].chAccess.chNonVolatileData.accessMode); |
| 1155 | jsonObj[accessModeString] = accModeStr; |
| 1156 | jsonObj[userAuthDisabledString] = |
| 1157 | channelData[chNum] |
| 1158 | .chAccess.chNonVolatileData.userAuthDisabled; |
| 1159 | jsonObj[perMsgAuthDisabledString] = |
| 1160 | channelData[chNum] |
| 1161 | .chAccess.chNonVolatileData.perMsgAuthDisabled; |
| 1162 | jsonObj[alertingDisabledString] = |
| 1163 | channelData[chNum] |
| 1164 | .chAccess.chNonVolatileData.alertingDisabled; |
| 1165 | std::string privStr = convertToPrivLimitString( |
| 1166 | channelData[chNum].chAccess.chNonVolatileData.privLimit); |
| 1167 | jsonObj[privLimitString] = privStr; |
| 1168 | |
| 1169 | outData[chKey] = jsonObj; |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | catch (const std::invalid_argument& e) |
| 1174 | { |
| 1175 | log<level::ERR>("Corrupted config.", entry("MSG: %s", e.what())); |
| 1176 | return -EINVAL; |
| 1177 | } |
| 1178 | |
| 1179 | if (writeJsonFile(channelNvDataFilename, outData) != 0) |
| 1180 | { |
| 1181 | log<level::DEBUG>("Error in write JSON data to file"); |
| 1182 | return -EIO; |
| 1183 | } |
| 1184 | |
| 1185 | // Update the timestamp |
| 1186 | nvFileLastUpdatedTime = getUpdatedFileTime(channelNvDataFilename); |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | int ChannelConfig::checkAndReloadNVData() |
| 1191 | { |
| 1192 | std::time_t updateTime = getUpdatedFileTime(channelNvDataFilename); |
| 1193 | int ret = 0; |
| 1194 | if (updateTime != nvFileLastUpdatedTime || updateTime == -EIO) |
| 1195 | { |
| 1196 | try |
| 1197 | { |
| 1198 | ret = readChannelPersistData(); |
| 1199 | } |
| 1200 | catch (const std::exception& e) |
| 1201 | { |
| 1202 | log<level::ERR>("Exception caught in readChannelPersistData.", |
| 1203 | entry("MSG=%s", e.what())); |
| 1204 | ret = -EIO; |
| 1205 | } |
| 1206 | } |
| 1207 | return ret; |
| 1208 | } |
| 1209 | |
| 1210 | int ChannelConfig::checkAndReloadVolatileData() |
| 1211 | { |
| 1212 | std::time_t updateTime = getUpdatedFileTime(channelVolatileDataFilename); |
| 1213 | int ret = 0; |
| 1214 | if (updateTime != voltFileLastUpdatedTime || updateTime == -EIO) |
| 1215 | { |
| 1216 | try |
| 1217 | { |
| 1218 | ret = readChannelVolatileData(); |
| 1219 | } |
| 1220 | catch (const std::exception& e) |
| 1221 | { |
| 1222 | log<level::ERR>("Exception caught in readChannelVolatileData.", |
| 1223 | entry("MSG=%s", e.what())); |
| 1224 | ret = -EIO; |
| 1225 | } |
| 1226 | } |
| 1227 | return ret; |
| 1228 | } |
| 1229 | |
Johnathan Mantey | f92261d | 2018-12-10 15:49:34 -0800 | [diff] [blame] | 1230 | int ChannelConfig::setDbusProperty(const std::string& service, |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1231 | const std::string& objPath, |
| 1232 | const std::string& interface, |
| 1233 | const std::string& property, |
| 1234 | const DbusVariant& value) |
| 1235 | { |
| 1236 | try |
| 1237 | { |
| 1238 | auto method = |
| 1239 | bus.new_method_call(service.c_str(), objPath.c_str(), |
| 1240 | "org.freedesktop.DBus.Properties", "Set"); |
| 1241 | |
| 1242 | method.append(interface, property, value); |
| 1243 | |
| 1244 | auto reply = bus.call(method); |
| 1245 | } |
| 1246 | catch (const sdbusplus::exception::SdBusError& e) |
| 1247 | { |
| 1248 | log<level::DEBUG>("set-property failed", |
| 1249 | entry("SERVICE:%s", service.c_str()), |
| 1250 | entry("OBJPATH:%s", objPath.c_str()), |
| 1251 | entry("INTERFACE:%s", interface.c_str()), |
| 1252 | entry("PROP:%s", property.c_str())); |
| 1253 | return -EIO; |
| 1254 | } |
| 1255 | |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
Johnathan Mantey | f92261d | 2018-12-10 15:49:34 -0800 | [diff] [blame] | 1259 | int ChannelConfig::getDbusProperty(const std::string& service, |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1260 | const std::string& objPath, |
| 1261 | const std::string& interface, |
| 1262 | const std::string& property, |
| 1263 | DbusVariant& value) |
| 1264 | { |
| 1265 | try |
| 1266 | { |
| 1267 | auto method = |
| 1268 | bus.new_method_call(service.c_str(), objPath.c_str(), |
| 1269 | "org.freedesktop.DBus.Properties", "Get"); |
| 1270 | |
| 1271 | method.append(interface, property); |
| 1272 | |
| 1273 | auto reply = bus.call(method); |
| 1274 | reply.read(value); |
| 1275 | } |
| 1276 | catch (const sdbusplus::exception::SdBusError& e) |
| 1277 | { |
| 1278 | log<level::DEBUG>("get-property failed", |
| 1279 | entry("SERVICE:%s", service.c_str()), |
| 1280 | entry("OBJPATH:%s", objPath.c_str()), |
| 1281 | entry("INTERFACE:%s", interface.c_str()), |
| 1282 | entry("PROP:%s", property.c_str())); |
| 1283 | return -EIO; |
| 1284 | } |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | int ChannelConfig::syncNetworkChannelConfig() |
| 1289 | { |
| 1290 | boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex> |
| 1291 | channelLock{*channelMutex}; |
| 1292 | bool isUpdated = false; |
| 1293 | for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++) |
| 1294 | { |
| 1295 | if (getChannelSessionSupport(chNum) != EChannelSessSupported::none) |
| 1296 | { |
| 1297 | std::string intfPrivStr; |
| 1298 | try |
| 1299 | { |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1300 | std::string networkIntfObj = |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 1301 | std::string(networkIntfObjectBasePath) + "/" + |
| 1302 | channelData[chNum].chName; |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1303 | DbusVariant variant; |
Johnathan Mantey | f92261d | 2018-12-10 15:49:34 -0800 | [diff] [blame] | 1304 | if (0 != getDbusProperty(networkIntfServiceName, networkIntfObj, |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1305 | networkChConfigIntfName, |
| 1306 | privilegePropertyString, variant)) |
| 1307 | { |
| 1308 | log<level::DEBUG>("Network interface does not exist", |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 1309 | entry("INTERFACE:%s", |
| 1310 | channelData[chNum].chName.c_str())); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1311 | continue; |
| 1312 | } |
William A. Kennington III | dfad486 | 2018-11-19 17:45:35 -0800 | [diff] [blame] | 1313 | intfPrivStr = variant_ns::get<std::string>(variant); |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1314 | } |
William A. Kennington III | dfad486 | 2018-11-19 17:45:35 -0800 | [diff] [blame] | 1315 | catch (const variant_ns::bad_variant_access& e) |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1316 | { |
| 1317 | log<level::DEBUG>( |
| 1318 | "exception: Network interface does not exist"); |
| 1319 | continue; |
| 1320 | } |
| 1321 | catch (const sdbusplus::exception::SdBusError& e) |
| 1322 | { |
| 1323 | log<level::DEBUG>( |
| 1324 | "exception: Network interface does not exist"); |
| 1325 | continue; |
| 1326 | } |
| 1327 | |
| 1328 | uint8_t intfPriv = |
| 1329 | static_cast<uint8_t>(convertToPrivLimitIndex(intfPrivStr)); |
| 1330 | if (channelData[chNum].chAccess.chNonVolatileData.privLimit != |
| 1331 | intfPriv) |
| 1332 | { |
| 1333 | isUpdated = true; |
| 1334 | channelData[chNum].chAccess.chNonVolatileData.privLimit = |
| 1335 | intfPriv; |
| 1336 | channelData[chNum].chAccess.chVolatileData.privLimit = intfPriv; |
| 1337 | } |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | if (isUpdated) |
| 1342 | { |
| 1343 | // Write persistent data to file |
| 1344 | if (writeChannelPersistData() != 0) |
| 1345 | { |
| 1346 | log<level::DEBUG>("Failed to update the persistent data file"); |
| 1347 | return -EIO; |
| 1348 | } |
| 1349 | // Write Volatile data to file |
| 1350 | if (writeChannelVolatileData() != 0) |
| 1351 | { |
| 1352 | log<level::DEBUG>("Failed to update the channel volatile data"); |
| 1353 | return -EIO; |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 1360 | void ChannelConfig::initChannelPersistData() |
| 1361 | { |
| 1362 | /* Always read the channel config */ |
| 1363 | if (loadChannelConfig() != 0) |
| 1364 | { |
| 1365 | log<level::ERR>("Failed to read channel config file"); |
| 1366 | throw std::ios_base::failure("Failed to load channel configuration"); |
| 1367 | } |
| 1368 | |
| 1369 | /* Populate the channel persist data */ |
| 1370 | if (readChannelPersistData() != 0) |
| 1371 | { |
| 1372 | // Copy default NV data to RW location |
| 1373 | std::experimental::filesystem::copy_file(channelAccessDefaultFilename, |
| 1374 | channelNvDataFilename); |
| 1375 | |
| 1376 | // Load the channel access NV data |
| 1377 | if (readChannelPersistData() != 0) |
| 1378 | { |
| 1379 | log<level::ERR>("Failed to read channel access NV data"); |
| 1380 | throw std::ios_base::failure( |
| 1381 | "Failed to read channel access NV configuration"); |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | // First check the volatile data file |
| 1386 | // If not present, load the default values |
| 1387 | if (readChannelVolatileData() != 0) |
| 1388 | { |
| 1389 | // Copy default volatile data to temporary location |
| 1390 | // NV file(channelNvDataFilename) must have created by now. |
| 1391 | std::experimental::filesystem::copy_file(channelNvDataFilename, |
| 1392 | channelVolatileDataFilename); |
| 1393 | |
| 1394 | // Load the channel access volatile data |
| 1395 | if (readChannelVolatileData() != 0) |
| 1396 | { |
| 1397 | log<level::ERR>("Failed to read channel access volatile data"); |
| 1398 | throw std::ios_base::failure( |
| 1399 | "Failed to read channel access volatile configuration"); |
| 1400 | } |
| 1401 | } |
AppaRao Puli | 9613ed7 | 2018-09-01 23:46:44 +0530 | [diff] [blame] | 1402 | |
| 1403 | // Synchronize the channel config(priv) with network channel |
| 1404 | // configuration(priv) over dbus |
| 1405 | if (syncNetworkChannelConfig() != 0) |
| 1406 | { |
| 1407 | log<level::ERR>( |
| 1408 | "Failed to synchronize data with network channel config over dbus"); |
| 1409 | throw std::ios_base::failure( |
| 1410 | "Failed to synchronize data with network channel config over dbus"); |
| 1411 | } |
| 1412 | |
| 1413 | log<level::DEBUG>("Successfully completed channel data initialization."); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 1414 | return; |
| 1415 | } |
| 1416 | |
| 1417 | } // namespace ipmi |