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