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