| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 3 | #include "dcmihandler.hpp" |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 5 | #include "user_channel/channel_layer.hpp" |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | |
| Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 7 | #include <ipmid/api.hpp> |
| Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 8 | #include <ipmid/utils.hpp> |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | #include <nlohmann/json.hpp> |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 10 | #include <phosphor-logging/elog-errors.hpp> |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 11 | #include <phosphor-logging/lg2.hpp> |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 12 | #include <sdbusplus/bus.hpp> |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Common/error.hpp> |
| Thang Tran | 55cbf55 | 2023-01-31 14:43:02 +0700 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Network/EthernetInterface/server.hpp> |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 15 | #include <xyz/openbmc_project/Sensor/Value/common.hpp> |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 16 | |
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 17 | #include <bitset> |
| 18 | #include <cmath> |
| 19 | #include <fstream> |
| 20 | #include <variant> |
| 21 | |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 22 | using namespace phosphor::logging; |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 23 | using sdbusplus::server::xyz::openbmc_project::network::EthernetInterface; |
| Thang Tran | 55cbf55 | 2023-01-31 14:43:02 +0700 | [diff] [blame] | 24 | |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 25 | using InternalFailure = |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 26 | sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
| Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 27 | |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 28 | using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value; |
| 29 | |
| George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 30 | void registerNetFnDcmiFunctions() __attribute__((constructor)); |
| Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 31 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 32 | constexpr auto pcapInterface = "xyz.openbmc_project.Control.Power.Cap"; |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 33 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 34 | constexpr auto powerCapProp = "PowerCap"; |
| 35 | constexpr auto powerCapEnableProp = "PowerCapEnable"; |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 36 | constexpr auto powerCapExceptActProp = "ExceptionAction"; |
| 37 | constexpr auto powerCapSamplPeriodProp = "SamplingPeriod"; |
| 38 | constexpr auto powerCapCorrectTimeProp = "CorrectionTime"; |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 39 | |
| 40 | using namespace phosphor::logging; |
| 41 | |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 42 | namespace dcmi |
| 43 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 44 | constexpr auto assetTagMaxOffset = 62; |
| 45 | constexpr auto assetTagMaxSize = 63; |
| 46 | constexpr auto maxBytes = 16; |
| 47 | constexpr size_t maxCtrlIdStrLen = 63; |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 48 | |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 49 | constexpr uint8_t parameterRevision = 2; |
| 50 | constexpr uint8_t specMajorVersion = 1; |
| 51 | constexpr uint8_t specMinorVersion = 5; |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 52 | constexpr uint8_t configParameterRevision = 1; |
| 53 | constexpr auto option12Mask = 0x01; |
| 54 | constexpr auto activateDhcpReply = 0x00; |
| 55 | constexpr uint8_t dhcpTiming1 = 0x04; // 4 sec |
| 56 | constexpr uint16_t dhcpTiming2 = 0x78; // 120 sec |
| 57 | constexpr uint16_t dhcpTiming3 = 0x40; // 60 sec |
| 58 | // When DHCP Option 12 is enabled the string "SendHostName=true" will be |
| 59 | // added into n/w configuration file and the parameter |
| 60 | // SendHostNameEnabled will set to true. |
| 61 | constexpr auto dhcpOpt12Enabled = "SendHostNameEnabled"; |
| 62 | |
| 63 | enum class DCMIConfigParameters : uint8_t |
| 64 | { |
| 65 | ActivateDHCP = 1, |
| 66 | DiscoveryConfig, |
| 67 | DHCPTiming1, |
| 68 | DHCPTiming2, |
| 69 | DHCPTiming3, |
| 70 | }; |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 71 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 72 | /* |
| 73 | * The list of Exception action options. Please refer to table 6-17 of DCMI |
| 74 | * specification version 1.5 for more information. |
| 75 | * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/dcmi-v1-5-rev-spec.pdf |
| 76 | */ |
| 77 | enum class ExceptActOptions : uint8_t |
| 78 | { |
| 79 | NoAction = 0x00, |
| 80 | HardPowerOff, |
| 81 | Oem02, |
| 82 | Oem03, |
| 83 | Oem04, |
| 84 | Oem05, |
| 85 | Oem06, |
| 86 | Oem07, |
| 87 | Oem08, |
| 88 | Oem09, |
| 89 | Oem0A, |
| 90 | Oem0B, |
| 91 | Oem0C, |
| 92 | Oem0D, |
| 93 | Oem0E, |
| 94 | Oem0F, |
| 95 | Oem10, |
| 96 | LogEventOnly, |
| 97 | }; |
| 98 | |
| 99 | /* |
| 100 | * The PDIs only supports NoAction/HardPowerOff/LogEventOnly/Oem options for |
| 101 | * exception action. |
| 102 | */ |
| 103 | namespace DbusExceptAct |
| 104 | { |
| 105 | constexpr auto noAction = |
| 106 | "xyz.openbmc_project.Control.Power.Cap.ExceptionActions.NoAction"; |
| 107 | constexpr auto hardPowerOff = |
| 108 | "xyz.openbmc_project.Control.Power.Cap.ExceptionActions.HardPowerOff"; |
| 109 | constexpr auto logEventOnly = |
| 110 | "xyz.openbmc_project.Control.Power.Cap.ExceptionActions.LogEventOnly"; |
| 111 | constexpr auto oem = |
| 112 | "xyz.openbmc_project.Control.Power.Cap.ExceptionActions.Oem"; |
| 113 | } // namespace DbusExceptAct |
| 114 | |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 115 | // Refer Table 6-14, DCMI Entity ID Extension, DCMI v1.5 spec |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 116 | static const std::map<uint8_t, std::string> entityIdToName{ |
| 117 | {0x40, "inlet"}, {0x37, "inlet"}, {0x41, "cpu"}, |
| 118 | {0x03, "cpu"}, {0x42, "baseboard"}, {0x07, "baseboard"}}; |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 119 | |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 120 | nlohmann::json parseJSONConfig(const std::string& configFile) |
| 121 | { |
| 122 | std::ifstream jsonFile(configFile); |
| 123 | if (!jsonFile.is_open()) |
| 124 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 125 | lg2::error("Temperature readings JSON file not found"); |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 126 | elog<InternalFailure>(); |
| 127 | } |
| 128 | |
| 129 | auto data = nlohmann::json::parse(jsonFile, nullptr, false); |
| 130 | if (data.is_discarded()) |
| 131 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 132 | lg2::error("Temperature readings JSON parser failure"); |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 133 | elog<InternalFailure>(); |
| 134 | } |
| 135 | |
| 136 | return data; |
| 137 | } |
| 138 | |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 139 | bool isDCMIPowerMgmtSupported() |
| 140 | { |
| Vernon Mauery | f4eb35d | 2023-07-27 11:08:49 -0700 | [diff] [blame] | 141 | static bool parsed = false; |
| 142 | static bool supported = false; |
| 143 | if (!parsed) |
| 144 | { |
| 145 | auto data = parseJSONConfig(gDCMICapabilitiesConfig); |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 146 | |
| Vernon Mauery | f4eb35d | 2023-07-27 11:08:49 -0700 | [diff] [blame] | 147 | supported = (gDCMIPowerMgmtSupported == |
| 148 | data.value(gDCMIPowerMgmtCapability, 0)); |
| 149 | } |
| 150 | return supported; |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 151 | } |
| 152 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 153 | std::optional<ipmi::DbusObjectInfo> getPCapObject(ipmi::Context::ptr& ctx) |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 154 | { |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 155 | static std::optional<ipmi::DbusObjectInfo> pcapObject = std::nullopt; |
| 156 | |
| 157 | if (pcapObject != std::nullopt) |
| 158 | { |
| 159 | return pcapObject; |
| 160 | } |
| 161 | |
| 162 | ipmi::DbusObjectInfo objectPath{}; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 163 | boost::system::error_code ec = |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 164 | ipmi::getDbusObject(ctx, pcapInterface, objectPath); |
| 165 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 166 | if (ec.value()) |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 167 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 168 | return std::nullopt; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 169 | } |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 170 | |
| 171 | pcapObject = objectPath; |
| 172 | |
| 173 | return pcapObject; |
| 174 | } |
| 175 | |
| 176 | std::optional<uint32_t> getPcap(ipmi::Context::ptr& ctx) |
| 177 | { |
| 178 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 179 | |
| 180 | if (pcapObject == std::nullopt) |
| 181 | { |
| 182 | return std::nullopt; |
| 183 | } |
| 184 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 185 | uint32_t pcap{}; |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 186 | boost::system::error_code ec = ipmi::getDbusProperty( |
| 187 | ctx, pcapObject.value().second.c_str(), |
| 188 | pcapObject.value().first.c_str(), pcapInterface, powerCapProp, pcap); |
| 189 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 190 | if (ec.value()) |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 191 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 192 | lg2::error("Error in getPcap prop: {ERROR}", "ERROR", ec.message()); |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 193 | elog<InternalFailure>(); |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 194 | return std::nullopt; |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 195 | } |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 196 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 197 | return pcap; |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 198 | } |
| 199 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 200 | std::optional<bool> getPcapEnabled(ipmi::Context::ptr& ctx) |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 201 | { |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 202 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 203 | |
| 204 | if (pcapObject == std::nullopt) |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 205 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 206 | return std::nullopt; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 207 | } |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 208 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 209 | bool pcapEnabled{}; |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 210 | boost::system::error_code ec = |
| 211 | ipmi::getDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 212 | pcapObject.value().first.c_str(), pcapInterface, |
| 213 | powerCapEnableProp, pcapEnabled); |
| 214 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 215 | if (ec.value()) |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 216 | { |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 217 | lg2::error("Error in getPcapEnabled prop: {ERROR}", "ERROR", |
| 218 | ec.message()); |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 219 | elog<InternalFailure>(); |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 220 | return std::nullopt; |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 221 | } |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 222 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 223 | return pcapEnabled; |
| Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 224 | } |
| Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 225 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 226 | std::optional<std::string> getPcapExceptAction(ipmi::Context::ptr& ctx) |
| 227 | { |
| 228 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 229 | |
| 230 | if (pcapObject == std::nullopt) |
| 231 | { |
| 232 | return std::nullopt; |
| 233 | } |
| 234 | |
| 235 | std::string exceptActStr{}; |
| 236 | |
| 237 | boost::system::error_code ec = |
| 238 | ipmi::getDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 239 | pcapObject.value().first.c_str(), pcapInterface, |
| 240 | powerCapExceptActProp, exceptActStr); |
| 241 | |
| 242 | if (ec.value()) |
| 243 | { |
| 244 | lg2::error("Error in getPcapExceptAction prop: {ERROR}", "ERROR", |
| 245 | ec.message()); |
| 246 | elog<InternalFailure>(); |
| 247 | return std::nullopt; |
| 248 | } |
| 249 | |
| 250 | return exceptActStr; |
| 251 | } |
| 252 | |
| 253 | std::optional<uint32_t> getPcapCorrectTime(ipmi::Context::ptr& ctx) |
| 254 | { |
| 255 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 256 | |
| 257 | if (pcapObject == std::nullopt) |
| 258 | { |
| 259 | return std::nullopt; |
| 260 | } |
| 261 | |
| 262 | uint64_t pcapCorrectTimeUs{}; |
| 263 | boost::system::error_code ec = |
| 264 | ipmi::getDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 265 | pcapObject.value().first.c_str(), pcapInterface, |
| 266 | powerCapCorrectTimeProp, pcapCorrectTimeUs); |
| 267 | if (ec.value()) |
| 268 | { |
| 269 | lg2::error("Error in getPcapCorrectTime prop: {ERROR}", "ERROR", |
| 270 | ec.message()); |
| 271 | elog<InternalFailure>(); |
| 272 | return std::nullopt; |
| 273 | } |
| 274 | |
| 275 | return (uint32_t)(std::chrono::duration_cast<std::chrono::milliseconds>( |
| 276 | std::chrono::microseconds(pcapCorrectTimeUs))) |
| 277 | .count(); |
| 278 | } |
| 279 | |
| 280 | std::optional<uint16_t> getPcapSamplPeriod(ipmi::Context::ptr& ctx) |
| 281 | { |
| 282 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 283 | |
| 284 | if (pcapObject == std::nullopt) |
| 285 | { |
| 286 | return std::nullopt; |
| 287 | } |
| 288 | |
| 289 | uint64_t pcapSamplPeriodUs{}; |
| 290 | boost::system::error_code ec = |
| 291 | ipmi::getDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 292 | pcapObject.value().first.c_str(), pcapInterface, |
| 293 | powerCapSamplPeriodProp, pcapSamplPeriodUs); |
| 294 | if (ec.value()) |
| 295 | { |
| 296 | lg2::error("Error in getPcapSamplPeriod prop: {ERROR}", "ERROR", |
| 297 | ec.message()); |
| 298 | elog<InternalFailure>(); |
| 299 | return std::nullopt; |
| 300 | } |
| 301 | |
| 302 | return (uint16_t)(std::chrono::duration_cast<std::chrono::seconds>( |
| 303 | std::chrono::microseconds(pcapSamplPeriodUs))) |
| 304 | .count(); |
| 305 | } |
| 306 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 307 | bool setPcap(ipmi::Context::ptr& ctx, const uint32_t powerCap) |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 308 | { |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 309 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 310 | |
| 311 | if (pcapObject == std::nullopt) |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 312 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 313 | return false; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 314 | } |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 315 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 316 | boost::system::error_code ec = |
| 317 | ipmi::setDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 318 | pcapObject.value().first.c_str(), pcapInterface, |
| 319 | powerCapProp, powerCap); |
| 320 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 321 | if (ec.value()) |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 322 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 323 | lg2::error("Error in setPcap property: {ERROR}", "ERROR", ec.message()); |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 324 | elog<InternalFailure>(); |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 325 | return false; |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 326 | } |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 327 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 328 | return true; |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 329 | } |
| 330 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 331 | bool setPcapEnable(ipmi::Context::ptr& ctx, bool enabled) |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 332 | { |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 333 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 334 | |
| 335 | if (pcapObject == std::nullopt) |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 336 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 337 | return false; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 338 | } |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 339 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 340 | boost::system::error_code ec = |
| 341 | ipmi::setDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 342 | pcapObject.value().first.c_str(), pcapInterface, |
| 343 | powerCapEnableProp, enabled); |
| 344 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 345 | if (ec.value()) |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 346 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 347 | lg2::error("Error in setPcapEnabled property: {ERROR}", "ERROR", |
| 348 | ec.message()); |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 349 | elog<InternalFailure>(); |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 350 | return false; |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 351 | } |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 352 | return true; |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 353 | } |
| 354 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 355 | bool setPcapExceptAction(ipmi::Context::ptr& ctx, |
| 356 | const std::string& pcapExceptAct) |
| 357 | { |
| 358 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 359 | |
| 360 | if (pcapObject == std::nullopt) |
| 361 | { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | boost::system::error_code ec = |
| 366 | ipmi::setDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 367 | pcapObject.value().first.c_str(), pcapInterface, |
| 368 | powerCapExceptActProp, pcapExceptAct); |
| 369 | if (ec.value()) |
| 370 | { |
| 371 | lg2::error("Error in setPcapExceptAction property: {ERROR}", "ERROR", |
| 372 | ec.message()); |
| 373 | elog<InternalFailure>(); |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | bool setPcapCorrectTime(ipmi::Context::ptr& ctx, uint32_t pcapCorrectTime) |
| 381 | { |
| 382 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 383 | |
| 384 | if (pcapObject == std::nullopt) |
| 385 | { |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Dbus is storing Correction time in microseconds unit. |
| 391 | * Therefore, we have to convert it from milisecond to microseconds. |
| 392 | */ |
| 393 | uint64_t pcapCorrectTimeUs = |
| 394 | (uint64_t)(std::chrono::duration_cast<std::chrono::microseconds>( |
| 395 | std::chrono::milliseconds(pcapCorrectTime))) |
| 396 | .count(); |
| 397 | boost::system::error_code ec = |
| 398 | ipmi::setDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 399 | pcapObject.value().first.c_str(), pcapInterface, |
| 400 | powerCapCorrectTimeProp, pcapCorrectTimeUs); |
| 401 | if (ec.value()) |
| 402 | { |
| 403 | lg2::error("Error in setPcapCorrectTime property: {ERROR}", "ERROR", |
| 404 | ec.message()); |
| 405 | elog<InternalFailure>(); |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | return true; |
| 410 | } |
| 411 | |
| 412 | bool setPcapSamplPeriod(ipmi::Context::ptr& ctx, uint16_t pcapSamplPeriod) |
| 413 | { |
| 414 | std::optional<ipmi::DbusObjectInfo> pcapObject = getPCapObject(ctx); |
| 415 | |
| 416 | if (pcapObject == std::nullopt) |
| 417 | { |
| 418 | return false; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Dbus is storing Sampling periodic in microseconds unit. |
| 423 | * Therefore, we have to convert it from seconds to microseconds unit. |
| 424 | */ |
| 425 | uint64_t pcapSamplPeriodUs = |
| 426 | (uint64_t)(std::chrono::duration_cast<std::chrono::microseconds>( |
| 427 | std::chrono::seconds(pcapSamplPeriod))) |
| 428 | .count(); |
| 429 | boost::system::error_code ec = |
| 430 | ipmi::setDbusProperty(ctx, pcapObject.value().second.c_str(), |
| 431 | pcapObject.value().first.c_str(), pcapInterface, |
| 432 | powerCapSamplPeriodProp, pcapSamplPeriodUs); |
| 433 | if (ec.value()) |
| 434 | { |
| 435 | lg2::error("Error in setPcapSamplPeriod property: {ERROR}", "ERROR", |
| 436 | ec.message()); |
| 437 | elog<InternalFailure>(); |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | return true; |
| 442 | } |
| 443 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 444 | std::optional<std::string> readAssetTag(ipmi::Context::ptr& ctx) |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 445 | { |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 446 | // Read the object tree with the inventory root to figure out the object |
| 447 | // that has implemented the Asset tag interface. |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 448 | ipmi::DbusObjectInfo objectInfo; |
| 449 | boost::system::error_code ec = getDbusObject( |
| 450 | ctx, dcmi::assetTagIntf, ipmi::sensor::inventoryRoot, "", objectInfo); |
| 451 | if (ec.value()) |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 452 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 453 | return std::nullopt; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 454 | } |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 455 | |
| 456 | std::string assetTag{}; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 457 | ec = |
| 458 | ipmi::getDbusProperty(ctx, objectInfo.second, objectInfo.first, |
| 459 | dcmi::assetTagIntf, dcmi::assetTagProp, assetTag); |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 460 | if (ec.value()) |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 461 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 462 | lg2::error("Error in reading asset tag: {ERROR}", "ERROR", |
| 463 | ec.message()); |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 464 | elog<InternalFailure>(); |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 465 | return std::nullopt; |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 466 | } |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 467 | |
| 468 | return assetTag; |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 469 | } |
| 470 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 471 | bool writeAssetTag(ipmi::Context::ptr& ctx, const std::string& assetTag) |
| Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 472 | { |
| Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 473 | // Read the object tree with the inventory root to figure out the object |
| 474 | // that has implemented the Asset tag interface. |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 475 | ipmi::DbusObjectInfo objectInfo; |
| 476 | boost::system::error_code ec = getDbusObject( |
| 477 | ctx, dcmi::assetTagIntf, ipmi::sensor::inventoryRoot, "", objectInfo); |
| 478 | if (ec.value()) |
| Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 479 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 480 | return false; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 481 | } |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 482 | |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 483 | ec = |
| 484 | ipmi::setDbusProperty(ctx, objectInfo.second, objectInfo.first, |
| 485 | dcmi::assetTagIntf, dcmi::assetTagProp, assetTag); |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 486 | if (ec.value()) |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 487 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 488 | lg2::error("Error in writing asset tag: {ERROR}", "ERROR", |
| 489 | ec.message()); |
| Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 490 | elog<InternalFailure>(); |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 491 | return false; |
| Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 492 | } |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 493 | return true; |
| Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 494 | } |
| 495 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 496 | std::optional<std::string> getHostName(ipmi::Context::ptr& ctx) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 497 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 498 | std::string service{}; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 499 | boost::system::error_code ec = |
| 500 | ipmi::getService(ctx, networkConfigIntf, networkConfigObj, service); |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 501 | if (ec.value()) |
| 502 | { |
| 503 | return std::nullopt; |
| 504 | } |
| 505 | std::string hostname{}; |
| 506 | ec = ipmi::getDbusProperty(ctx, service, networkConfigObj, |
| 507 | networkConfigIntf, hostNameProp, hostname); |
| 508 | if (ec.value()) |
| 509 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 510 | lg2::error("Error fetching hostname"); |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 511 | elog<InternalFailure>(); |
| 512 | return std::nullopt; |
| 513 | } |
| 514 | return hostname; |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 515 | } |
| 516 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 517 | std::optional<EthernetInterface::DHCPConf> getDHCPEnabled( |
| 518 | ipmi::Context::ptr& ctx) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 519 | { |
| Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 520 | auto ethdevice = ipmi::getChannelName(ethernetDefaultChannelNum); |
| Prithvi Pai | 1dd18d2 | 2025-09-19 14:27:03 +0530 | [diff] [blame] | 521 | if (ethdevice.empty()) |
| 522 | { |
| 523 | lg2::error("Channel name does not exist for channel {CHANNEL}", |
| 524 | "CHANNEL", ethernetDefaultChannelNum); |
| 525 | return std::nullopt; |
| 526 | } |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 527 | ipmi::DbusObjectInfo ethernetObj{}; |
| 528 | boost::system::error_code ec = ipmi::getDbusObject( |
| 529 | ctx, ethernetIntf, networkRoot, ethdevice, ethernetObj); |
| 530 | if (ec.value()) |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 531 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 532 | return std::nullopt; |
| 533 | } |
| 534 | std::string service{}; |
| 535 | ec = ipmi::getService(ctx, ethernetIntf, ethernetObj.first, service); |
| 536 | if (ec.value()) |
| 537 | { |
| 538 | return std::nullopt; |
| 539 | } |
| 540 | std::string dhcpVal{}; |
| 541 | ec = ipmi::getDbusProperty(ctx, service, ethernetObj.first, ethernetIntf, |
| 542 | "DHCPEnabled", dhcpVal); |
| 543 | if (ec.value()) |
| 544 | { |
| 545 | return std::nullopt; |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 546 | } |
| 547 | |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 548 | return EthernetInterface::convertDHCPConfFromString(dhcpVal); |
| 549 | } |
| 550 | |
| 551 | std::optional<bool> getDHCPOption(ipmi::Context::ptr& ctx, |
| 552 | const std::string& prop) |
| 553 | { |
| George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 554 | ipmi::ObjectTree objectTree; |
| 555 | if (ipmi::getAllDbusObjects(ctx, networkRoot, dhcpIntf, objectTree)) |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 556 | { |
| 557 | return std::nullopt; |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 558 | } |
| 559 | |
| George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 560 | for (const auto& [path, serviceMap] : objectTree) |
| 561 | { |
| 562 | for (const auto& [service, object] : serviceMap) |
| 563 | { |
| 564 | bool value{}; |
| 565 | if (ipmi::getDbusProperty(ctx, service, path, dhcpIntf, prop, |
| 566 | value)) |
| 567 | { |
| 568 | return std::nullopt; |
| 569 | } |
| 570 | |
| 571 | if (value) |
| 572 | { |
| 573 | return true; |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | return false; |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | bool setDHCPOption(ipmi::Context::ptr& ctx, std::string prop, bool value) |
| 582 | { |
| George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 583 | ipmi::ObjectTree objectTree; |
| 584 | if (ipmi::getAllDbusObjects(ctx, networkRoot, dhcpIntf, objectTree)) |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 585 | { |
| George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 586 | return false; |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 587 | } |
| George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 588 | |
| 589 | for (const auto& [path, serviceMap] : objectTree) |
| 590 | { |
| 591 | for (const auto& [service, object] : serviceMap) |
| 592 | { |
| 593 | if (ipmi::setDbusProperty(ctx, service, path, dhcpIntf, prop, |
| 594 | value)) |
| 595 | { |
| 596 | return false; |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | return true; |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 602 | } |
| 603 | |
| Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 604 | } // namespace dcmi |
| Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 605 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 606 | ipmi::RspType<uint16_t, // reserved |
| 607 | uint8_t, // exception actions |
| 608 | uint16_t, // power limit requested in watts |
| 609 | uint32_t, // correction time in milliseconds |
| 610 | uint16_t, // reserved |
| 611 | uint16_t // statistics sampling period in seconds |
| 612 | > |
| 613 | getPowerLimit(ipmi::Context::ptr ctx, uint16_t reserved) |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 614 | { |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 615 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 616 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 617 | return ipmi::responseInvalidCommand(); |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 618 | } |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 619 | if (reserved) |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 620 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 621 | return ipmi::responseInvalidFieldRequest(); |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 622 | } |
| 623 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 624 | std::optional<uint16_t> pcapValue = dcmi::getPcap(ctx); |
| 625 | std::optional<bool> pcapEnable = dcmi::getPcapEnabled(ctx); |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 626 | std::optional<uint32_t> pcapCorrectTime = dcmi::getPcapCorrectTime(ctx); |
| 627 | std::optional<uint16_t> pcapSamplPeriod = dcmi::getPcapSamplPeriod(ctx); |
| 628 | std::optional<std::string> pcapExceptAct = dcmi::getPcapExceptAction(ctx); |
| 629 | |
| 630 | if (!pcapValue || !pcapEnable || !pcapCorrectTime || !pcapSamplPeriod || |
| 631 | !pcapExceptAct) |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 632 | { |
| 633 | return ipmi::responseUnspecifiedError(); |
| 634 | } |
| 635 | |
| 636 | constexpr uint16_t reserved1{}; |
| 637 | constexpr uint16_t reserved2{}; |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 638 | uint8_t exception; |
| 639 | |
| 640 | std::string exceptAct = pcapExceptAct.value(); |
| 641 | |
| 642 | if (exceptAct == dcmi::DbusExceptAct::noAction) |
| 643 | { |
| 644 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::NoAction); |
| 645 | } |
| 646 | else if (exceptAct == dcmi::DbusExceptAct::hardPowerOff) |
| 647 | { |
| 648 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::HardPowerOff); |
| 649 | } |
| 650 | else if (exceptAct == dcmi::DbusExceptAct::logEventOnly) |
| 651 | { |
| 652 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::LogEventOnly); |
| 653 | } |
| 654 | else if (exceptAct == dcmi::DbusExceptAct::oem) |
| 655 | { |
| 656 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::Oem02); |
| 657 | } |
| 658 | else |
| 659 | { |
| 660 | return ipmi::responseUnspecifiedError(); |
| 661 | } |
| 662 | |
| 663 | if (!pcapEnable.value()) |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 664 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 665 | constexpr ipmi::Cc responseNoPowerLimitSet = 0x80; |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 666 | return ipmi::response(responseNoPowerLimitSet, reserved1, exception, |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 667 | pcapValue.value(), pcapCorrectTime.value(), |
| 668 | reserved2, pcapSamplPeriod.value()); |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 669 | } |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 670 | |
| 671 | return ipmi::responseSuccess(reserved1, exception, pcapValue.value(), |
| 672 | pcapCorrectTime.value(), reserved2, |
| 673 | pcapSamplPeriod.value()); |
| Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 674 | } |
| 675 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 676 | ipmi::RspType<> setPowerLimit(ipmi::Context::ptr& ctx, uint16_t reserved1, |
| Thang Tran | fd9c361 | 2023-09-20 11:16:59 +0700 | [diff] [blame] | 677 | uint8_t reserved2, uint8_t exceptionAction, |
| 678 | uint16_t powerLimit, uint32_t correctionTime, |
| 679 | uint16_t reserved3, uint16_t statsPeriod) |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 680 | { |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 681 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 682 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 683 | lg2::error("DCMI Power management is unsupported!"); |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 684 | return ipmi::responseInvalidCommand(); |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 685 | } |
| 686 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 687 | if (reserved1 || reserved2 || reserved3) |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 688 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 689 | return ipmi::responseInvalidFieldRequest(); |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 690 | } |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 691 | |
| 692 | if (!dcmi::setPcap(ctx, powerLimit)) |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 693 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 694 | return ipmi::responseUnspecifiedError(); |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 695 | } |
| 696 | |
| Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 697 | /* |
| 698 | * As defined in table 6-18 of DCMI specification version 1.5. |
| 699 | * The Exception action value is mapped as below |
| 700 | * 00h - No Action |
| 701 | * 01h - Hard Power Off system and log events to SEL |
| 702 | * 02h - 10h OEM defined actions |
| 703 | * 11h - Log event to SEL only |
| 704 | * 12h-FFh Reserved |
| 705 | */ |
| 706 | if (exceptionAction >= 0x12) |
| 707 | { |
| 708 | return ipmi::responseUnspecifiedError(); |
| 709 | } |
| 710 | |
| 711 | std::string exceptActStr; |
| 712 | |
| 713 | switch (static_cast<dcmi::ExceptActOptions>(exceptionAction)) |
| 714 | { |
| 715 | case dcmi::ExceptActOptions::NoAction: |
| 716 | { |
| 717 | exceptActStr = dcmi::DbusExceptAct::noAction; |
| 718 | break; |
| 719 | } |
| 720 | case dcmi::ExceptActOptions::HardPowerOff: |
| 721 | { |
| 722 | exceptActStr = dcmi::DbusExceptAct::hardPowerOff; |
| 723 | break; |
| 724 | } |
| 725 | case dcmi::ExceptActOptions::LogEventOnly: |
| 726 | { |
| 727 | exceptActStr = dcmi::DbusExceptAct::logEventOnly; |
| 728 | break; |
| 729 | } |
| 730 | default: |
| 731 | { |
| 732 | exceptActStr = dcmi::DbusExceptAct::oem; |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | if (!dcmi::setPcapExceptAction(ctx, exceptActStr)) |
| 738 | { |
| 739 | return ipmi::responseUnspecifiedError(); |
| 740 | } |
| 741 | |
| 742 | if (!dcmi::setPcapCorrectTime(ctx, correctionTime)) |
| 743 | { |
| 744 | return ipmi::responseUnspecifiedError(); |
| 745 | } |
| 746 | |
| 747 | if (!dcmi::setPcapSamplPeriod(ctx, statsPeriod)) |
| 748 | { |
| 749 | return ipmi::responseUnspecifiedError(); |
| 750 | } |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 751 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 752 | return ipmi::responseSuccess(); |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 753 | } |
| 754 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 755 | ipmi::RspType<> applyPowerLimit(ipmi::Context::ptr& ctx, bool enabled, |
| 756 | uint7_t reserved1, uint16_t reserved2) |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 757 | { |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 758 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 759 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 760 | lg2::error("DCMI Power management is unsupported!"); |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 761 | return ipmi::responseInvalidCommand(); |
| 762 | } |
| 763 | if (reserved1 || reserved2) |
| 764 | { |
| 765 | return ipmi::responseInvalidFieldRequest(); |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 766 | } |
| 767 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 768 | if (!dcmi::setPcapEnable(ctx, enabled)) |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 769 | { |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 770 | return ipmi::responseUnspecifiedError(); |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 771 | } |
| 772 | |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 773 | lg2::info("Set Power Cap Enable: {POWERCAPENABLE}", "POWERCAPENABLE", |
| 774 | enabled); |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 775 | |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 776 | return ipmi::responseSuccess(); |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 777 | } |
| 778 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 779 | ipmi::RspType<uint8_t, // total tag length |
| 780 | std::vector<char> // tag data |
| 781 | > |
| 782 | getAssetTag(ipmi::Context::ptr& ctx, uint8_t offset, uint8_t count) |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 783 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 784 | // Verify offset to read and number of bytes to read are not exceeding |
| 785 | // the range. |
| 786 | if ((offset > dcmi::assetTagMaxOffset) || (count > dcmi::maxBytes) || |
| 787 | ((offset + count) > dcmi::assetTagMaxSize)) |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 788 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 789 | return ipmi::responseParmOutOfRange(); |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 790 | } |
| 791 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 792 | std::optional<std::string> assetTagResp = dcmi::readAssetTag(ctx); |
| 793 | if (!assetTagResp) |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 794 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 795 | return ipmi::responseUnspecifiedError(); |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 796 | } |
| 797 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 798 | std::string& assetTag = assetTagResp.value(); |
| 799 | // If the asset tag is longer than 63 bytes, restrict it to 63 bytes to |
| 800 | // suit Get Asset Tag command. |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 801 | if (assetTag.size() > dcmi::assetTagMaxSize) |
| 802 | { |
| 803 | assetTag.resize(dcmi::assetTagMaxSize); |
| 804 | } |
| 805 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 806 | if (offset >= assetTag.size()) |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 807 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 808 | return ipmi::responseParmOutOfRange(); |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 809 | } |
| 810 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 811 | // silently truncate reads beyond the end of assetTag |
| 812 | if ((offset + count) >= assetTag.size()) |
| 813 | { |
| 814 | count = assetTag.size() - offset; |
| 815 | } |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 816 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 817 | auto totalTagSize = static_cast<uint8_t>(assetTag.size()); |
| 818 | std::vector<char> data{assetTag.begin() + offset, |
| 819 | assetTag.begin() + offset + count}; |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 820 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 821 | return ipmi::responseSuccess(totalTagSize, data); |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 822 | } |
| 823 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 824 | ipmi::RspType<uint8_t // new asset tag length |
| 825 | > |
| 826 | setAssetTag(ipmi::Context::ptr& ctx, uint8_t offset, uint8_t count, |
| 827 | const std::vector<char>& data) |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 828 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 829 | // Verify offset to read and number of bytes to read are not exceeding |
| 830 | // the range. |
| 831 | if ((offset > dcmi::assetTagMaxOffset) || (count > dcmi::maxBytes) || |
| 832 | ((offset + count) > dcmi::assetTagMaxSize)) |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 833 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 834 | return ipmi::responseParmOutOfRange(); |
| 835 | } |
| 836 | if (data.size() != count) |
| 837 | { |
| 838 | return ipmi::responseReqDataLenInvalid(); |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 839 | } |
| 840 | |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 841 | std::optional<std::string> assetTagResp = dcmi::readAssetTag(ctx); |
| 842 | if (!assetTagResp) |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 843 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 844 | return ipmi::responseUnspecifiedError(); |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 845 | } |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 846 | |
| 847 | std::string& assetTag = assetTagResp.value(); |
| 848 | |
| 849 | if (offset > assetTag.size()) |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 850 | { |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 851 | return ipmi::responseParmOutOfRange(); |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 852 | } |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 853 | |
| 854 | // operation is to truncate at offset and append new data |
| 855 | assetTag.resize(offset); |
| 856 | assetTag.append(data.begin(), data.end()); |
| 857 | |
| 858 | if (!dcmi::writeAssetTag(ctx, assetTag)) |
| 859 | { |
| 860 | return ipmi::responseUnspecifiedError(); |
| 861 | } |
| 862 | |
| 863 | auto totalTagSize = static_cast<uint8_t>(assetTag.size()); |
| 864 | return ipmi::responseSuccess(totalTagSize); |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 865 | } |
| 866 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 867 | ipmi::RspType<uint8_t, // length |
| 868 | std::vector<char> // data |
| 869 | > |
| 870 | getMgmntCtrlIdStr(ipmi::Context::ptr& ctx, uint8_t offset, uint8_t count) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 871 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 872 | if (count > dcmi::maxBytes || offset + count > dcmi::maxCtrlIdStrLen) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 873 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 874 | return ipmi::responseParmOutOfRange(); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 875 | } |
| 876 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 877 | std::optional<std::string> hostnameResp = dcmi::getHostName(ctx); |
| 878 | if (!hostnameResp) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 879 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 880 | return ipmi::responseUnspecifiedError(); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 881 | } |
| 882 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 883 | std::string& hostname = hostnameResp.value(); |
| 884 | // If the id string is longer than 63 bytes, restrict it to 63 bytes to |
| 885 | // suit set management ctrl str command. |
| 886 | if (hostname.size() > dcmi::maxCtrlIdStrLen) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 887 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 888 | hostname.resize(dcmi::maxCtrlIdStrLen); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 889 | } |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 890 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 891 | if (offset >= hostname.size()) |
| 892 | { |
| 893 | return ipmi::responseParmOutOfRange(); |
| 894 | } |
| 895 | |
| 896 | // silently truncate reads beyond the end of hostname |
| 897 | if ((offset + count) >= hostname.size()) |
| 898 | { |
| 899 | count = hostname.size() - offset; |
| 900 | } |
| 901 | |
| 902 | auto nameSize = static_cast<uint8_t>(hostname.size()); |
| 903 | std::vector<char> data{hostname.begin() + offset, |
| 904 | hostname.begin() + offset + count}; |
| 905 | |
| 906 | return ipmi::responseSuccess(nameSize, data); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 907 | } |
| 908 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 909 | ipmi::RspType<uint8_t> setMgmntCtrlIdStr(ipmi::Context::ptr& ctx, |
| 910 | uint8_t offset, uint8_t count, |
| 911 | std::vector<char> data) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 912 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 913 | if ((offset > dcmi::maxCtrlIdStrLen) || (count > dcmi::maxBytes) || |
| 914 | ((offset + count) > dcmi::maxCtrlIdStrLen)) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 915 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 916 | return ipmi::responseParmOutOfRange(); |
| 917 | } |
| 918 | if (data.size() != count) |
| 919 | { |
| 920 | return ipmi::responseReqDataLenInvalid(); |
| 921 | } |
| 922 | bool terminalWrite{data.back() == '\0'}; |
| 923 | if (terminalWrite) |
| 924 | { |
| 925 | // remove the null termination from the data (no need with std::string) |
| 926 | data.resize(count - 1); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 927 | } |
| 928 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 929 | static std::string hostname{}; |
| 930 | // read in the current value if not starting at offset 0 |
| 931 | if (hostname.size() == 0 && offset != 0) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 932 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 933 | /* read old ctrlIdStr */ |
| 934 | std::optional<std::string> hostnameResp = dcmi::getHostName(ctx); |
| 935 | if (!hostnameResp) |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 936 | { |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 937 | return ipmi::responseUnspecifiedError(); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 938 | } |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 939 | hostname = hostnameResp.value(); |
| 940 | hostname.resize(offset); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 941 | } |
| 942 | |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 943 | // operation is to truncate at offset and append new data |
| 944 | hostname.append(data.begin(), data.end()); |
| 945 | |
| 946 | // do the update if this is the last write |
| 947 | if (terminalWrite) |
| 948 | { |
| 949 | boost::system::error_code ec = ipmi::setDbusProperty( |
| 950 | ctx, dcmi::networkServiceName, dcmi::networkConfigObj, |
| 951 | dcmi::networkConfigIntf, dcmi::hostNameProp, hostname); |
| 952 | hostname.clear(); |
| 953 | if (ec.value()) |
| 954 | { |
| 955 | return ipmi::responseUnspecifiedError(); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | auto totalIdSize = static_cast<uint8_t>(offset + count); |
| 960 | return ipmi::responseSuccess(totalIdSize); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 961 | } |
| 962 | |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 963 | ipmi::RspType<ipmi::message::Payload> getDCMICapabilities(uint8_t parameter) |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 964 | { |
| Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 965 | std::ifstream dcmiCapFile(dcmi::gDCMICapabilitiesConfig); |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 966 | if (!dcmiCapFile.is_open()) |
| 967 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 968 | lg2::error("DCMI Capabilities file not found"); |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 969 | return ipmi::responseUnspecifiedError(); |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | auto data = nlohmann::json::parse(dcmiCapFile, nullptr, false); |
| 973 | if (data.is_discarded()) |
| 974 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 975 | lg2::error("DCMI Capabilities JSON parser failure"); |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 976 | return ipmi::responseUnspecifiedError(); |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 977 | } |
| 978 | |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 979 | constexpr bool reserved1{}; |
| 980 | constexpr uint5_t reserved5{}; |
| 981 | constexpr uint7_t reserved7{}; |
| 982 | constexpr uint8_t reserved8{}; |
| 983 | constexpr uint16_t reserved16{}; |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 984 | |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 985 | ipmi::message::Payload payload; |
| 986 | payload.pack(dcmi::specMajorVersion, dcmi::specMinorVersion, |
| 987 | dcmi::parameterRevision); |
| 988 | |
| 989 | enum class DCMICapParameters : uint8_t |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 990 | { |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 991 | SupportedDcmiCaps = 0x01, // Supported DCMI Capabilities |
| 992 | MandatoryPlatAttributes = 0x02, // Mandatory Platform Attributes |
| 993 | OptionalPlatAttributes = 0x03, // Optional Platform Attributes |
| 994 | ManageabilityAccessAttributes = 0x04, // Manageability Access Attributes |
| 995 | }; |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 996 | |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 997 | switch (static_cast<DCMICapParameters>(parameter)) |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 998 | { |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 999 | case DCMICapParameters::SupportedDcmiCaps: |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1000 | { |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1001 | bool powerManagement = data.value("PowerManagement", 0); |
| 1002 | bool oobSecondaryLan = data.value("OOBSecondaryLan", 0); |
| 1003 | bool serialTMode = data.value("SerialTMODE", 0); |
| 1004 | bool inBandSystemInterfaceChannel = |
| 1005 | data.value("InBandSystemInterfaceChannel", 0); |
| 1006 | payload.pack(reserved8, powerManagement, reserved7, |
| 1007 | inBandSystemInterfaceChannel, serialTMode, |
| 1008 | oobSecondaryLan, reserved5); |
| 1009 | break; |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1010 | } |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1011 | // Mandatory Platform Attributes |
| 1012 | case DCMICapParameters::MandatoryPlatAttributes: |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1013 | { |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1014 | bool selAutoRollOver = data.value("SELAutoRollOver", 0); |
| 1015 | bool flushEntireSELUponRollOver = |
| 1016 | data.value("FlushEntireSELUponRollOver", 0); |
| 1017 | bool recordLevelSELFlushUponRollOver = |
| 1018 | data.value("RecordLevelSELFlushUponRollOver", 0); |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1019 | uint12_t numberOfSELEntries = |
| 1020 | data.value("NumberOfSELEntries", 0xcac); |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1021 | uint8_t tempMonitoringSamplingFreq = |
| 1022 | data.value("TempMonitoringSamplingFreq", 0); |
| 1023 | payload.pack(numberOfSELEntries, reserved1, |
| 1024 | recordLevelSELFlushUponRollOver, |
| 1025 | flushEntireSELUponRollOver, selAutoRollOver, |
| 1026 | reserved16, tempMonitoringSamplingFreq); |
| 1027 | break; |
| 1028 | } |
| 1029 | // Optional Platform Attributes |
| 1030 | case DCMICapParameters::OptionalPlatAttributes: |
| 1031 | { |
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1032 | uint7_t powerMgmtDeviceTargetAddress = |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1033 | data.value("PowerMgmtDeviceSlaveAddress", 0); |
| 1034 | uint4_t bmcChannelNumber = data.value("BMCChannelNumber", 0); |
| 1035 | uint4_t deviceRivision = data.value("DeviceRivision", 0); |
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1036 | payload.pack(powerMgmtDeviceTargetAddress, reserved1, |
| 1037 | deviceRivision, bmcChannelNumber); |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | // Manageability Access Attributes |
| 1041 | case DCMICapParameters::ManageabilityAccessAttributes: |
| 1042 | { |
| 1043 | uint8_t mandatoryPrimaryLanOOBSupport = |
| 1044 | data.value("MandatoryPrimaryLanOOBSupport", 0xff); |
| 1045 | uint8_t optionalSecondaryLanOOBSupport = |
| 1046 | data.value("OptionalSecondaryLanOOBSupport", 0xff); |
| 1047 | uint8_t optionalSerialOOBMTMODECapability = |
| 1048 | data.value("OptionalSerialOOBMTMODECapability", 0xff); |
| 1049 | payload.pack(mandatoryPrimaryLanOOBSupport, |
| 1050 | optionalSecondaryLanOOBSupport, |
| 1051 | optionalSerialOOBMTMODECapability); |
| 1052 | break; |
| 1053 | } |
| 1054 | default: |
| 1055 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1056 | lg2::error("Invalid input parameter"); |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1057 | return ipmi::responseInvalidFieldRequest(); |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1061 | return ipmi::responseSuccess(payload); |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1062 | } |
| 1063 | |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1064 | namespace dcmi |
| 1065 | { |
| 1066 | namespace temp_readings |
| 1067 | { |
| 1068 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1069 | std::tuple<bool, bool, uint8_t> readTemp(ipmi::Context::ptr& ctx, |
| 1070 | const std::string& dbusService, |
| 1071 | const std::string& dbusPath) |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1072 | { |
| 1073 | // Read the temperature value from d-bus object. Need some conversion. |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1074 | // As per the interface xyz.openbmc_project.Sensor.Value, the |
| 1075 | // temperature is an double and in degrees C. It needs to be scaled by |
| 1076 | // using the formula Value * 10^Scale. The ipmi spec has the temperature |
| 1077 | // as a uint8_t, with a separate single bit for the sign. |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1078 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1079 | ipmi::PropertyMap result{}; |
| 1080 | boost::system::error_code ec = ipmi::getAllDbusProperties( |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1081 | ctx, dbusService, dbusPath, SensorValue::interface, result); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1082 | if (ec.value()) |
| 1083 | { |
| 1084 | return std::make_tuple(false, false, 0); |
| 1085 | } |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1086 | auto temperature = |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1087 | std::visit(ipmi::VariantToDoubleVisitor(), |
| 1088 | result.at(SensorValue::property_names::value)); |
| James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 1089 | double absTemp = std::abs(temperature); |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1090 | |
| James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 1091 | auto findFactor = result.find("Scale"); |
| 1092 | double factor = 0.0; |
| 1093 | if (findFactor != result.end()) |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1094 | { |
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 1095 | factor = std::visit(ipmi::VariantToDoubleVisitor(), findFactor->second); |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1096 | } |
| James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 1097 | double scale = std::pow(10, factor); |
| 1098 | |
| 1099 | auto tempDegrees = absTemp * scale; |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1100 | // Max absolute temp as per ipmi spec is 127. |
| 1101 | constexpr auto maxTemp = 127; |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1102 | if (tempDegrees > maxTemp) |
| 1103 | { |
| 1104 | tempDegrees = maxTemp; |
| 1105 | } |
| 1106 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1107 | return std::make_tuple(true, (temperature < 0), |
| 1108 | static_cast<uint8_t>(tempDegrees)); |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1109 | } |
| 1110 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1111 | std::tuple<std::vector<std::tuple<uint7_t, bool, uint8_t>>, uint8_t> read( |
| 1112 | ipmi::Context::ptr& ctx, const std::string& type, uint8_t instance, |
| 1113 | size_t count) |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1114 | { |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1115 | std::vector<std::tuple<uint7_t, bool, uint8_t>> response{}; |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1116 | |
| Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 1117 | auto data = parseJSONConfig(gDCMISensorsConfig); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1118 | static const std::vector<nlohmann::json> empty{}; |
| 1119 | std::vector<nlohmann::json> readings = data.value(type, empty); |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1120 | for (const auto& j : readings) |
| 1121 | { |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1122 | // Max of 8 response data sets |
| 1123 | if (response.size() == count) |
| 1124 | { |
| 1125 | break; |
| 1126 | } |
| 1127 | |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1128 | uint8_t instanceNum = j.value("instance", 0); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1129 | // Not in the instance range we're interested in |
| 1130 | if (instanceNum < instance) |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1131 | { |
| 1132 | continue; |
| 1133 | } |
| 1134 | |
| 1135 | std::string path = j.value("dbus", ""); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1136 | std::string service{}; |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1137 | boost::system::error_code ec = |
| 1138 | ipmi::getService(ctx, SensorValue::interface, path, service); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1139 | if (ec.value()) |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1140 | { |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1141 | // not found on dbus |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1142 | continue; |
| 1143 | } |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1144 | |
| 1145 | const auto& [ok, sign, temp] = readTemp(ctx, service, path); |
| 1146 | if (ok) |
| 1147 | { |
| 1148 | response.emplace_back(uint7_t{temp}, sign, instanceNum); |
| 1149 | } |
| Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1152 | auto totalInstances = |
| 1153 | static_cast<uint8_t>(std::min(readings.size(), maxInstances)); |
| 1154 | return std::make_tuple(response, totalInstances); |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1155 | } |
| 1156 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1157 | } // namespace temp_readings |
| 1158 | } // namespace dcmi |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1159 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1160 | ipmi::RspType<uint8_t, // total instances for entity id |
| 1161 | uint8_t, // number of instances in this reply |
| 1162 | std::vector< // zero or more of the following two bytes |
| 1163 | std::tuple<uint7_t, // temperature value |
| 1164 | bool, // sign bit |
| 1165 | uint8_t // entity instance |
| 1166 | >>> |
| 1167 | getTempReadings(ipmi::Context::ptr& ctx, uint8_t sensorType, |
| 1168 | uint8_t entityId, uint8_t entityInstance, |
| 1169 | uint8_t instanceStart) |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1170 | { |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1171 | auto it = dcmi::entityIdToName.find(entityId); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1172 | if (it == dcmi::entityIdToName.end()) |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1173 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1174 | lg2::error("Unknown Entity ID: {ENTITY_ID}", "ENTITY_ID", entityId); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1175 | return ipmi::responseInvalidFieldRequest(); |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1176 | } |
| 1177 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1178 | if (sensorType != dcmi::temperatureSensorType) |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1179 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1180 | lg2::error("Invalid sensor type: {SENSOR_TYPE}", "SENSOR_TYPE", |
| 1181 | sensorType); |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1182 | return ipmi::responseInvalidFieldRequest(); |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1183 | } |
| 1184 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1185 | uint8_t requestedRecords = (entityInstance == 0) ? dcmi::maxRecords : 1; |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1186 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1187 | // Read requested instances |
| 1188 | const auto& [temps, totalInstances] = dcmi::temp_readings::read( |
| 1189 | ctx, it->second, instanceStart, requestedRecords); |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1190 | |
| Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1191 | auto numInstances = static_cast<uint8_t>(temps.size()); |
| 1192 | |
| 1193 | return ipmi::responseSuccess(totalInstances, numInstances, temps); |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1194 | } |
| 1195 | |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1196 | ipmi::RspType<> setDCMIConfParams(ipmi::Context::ptr& ctx, uint8_t parameter, |
| 1197 | uint8_t setSelector, |
| 1198 | ipmi::message::Payload& payload) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1199 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1200 | if (setSelector) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1201 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1202 | return ipmi::responseInvalidFieldRequest(); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1203 | } |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1204 | // Take action based on the Parameter Selector |
| 1205 | switch (static_cast<dcmi::DCMIConfigParameters>(parameter)) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1206 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1207 | case dcmi::DCMIConfigParameters::ActivateDHCP: |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1208 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1209 | uint7_t reserved{}; |
| 1210 | bool activate{}; |
| 1211 | if (payload.unpack(activate, reserved) || !payload.fullyUnpacked()) |
| 1212 | { |
| 1213 | return ipmi::responseReqDataLenInvalid(); |
| 1214 | } |
| 1215 | if (reserved) |
| 1216 | { |
| 1217 | return ipmi::responseInvalidFieldRequest(); |
| 1218 | } |
| 1219 | std::optional<EthernetInterface::DHCPConf> dhcpEnabled = |
| 1220 | dcmi::getDHCPEnabled(ctx); |
| 1221 | if (!dhcpEnabled) |
| 1222 | { |
| 1223 | return ipmi::responseUnspecifiedError(); |
| 1224 | } |
| 1225 | if (activate && |
| 1226 | (dhcpEnabled.value() != EthernetInterface::DHCPConf::none)) |
| 1227 | { |
| 1228 | // When these conditions are met we have to trigger DHCP |
| 1229 | // protocol restart using the latest parameter settings, |
| 1230 | // but as per n/w manager design, each time when we |
| 1231 | // update n/w parameters, n/w service is restarted. So |
| 1232 | // we no need to take any action in this case. |
| 1233 | } |
| 1234 | break; |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1235 | } |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1236 | case dcmi::DCMIConfigParameters::DiscoveryConfig: |
| 1237 | { |
| 1238 | bool option12{}; |
| 1239 | uint6_t reserved1{}; |
| 1240 | bool randBackOff{}; |
| 1241 | if (payload.unpack(option12, reserved1, randBackOff) || |
| 1242 | !payload.fullyUnpacked()) |
| 1243 | { |
| 1244 | return ipmi::responseReqDataLenInvalid(); |
| 1245 | } |
| 1246 | // Systemd-networkd doesn't support Random Back off |
| 1247 | if (reserved1 || randBackOff) |
| 1248 | { |
| 1249 | return ipmi::responseInvalidFieldRequest(); |
| 1250 | } |
| 1251 | dcmi::setDHCPOption(ctx, dcmi::dhcpOpt12Enabled, option12); |
| 1252 | break; |
| 1253 | } |
| 1254 | // Systemd-networkd doesn't allow to configure DHCP timigs |
| 1255 | case dcmi::DCMIConfigParameters::DHCPTiming1: |
| 1256 | case dcmi::DCMIConfigParameters::DHCPTiming2: |
| 1257 | case dcmi::DCMIConfigParameters::DHCPTiming3: |
| 1258 | default: |
| 1259 | return ipmi::responseInvalidFieldRequest(); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1260 | } |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1261 | return ipmi::responseSuccess(); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1262 | } |
| 1263 | |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1264 | ipmi::RspType<ipmi::message::Payload> getDCMIConfParams( |
| 1265 | ipmi::Context::ptr& ctx, uint8_t parameter, uint8_t setSelector) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1266 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1267 | if (setSelector) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1268 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1269 | return ipmi::responseInvalidFieldRequest(); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1270 | } |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1271 | ipmi::message::Payload payload; |
| 1272 | payload.pack(dcmi::specMajorVersion, dcmi::specMinorVersion, |
| 1273 | dcmi::configParameterRevision); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1274 | |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1275 | // Take action based on the Parameter Selector |
| 1276 | switch (static_cast<dcmi::DCMIConfigParameters>(parameter)) |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1277 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1278 | case dcmi::DCMIConfigParameters::ActivateDHCP: |
| 1279 | payload.pack(dcmi::activateDhcpReply); |
| 1280 | break; |
| 1281 | case dcmi::DCMIConfigParameters::DiscoveryConfig: |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1282 | { |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1283 | uint8_t discovery{}; |
| 1284 | std::optional<bool> enabled = |
| 1285 | dcmi::getDHCPOption(ctx, dcmi::dhcpOpt12Enabled); |
| 1286 | if (!enabled.has_value()) |
| 1287 | { |
| 1288 | return ipmi::responseUnspecifiedError(); |
| 1289 | } |
| 1290 | if (enabled.value()) |
| 1291 | { |
| 1292 | discovery = dcmi::option12Mask; |
| 1293 | } |
| 1294 | payload.pack(discovery); |
| 1295 | break; |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1296 | } |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1297 | // Get below values from Systemd-networkd source code |
| 1298 | case dcmi::DCMIConfigParameters::DHCPTiming1: |
| 1299 | payload.pack(dcmi::dhcpTiming1); |
| 1300 | break; |
| 1301 | case dcmi::DCMIConfigParameters::DHCPTiming2: |
| 1302 | payload.pack(dcmi::dhcpTiming2); |
| 1303 | break; |
| 1304 | case dcmi::DCMIConfigParameters::DHCPTiming3: |
| 1305 | payload.pack(dcmi::dhcpTiming3); |
| 1306 | break; |
| 1307 | default: |
| 1308 | return ipmi::responseInvalidFieldRequest(); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1309 | } |
| 1310 | |
| Thang Tran | af762de | 2023-12-18 11:19:28 +0700 | [diff] [blame] | 1311 | return ipmi::responseSuccess(payload); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1312 | } |
| 1313 | |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1314 | static std::optional<uint16_t> readPower(ipmi::Context::ptr& ctx) |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1315 | { |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1316 | std::ifstream sensorFile(POWER_READING_SENSOR); |
| 1317 | std::string objectPath; |
| 1318 | if (!sensorFile.is_open()) |
| 1319 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1320 | lg2::error( |
| 1321 | "Power reading configuration file not found: {POWER_SENSOR_FILE}", |
| 1322 | "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR}); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1323 | return std::nullopt; |
| 1324 | } |
| 1325 | |
| 1326 | auto data = nlohmann::json::parse(sensorFile, nullptr, false); |
| 1327 | if (data.is_discarded()) |
| 1328 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1329 | lg2::error("Error in parsing configuration file: {POWER_SENSOR_FILE}", |
| 1330 | "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR}); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1331 | return std::nullopt; |
| 1332 | } |
| 1333 | |
| 1334 | objectPath = data.value("path", ""); |
| 1335 | if (objectPath.empty()) |
| 1336 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1337 | lg2::error( |
| 1338 | "Power sensor D-Bus object path is empty: {POWER_SENSOR_FILE}", |
| 1339 | "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR}); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1340 | return std::nullopt; |
| 1341 | } |
| 1342 | |
| 1343 | // Return default value if failed to read from D-Bus object |
| 1344 | std::string service{}; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1345 | boost::system::error_code ec = |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1346 | ipmi::getService(ctx, SensorValue::interface, objectPath, service); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1347 | if (ec.value()) |
| 1348 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1349 | lg2::error("Failed to fetch service for D-Bus object, " |
| 1350 | "object path: {OBJECT_PATH}, interface: {INTERFACE}", |
| 1351 | "OBJECT_PATH", objectPath, "INTERFACE", |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1352 | SensorValue::interface); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1353 | return std::nullopt; |
| 1354 | } |
| 1355 | |
| 1356 | // Read the sensor value and scale properties |
| 1357 | double value{}; |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1358 | ec = ipmi::getDbusProperty(ctx, service, objectPath, SensorValue::interface, |
| 1359 | SensorValue::property_names::value, value); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1360 | if (ec.value()) |
| 1361 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1362 | lg2::error("Failed to read power value from D-Bus object, " |
| 1363 | "object path: {OBJECT_PATH}, interface: {INTERFACE}", |
| 1364 | "OBJECT_PATH", objectPath, "INTERFACE", |
| Alexander Hansen | f365c7f | 2025-11-14 12:08:34 +0100 | [diff] [blame^] | 1365 | SensorValue::interface); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1366 | return std::nullopt; |
| 1367 | } |
| 1368 | auto power = static_cast<uint16_t>(value); |
| 1369 | return power; |
| 1370 | } |
| 1371 | |
| 1372 | ipmi::RspType<uint16_t, // current power |
| 1373 | uint16_t, // minimum power |
| 1374 | uint16_t, // maximum power |
| 1375 | uint16_t, // average power |
| 1376 | uint32_t, // timestamp |
| 1377 | uint32_t, // sample period ms |
| 1378 | uint6_t, // reserved |
| 1379 | bool, // power measurement active |
| 1380 | bool // reserved |
| 1381 | > |
| 1382 | getPowerReading(ipmi::Context::ptr& ctx, uint8_t mode, uint8_t attributes, |
| 1383 | uint8_t reserved) |
| 1384 | { |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 1385 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 1386 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1387 | lg2::error("DCMI Power management is unsupported!"); |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1388 | return ipmi::responseInvalidCommand(); |
| 1389 | } |
| 1390 | if (reserved) |
| 1391 | { |
| 1392 | return ipmi::responseInvalidFieldRequest(); |
| Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 1393 | } |
| 1394 | |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1395 | enum class PowerMode : uint8_t |
| 1396 | { |
| 1397 | SystemPowerStatistics = 1, |
| 1398 | EnhancedSystemPowerStatistics = 2, |
| 1399 | }; |
| Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1400 | |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1401 | if (static_cast<PowerMode>(mode) != PowerMode::SystemPowerStatistics) |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1402 | { |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1403 | return ipmi::responseInvalidFieldRequest(); |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1404 | } |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1405 | if (attributes) |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1406 | { |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1407 | return ipmi::responseInvalidFieldRequest(); |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1408 | } |
| Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1409 | |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1410 | std::optional<uint16_t> powerResp = readPower(ctx); |
| 1411 | if (!powerResp) |
| 1412 | { |
| 1413 | return ipmi::responseUnspecifiedError(); |
| 1414 | } |
| 1415 | auto& power = powerResp.value(); |
| 1416 | |
| Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1417 | // TODO: openbmc/openbmc#2819 |
| Gunnar Mills | 8466b79 | 2018-03-23 12:18:12 -0500 | [diff] [blame] | 1418 | // Minimum, Maximum, Average power, TimeFrame, TimeStamp, |
| Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1419 | // PowerReadingState readings need to be populated |
| 1420 | // after Telemetry changes. |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1421 | constexpr uint32_t samplePeriod = 1; |
| 1422 | constexpr uint6_t reserved1 = 0; |
| 1423 | constexpr bool measurementActive = true; |
| 1424 | constexpr bool reserved2 = false; |
| 1425 | auto timestamp = static_cast<uint32_t>(time(nullptr)); |
| 1426 | return ipmi::responseSuccess(power, power, power, power, timestamp, |
| 1427 | samplePeriod, reserved1, measurementActive, |
| 1428 | reserved2); |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1429 | } |
| 1430 | |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1431 | namespace dcmi |
| 1432 | { |
| 1433 | namespace sensor_info |
| 1434 | { |
| 1435 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1436 | std::tuple<std::vector<uint16_t>, uint8_t> read( |
| 1437 | const std::string& type, uint8_t instance, const nlohmann::json& config, |
| 1438 | uint8_t count) |
| Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1439 | { |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1440 | std::vector<uint16_t> responses{}; |
| Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1441 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1442 | static const std::vector<nlohmann::json> empty{}; |
| 1443 | std::vector<nlohmann::json> readings = config.value(type, empty); |
| 1444 | uint8_t totalInstances = std::min(readings.size(), maxInstances); |
| Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1445 | for (const auto& reading : readings) |
| 1446 | { |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1447 | // limit to requested count |
| 1448 | if (responses.size() == count) |
| 1449 | { |
| 1450 | break; |
| 1451 | } |
| 1452 | |
| Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1453 | uint8_t instanceNum = reading.value("instance", 0); |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1454 | // Not in the instance range we're interested in |
| 1455 | if (instanceNum < instance) |
| Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1456 | { |
| 1457 | continue; |
| 1458 | } |
| 1459 | |
| Thang Tran | 5ea83fa | 2023-10-16 14:37:56 +0700 | [diff] [blame] | 1460 | uint16_t recordId = reading.value("record_id", 0); |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1461 | responses.emplace_back(recordId); |
| Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1462 | } |
| 1463 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1464 | return std::make_tuple(responses, totalInstances); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | } // namespace sensor_info |
| 1468 | } // namespace dcmi |
| 1469 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1470 | ipmi::RspType<uint8_t, // total available instances |
| 1471 | uint8_t, // number of records in this response |
| 1472 | std::vector<uint16_t> // records |
| 1473 | > |
| 1474 | getSensorInfo(uint8_t sensorType, uint8_t entityId, uint8_t entityInstance, |
| 1475 | uint8_t instanceStart) |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1476 | { |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1477 | auto it = dcmi::entityIdToName.find(entityId); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1478 | if (it == dcmi::entityIdToName.end()) |
| 1479 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1480 | lg2::error("Unknown Entity ID: {ENTITY_ID}", "ENTITY_ID", entityId); |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1481 | return ipmi::responseInvalidFieldRequest(); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1482 | } |
| 1483 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1484 | if (sensorType != dcmi::temperatureSensorType) |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1485 | { |
| George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1486 | lg2::error("Invalid sensor type: {SENSOR_TYPE}", "SENSOR_TYPE", |
| 1487 | sensorType); |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1488 | return ipmi::responseInvalidFieldRequest(); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1489 | } |
| 1490 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1491 | nlohmann::json config = dcmi::parseJSONConfig(dcmi::gDCMISensorsConfig); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1492 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1493 | uint8_t requestedRecords = (entityInstance == 0) ? dcmi::maxRecords : 1; |
| 1494 | // Read requested instances |
| 1495 | const auto& [sensors, totalInstances] = dcmi::sensor_info::read( |
| 1496 | it->second, instanceStart, config, requestedRecords); |
| 1497 | uint8_t numRecords = sensors.size(); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1498 | |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1499 | return ipmi::responseSuccess(totalInstances, numRecords, sensors); |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1500 | } |
| 1501 | |
| George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 1502 | void registerNetFnDcmiFunctions() |
| Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 1503 | { |
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1504 | // <Get Power Limit> |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 1505 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1506 | ipmi::dcmi::cmdGetPowerLimit, ipmi::Privilege::User, |
| 1507 | getPowerLimit); |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 1508 | |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 1509 | // <Set Power Limit> |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 1510 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1511 | ipmi::dcmi::cmdSetPowerLimit, |
| 1512 | ipmi::Privilege::Operator, setPowerLimit); |
| Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 1513 | |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 1514 | // <Activate/Deactivate Power Limit> |
| Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 1515 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1516 | ipmi::dcmi::cmdActDeactivatePwrLimit, |
| 1517 | ipmi::Privilege::Operator, applyPowerLimit); |
| Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 1518 | |
| Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 1519 | // <Get Asset Tag> |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 1520 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1521 | ipmi::dcmi::cmdGetAssetTag, ipmi::Privilege::User, |
| 1522 | getAssetTag); |
| Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 1523 | |
| 1524 | // <Set Asset Tag> |
| Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 1525 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1526 | ipmi::dcmi::cmdSetAssetTag, ipmi::Privilege::Operator, |
| 1527 | setAssetTag); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1528 | |
| Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 1529 | // <Get Management Controller Identifier String> |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 1530 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1531 | ipmi::dcmi::cmdGetMgmtCntlrIdString, |
| 1532 | ipmi::Privilege::User, getMgmntCtrlIdStr); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1533 | |
| 1534 | // <Set Management Controller Identifier String> |
| Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 1535 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1536 | ipmi::dcmi::cmdSetMgmtCntlrIdString, |
| 1537 | ipmi::Privilege::Admin, setMgmntCtrlIdStr); |
| Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1538 | |
| Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1539 | // <Get DCMI capabilities> |
| Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1540 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1541 | ipmi::dcmi::cmdGetDcmiCapabilitiesInfo, |
| 1542 | ipmi::Privilege::User, getDCMICapabilities); |
| Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1543 | |
| Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1544 | // <Get Power Reading> |
| Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1545 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1546 | ipmi::dcmi::cmdGetPowerReading, ipmi::Privilege::User, |
| 1547 | getPowerReading); |
| 1548 | |
| adarshgrami | 042e9db | 2022-09-15 10:34:34 +0530 | [diff] [blame] | 1549 | // The Get sensor should get the senor details dynamically when |
| 1550 | // FEATURE_DYNAMIC_SENSORS is enabled. |
| 1551 | #ifndef FEATURE_DYNAMIC_SENSORS |
| Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1552 | // <Get Sensor Info> |
| Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1553 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1554 | ipmi::dcmi::cmdGetDcmiSensorInfo, |
| 1555 | ipmi::Privilege::Operator, getSensorInfo); |
| Thang Tran | 3dad826 | 2023-08-17 15:20:56 +0700 | [diff] [blame] | 1556 | |
| 1557 | // <Get Temperature Readings> |
| 1558 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1559 | ipmi::dcmi::cmdGetTemperatureReadings, |
| 1560 | ipmi::Privilege::User, getTempReadings); |
| adarshgrami | 042e9db | 2022-09-15 10:34:34 +0530 | [diff] [blame] | 1561 | #endif |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1562 | // <Get DCMI Configuration Parameters> |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1563 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1564 | ipmi::dcmi::cmdGetDcmiConfigParameters, |
| 1565 | ipmi::Privilege::User, getDCMIConfParams); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1566 | |
| 1567 | // <Set DCMI Configuration Parameters> |
| Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1568 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1569 | ipmi::dcmi::cmdSetDcmiConfigParameters, |
| 1570 | ipmi::Privilege::Admin, setDCMIConfParams); |
| Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1571 | |
| Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 1572 | return; |
| 1573 | } |