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); |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 520 | ipmi::DbusObjectInfo ethernetObj{}; |
| 521 | boost::system::error_code ec = ipmi::getDbusObject( |
| 522 | ctx, ethernetIntf, networkRoot, ethdevice, ethernetObj); |
| 523 | if (ec.value()) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 524 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 525 | return std::nullopt; |
| 526 | } |
| 527 | std::string service{}; |
| 528 | ec = ipmi::getService(ctx, ethernetIntf, ethernetObj.first, service); |
| 529 | if (ec.value()) |
| 530 | { |
| 531 | return std::nullopt; |
| 532 | } |
| 533 | std::string dhcpVal{}; |
| 534 | ec = ipmi::getDbusProperty(ctx, service, ethernetObj.first, ethernetIntf, |
| 535 | "DHCPEnabled", dhcpVal); |
| 536 | if (ec.value()) |
| 537 | { |
| 538 | return std::nullopt; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 539 | } |
| 540 | |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 541 | return EthernetInterface::convertDHCPConfFromString(dhcpVal); |
| 542 | } |
| 543 | |
| 544 | std::optional<bool> getDHCPOption(ipmi::Context::ptr& ctx, |
| 545 | const std::string& prop) |
| 546 | { |
George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 547 | ipmi::ObjectTree objectTree; |
| 548 | if (ipmi::getAllDbusObjects(ctx, networkRoot, dhcpIntf, objectTree)) |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 549 | { |
| 550 | return std::nullopt; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 551 | } |
| 552 | |
George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 553 | for (const auto& [path, serviceMap] : objectTree) |
| 554 | { |
| 555 | for (const auto& [service, object] : serviceMap) |
| 556 | { |
| 557 | bool value{}; |
| 558 | if (ipmi::getDbusProperty(ctx, service, path, dhcpIntf, prop, |
| 559 | value)) |
| 560 | { |
| 561 | return std::nullopt; |
| 562 | } |
| 563 | |
| 564 | if (value) |
| 565 | { |
| 566 | return true; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | return false; |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | bool setDHCPOption(ipmi::Context::ptr& ctx, std::string prop, bool value) |
| 575 | { |
George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 576 | ipmi::ObjectTree objectTree; |
| 577 | if (ipmi::getAllDbusObjects(ctx, networkRoot, dhcpIntf, objectTree)) |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 578 | { |
George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 579 | return false; |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 580 | } |
George Liu | cfd7fa8 | 2024-01-22 11:38:29 +0800 | [diff] [blame] | 581 | |
| 582 | for (const auto& [path, serviceMap] : objectTree) |
| 583 | { |
| 584 | for (const auto& [service, object] : serviceMap) |
| 585 | { |
| 586 | if (ipmi::setDbusProperty(ctx, service, path, dhcpIntf, prop, |
| 587 | value)) |
| 588 | { |
| 589 | return false; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | return true; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 595 | } |
| 596 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 597 | } // namespace dcmi |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 598 | |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 599 | ipmi::RspType<uint16_t, // reserved |
| 600 | uint8_t, // exception actions |
| 601 | uint16_t, // power limit requested in watts |
| 602 | uint32_t, // correction time in milliseconds |
| 603 | uint16_t, // reserved |
| 604 | uint16_t // statistics sampling period in seconds |
| 605 | > |
| 606 | getPowerLimit(ipmi::Context::ptr ctx, uint16_t reserved) |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 607 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 608 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 609 | { |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 610 | return ipmi::responseInvalidCommand(); |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 611 | } |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 612 | if (reserved) |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 613 | { |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 614 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 615 | } |
| 616 | |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 617 | std::optional<uint16_t> pcapValue = dcmi::getPcap(ctx); |
| 618 | std::optional<bool> pcapEnable = dcmi::getPcapEnabled(ctx); |
Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 619 | std::optional<uint32_t> pcapCorrectTime = dcmi::getPcapCorrectTime(ctx); |
| 620 | std::optional<uint16_t> pcapSamplPeriod = dcmi::getPcapSamplPeriod(ctx); |
| 621 | std::optional<std::string> pcapExceptAct = dcmi::getPcapExceptAction(ctx); |
| 622 | |
| 623 | if (!pcapValue || !pcapEnable || !pcapCorrectTime || !pcapSamplPeriod || |
| 624 | !pcapExceptAct) |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 625 | { |
| 626 | return ipmi::responseUnspecifiedError(); |
| 627 | } |
| 628 | |
| 629 | constexpr uint16_t reserved1{}; |
| 630 | constexpr uint16_t reserved2{}; |
Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 631 | uint8_t exception; |
| 632 | |
| 633 | std::string exceptAct = pcapExceptAct.value(); |
| 634 | |
| 635 | if (exceptAct == dcmi::DbusExceptAct::noAction) |
| 636 | { |
| 637 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::NoAction); |
| 638 | } |
| 639 | else if (exceptAct == dcmi::DbusExceptAct::hardPowerOff) |
| 640 | { |
| 641 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::HardPowerOff); |
| 642 | } |
| 643 | else if (exceptAct == dcmi::DbusExceptAct::logEventOnly) |
| 644 | { |
| 645 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::LogEventOnly); |
| 646 | } |
| 647 | else if (exceptAct == dcmi::DbusExceptAct::oem) |
| 648 | { |
| 649 | exception = static_cast<uint8_t>(dcmi::ExceptActOptions::Oem02); |
| 650 | } |
| 651 | else |
| 652 | { |
| 653 | return ipmi::responseUnspecifiedError(); |
| 654 | } |
| 655 | |
| 656 | if (!pcapEnable.value()) |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 657 | { |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 658 | constexpr ipmi::Cc responseNoPowerLimitSet = 0x80; |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 659 | return ipmi::response(responseNoPowerLimitSet, reserved1, exception, |
Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 660 | pcapValue.value(), pcapCorrectTime.value(), |
| 661 | reserved2, pcapSamplPeriod.value()); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 662 | } |
Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 663 | |
| 664 | return ipmi::responseSuccess(reserved1, exception, pcapValue.value(), |
| 665 | pcapCorrectTime.value(), reserved2, |
| 666 | pcapSamplPeriod.value()); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 667 | } |
| 668 | |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 669 | ipmi::RspType<> setPowerLimit(ipmi::Context::ptr& ctx, uint16_t reserved1, |
Thang Tran | fd9c361 | 2023-09-20 11:16:59 +0700 | [diff] [blame] | 670 | uint8_t reserved2, uint8_t exceptionAction, |
| 671 | uint16_t powerLimit, uint32_t correctionTime, |
| 672 | uint16_t reserved3, uint16_t statsPeriod) |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 673 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 674 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 675 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 676 | lg2::error("DCMI Power management is unsupported!"); |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 677 | return ipmi::responseInvalidCommand(); |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 678 | } |
| 679 | |
Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 680 | if (reserved1 || reserved2 || reserved3) |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 681 | { |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 682 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 683 | } |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 684 | |
| 685 | if (!dcmi::setPcap(ctx, powerLimit)) |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 686 | { |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 687 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 688 | } |
| 689 | |
Thang Tran | a95978d | 2025-06-04 10:39:15 +0700 | [diff] [blame] | 690 | /* |
| 691 | * As defined in table 6-18 of DCMI specification version 1.5. |
| 692 | * The Exception action value is mapped as below |
| 693 | * 00h - No Action |
| 694 | * 01h - Hard Power Off system and log events to SEL |
| 695 | * 02h - 10h OEM defined actions |
| 696 | * 11h - Log event to SEL only |
| 697 | * 12h-FFh Reserved |
| 698 | */ |
| 699 | if (exceptionAction >= 0x12) |
| 700 | { |
| 701 | return ipmi::responseUnspecifiedError(); |
| 702 | } |
| 703 | |
| 704 | std::string exceptActStr; |
| 705 | |
| 706 | switch (static_cast<dcmi::ExceptActOptions>(exceptionAction)) |
| 707 | { |
| 708 | case dcmi::ExceptActOptions::NoAction: |
| 709 | { |
| 710 | exceptActStr = dcmi::DbusExceptAct::noAction; |
| 711 | break; |
| 712 | } |
| 713 | case dcmi::ExceptActOptions::HardPowerOff: |
| 714 | { |
| 715 | exceptActStr = dcmi::DbusExceptAct::hardPowerOff; |
| 716 | break; |
| 717 | } |
| 718 | case dcmi::ExceptActOptions::LogEventOnly: |
| 719 | { |
| 720 | exceptActStr = dcmi::DbusExceptAct::logEventOnly; |
| 721 | break; |
| 722 | } |
| 723 | default: |
| 724 | { |
| 725 | exceptActStr = dcmi::DbusExceptAct::oem; |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | if (!dcmi::setPcapExceptAction(ctx, exceptActStr)) |
| 731 | { |
| 732 | return ipmi::responseUnspecifiedError(); |
| 733 | } |
| 734 | |
| 735 | if (!dcmi::setPcapCorrectTime(ctx, correctionTime)) |
| 736 | { |
| 737 | return ipmi::responseUnspecifiedError(); |
| 738 | } |
| 739 | |
| 740 | if (!dcmi::setPcapSamplPeriod(ctx, statsPeriod)) |
| 741 | { |
| 742 | return ipmi::responseUnspecifiedError(); |
| 743 | } |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 744 | |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 745 | return ipmi::responseSuccess(); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 746 | } |
| 747 | |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 748 | ipmi::RspType<> applyPowerLimit(ipmi::Context::ptr& ctx, bool enabled, |
| 749 | uint7_t reserved1, uint16_t reserved2) |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 750 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 751 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 752 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 753 | lg2::error("DCMI Power management is unsupported!"); |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 754 | return ipmi::responseInvalidCommand(); |
| 755 | } |
| 756 | if (reserved1 || reserved2) |
| 757 | { |
| 758 | return ipmi::responseInvalidFieldRequest(); |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 759 | } |
| 760 | |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 761 | if (!dcmi::setPcapEnable(ctx, enabled)) |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 762 | { |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 763 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 764 | } |
| 765 | |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 766 | lg2::info("Set Power Cap Enable: {POWERCAPENABLE}", "POWERCAPENABLE", |
| 767 | 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::responseSuccess(); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 770 | } |
| 771 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 772 | ipmi::RspType<uint8_t, // total tag length |
| 773 | std::vector<char> // tag data |
| 774 | > |
| 775 | getAssetTag(ipmi::Context::ptr& ctx, uint8_t offset, uint8_t count) |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 776 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 777 | // Verify offset to read and number of bytes to read are not exceeding |
| 778 | // the range. |
| 779 | if ((offset > dcmi::assetTagMaxOffset) || (count > dcmi::maxBytes) || |
| 780 | ((offset + count) > dcmi::assetTagMaxSize)) |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 781 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 782 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 783 | } |
| 784 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 785 | std::optional<std::string> assetTagResp = dcmi::readAssetTag(ctx); |
| 786 | if (!assetTagResp) |
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::responseUnspecifiedError(); |
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::string& assetTag = assetTagResp.value(); |
| 792 | // If the asset tag is longer than 63 bytes, restrict it to 63 bytes to |
| 793 | // suit Get Asset Tag command. |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 794 | if (assetTag.size() > dcmi::assetTagMaxSize) |
| 795 | { |
| 796 | assetTag.resize(dcmi::assetTagMaxSize); |
| 797 | } |
| 798 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 799 | if (offset >= assetTag.size()) |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 800 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 801 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 802 | } |
| 803 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 804 | // silently truncate reads beyond the end of assetTag |
| 805 | if ((offset + count) >= assetTag.size()) |
| 806 | { |
| 807 | count = assetTag.size() - offset; |
| 808 | } |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 809 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 810 | auto totalTagSize = static_cast<uint8_t>(assetTag.size()); |
| 811 | std::vector<char> data{assetTag.begin() + offset, |
| 812 | assetTag.begin() + offset + count}; |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 813 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 814 | return ipmi::responseSuccess(totalTagSize, data); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 815 | } |
| 816 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 817 | ipmi::RspType<uint8_t // new asset tag length |
| 818 | > |
| 819 | setAssetTag(ipmi::Context::ptr& ctx, uint8_t offset, uint8_t count, |
| 820 | const std::vector<char>& data) |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 821 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 822 | // Verify offset to read and number of bytes to read are not exceeding |
| 823 | // the range. |
| 824 | if ((offset > dcmi::assetTagMaxOffset) || (count > dcmi::maxBytes) || |
| 825 | ((offset + count) > dcmi::assetTagMaxSize)) |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 826 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 827 | return ipmi::responseParmOutOfRange(); |
| 828 | } |
| 829 | if (data.size() != count) |
| 830 | { |
| 831 | return ipmi::responseReqDataLenInvalid(); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 832 | } |
| 833 | |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 834 | std::optional<std::string> assetTagResp = dcmi::readAssetTag(ctx); |
| 835 | if (!assetTagResp) |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 836 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 837 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 838 | } |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 839 | |
| 840 | std::string& assetTag = assetTagResp.value(); |
| 841 | |
| 842 | if (offset > assetTag.size()) |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 843 | { |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 844 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 845 | } |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 846 | |
| 847 | // operation is to truncate at offset and append new data |
| 848 | assetTag.resize(offset); |
| 849 | assetTag.append(data.begin(), data.end()); |
| 850 | |
| 851 | if (!dcmi::writeAssetTag(ctx, assetTag)) |
| 852 | { |
| 853 | return ipmi::responseUnspecifiedError(); |
| 854 | } |
| 855 | |
| 856 | auto totalTagSize = static_cast<uint8_t>(assetTag.size()); |
| 857 | return ipmi::responseSuccess(totalTagSize); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 858 | } |
| 859 | |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 860 | ipmi::RspType<uint8_t, // length |
| 861 | std::vector<char> // data |
| 862 | > |
| 863 | getMgmntCtrlIdStr(ipmi::Context::ptr& ctx, uint8_t offset, uint8_t count) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 864 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 865 | if (count > dcmi::maxBytes || offset + count > dcmi::maxCtrlIdStrLen) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 866 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 867 | return ipmi::responseParmOutOfRange(); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 868 | } |
| 869 | |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 870 | std::optional<std::string> hostnameResp = dcmi::getHostName(ctx); |
| 871 | if (!hostnameResp) |
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::responseUnspecifiedError(); |
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::string& hostname = hostnameResp.value(); |
| 877 | // If the id string is longer than 63 bytes, restrict it to 63 bytes to |
| 878 | // suit set management ctrl str command. |
| 879 | if (hostname.size() > dcmi::maxCtrlIdStrLen) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 880 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 881 | hostname.resize(dcmi::maxCtrlIdStrLen); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 882 | } |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 883 | |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 884 | if (offset >= hostname.size()) |
| 885 | { |
| 886 | return ipmi::responseParmOutOfRange(); |
| 887 | } |
| 888 | |
| 889 | // silently truncate reads beyond the end of hostname |
| 890 | if ((offset + count) >= hostname.size()) |
| 891 | { |
| 892 | count = hostname.size() - offset; |
| 893 | } |
| 894 | |
| 895 | auto nameSize = static_cast<uint8_t>(hostname.size()); |
| 896 | std::vector<char> data{hostname.begin() + offset, |
| 897 | hostname.begin() + offset + count}; |
| 898 | |
| 899 | return ipmi::responseSuccess(nameSize, data); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 900 | } |
| 901 | |
Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 902 | ipmi::RspType<uint8_t> setMgmntCtrlIdStr(ipmi::Context::ptr& ctx, |
| 903 | uint8_t offset, uint8_t count, |
| 904 | std::vector<char> data) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 905 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 906 | if ((offset > dcmi::maxCtrlIdStrLen) || (count > dcmi::maxBytes) || |
| 907 | ((offset + count) > dcmi::maxCtrlIdStrLen)) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 908 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 909 | return ipmi::responseParmOutOfRange(); |
| 910 | } |
| 911 | if (data.size() != count) |
| 912 | { |
| 913 | return ipmi::responseReqDataLenInvalid(); |
| 914 | } |
| 915 | bool terminalWrite{data.back() == '\0'}; |
| 916 | if (terminalWrite) |
| 917 | { |
| 918 | // remove the null termination from the data (no need with std::string) |
| 919 | data.resize(count - 1); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 920 | } |
| 921 | |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 922 | static std::string hostname{}; |
| 923 | // read in the current value if not starting at offset 0 |
| 924 | if (hostname.size() == 0 && offset != 0) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 925 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 926 | /* read old ctrlIdStr */ |
| 927 | std::optional<std::string> hostnameResp = dcmi::getHostName(ctx); |
| 928 | if (!hostnameResp) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 929 | { |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 930 | return ipmi::responseUnspecifiedError(); |
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 | hostname = hostnameResp.value(); |
| 933 | hostname.resize(offset); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 934 | } |
| 935 | |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 936 | // operation is to truncate at offset and append new data |
| 937 | hostname.append(data.begin(), data.end()); |
| 938 | |
| 939 | // do the update if this is the last write |
| 940 | if (terminalWrite) |
| 941 | { |
| 942 | boost::system::error_code ec = ipmi::setDbusProperty( |
| 943 | ctx, dcmi::networkServiceName, dcmi::networkConfigObj, |
| 944 | dcmi::networkConfigIntf, dcmi::hostNameProp, hostname); |
| 945 | hostname.clear(); |
| 946 | if (ec.value()) |
| 947 | { |
| 948 | return ipmi::responseUnspecifiedError(); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | auto totalIdSize = static_cast<uint8_t>(offset + count); |
| 953 | return ipmi::responseSuccess(totalIdSize); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 954 | } |
| 955 | |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 956 | ipmi::RspType<ipmi::message::Payload> getDCMICapabilities(uint8_t parameter) |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 957 | { |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 958 | std::ifstream dcmiCapFile(dcmi::gDCMICapabilitiesConfig); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 959 | if (!dcmiCapFile.is_open()) |
| 960 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 961 | lg2::error("DCMI Capabilities file not found"); |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 962 | return ipmi::responseUnspecifiedError(); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | auto data = nlohmann::json::parse(dcmiCapFile, nullptr, false); |
| 966 | if (data.is_discarded()) |
| 967 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 968 | lg2::error("DCMI Capabilities JSON parser failure"); |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 969 | return ipmi::responseUnspecifiedError(); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 970 | } |
| 971 | |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 972 | constexpr bool reserved1{}; |
| 973 | constexpr uint5_t reserved5{}; |
| 974 | constexpr uint7_t reserved7{}; |
| 975 | constexpr uint8_t reserved8{}; |
| 976 | constexpr uint16_t reserved16{}; |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 977 | |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 978 | ipmi::message::Payload payload; |
| 979 | payload.pack(dcmi::specMajorVersion, dcmi::specMinorVersion, |
| 980 | dcmi::parameterRevision); |
| 981 | |
| 982 | enum class DCMICapParameters : uint8_t |
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 | SupportedDcmiCaps = 0x01, // Supported DCMI Capabilities |
| 985 | MandatoryPlatAttributes = 0x02, // Mandatory Platform Attributes |
| 986 | OptionalPlatAttributes = 0x03, // Optional Platform Attributes |
| 987 | ManageabilityAccessAttributes = 0x04, // Manageability Access Attributes |
| 988 | }; |
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 | switch (static_cast<DCMICapParameters>(parameter)) |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 991 | { |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 992 | case DCMICapParameters::SupportedDcmiCaps: |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 993 | { |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 994 | bool powerManagement = data.value("PowerManagement", 0); |
| 995 | bool oobSecondaryLan = data.value("OOBSecondaryLan", 0); |
| 996 | bool serialTMode = data.value("SerialTMODE", 0); |
| 997 | bool inBandSystemInterfaceChannel = |
| 998 | data.value("InBandSystemInterfaceChannel", 0); |
| 999 | payload.pack(reserved8, powerManagement, reserved7, |
| 1000 | inBandSystemInterfaceChannel, serialTMode, |
| 1001 | oobSecondaryLan, reserved5); |
| 1002 | break; |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1003 | } |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1004 | // Mandatory Platform Attributes |
| 1005 | case DCMICapParameters::MandatoryPlatAttributes: |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1006 | { |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1007 | bool selAutoRollOver = data.value("SELAutoRollOver", 0); |
| 1008 | bool flushEntireSELUponRollOver = |
| 1009 | data.value("FlushEntireSELUponRollOver", 0); |
| 1010 | bool recordLevelSELFlushUponRollOver = |
| 1011 | data.value("RecordLevelSELFlushUponRollOver", 0); |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1012 | uint12_t numberOfSELEntries = |
| 1013 | data.value("NumberOfSELEntries", 0xcac); |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1014 | uint8_t tempMonitoringSamplingFreq = |
| 1015 | data.value("TempMonitoringSamplingFreq", 0); |
| 1016 | payload.pack(numberOfSELEntries, reserved1, |
| 1017 | recordLevelSELFlushUponRollOver, |
| 1018 | flushEntireSELUponRollOver, selAutoRollOver, |
| 1019 | reserved16, tempMonitoringSamplingFreq); |
| 1020 | break; |
| 1021 | } |
| 1022 | // Optional Platform Attributes |
| 1023 | case DCMICapParameters::OptionalPlatAttributes: |
| 1024 | { |
Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1025 | uint7_t powerMgmtDeviceTargetAddress = |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1026 | data.value("PowerMgmtDeviceSlaveAddress", 0); |
| 1027 | uint4_t bmcChannelNumber = data.value("BMCChannelNumber", 0); |
| 1028 | uint4_t deviceRivision = data.value("DeviceRivision", 0); |
Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1029 | payload.pack(powerMgmtDeviceTargetAddress, reserved1, |
| 1030 | deviceRivision, bmcChannelNumber); |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1031 | break; |
| 1032 | } |
| 1033 | // Manageability Access Attributes |
| 1034 | case DCMICapParameters::ManageabilityAccessAttributes: |
| 1035 | { |
| 1036 | uint8_t mandatoryPrimaryLanOOBSupport = |
| 1037 | data.value("MandatoryPrimaryLanOOBSupport", 0xff); |
| 1038 | uint8_t optionalSecondaryLanOOBSupport = |
| 1039 | data.value("OptionalSecondaryLanOOBSupport", 0xff); |
| 1040 | uint8_t optionalSerialOOBMTMODECapability = |
| 1041 | data.value("OptionalSerialOOBMTMODECapability", 0xff); |
| 1042 | payload.pack(mandatoryPrimaryLanOOBSupport, |
| 1043 | optionalSecondaryLanOOBSupport, |
| 1044 | optionalSerialOOBMTMODECapability); |
| 1045 | break; |
| 1046 | } |
| 1047 | default: |
| 1048 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1049 | lg2::error("Invalid input parameter"); |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1050 | return ipmi::responseInvalidFieldRequest(); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1054 | return ipmi::responseSuccess(payload); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1055 | } |
| 1056 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1057 | namespace dcmi |
| 1058 | { |
| 1059 | namespace temp_readings |
| 1060 | { |
| 1061 | |
Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1062 | std::tuple<bool, bool, uint8_t> readTemp(ipmi::Context::ptr& ctx, |
| 1063 | const std::string& dbusService, |
| 1064 | const std::string& dbusPath) |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1065 | { |
| 1066 | // Read the temperature value from d-bus object. Need some conversion. |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1067 | // As per the interface xyz.openbmc_project.Sensor.Value, the |
| 1068 | // temperature is an double and in degrees C. It needs to be scaled by |
| 1069 | // using the formula Value * 10^Scale. The ipmi spec has the temperature |
| 1070 | // as a uint8_t, with a separate single bit for the sign. |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1071 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1072 | ipmi::PropertyMap result{}; |
| 1073 | boost::system::error_code ec = ipmi::getAllDbusProperties( |
| 1074 | ctx, dbusService, dbusPath, "xyz.openbmc_project.Sensor.Value", result); |
| 1075 | if (ec.value()) |
| 1076 | { |
| 1077 | return std::make_tuple(false, false, 0); |
| 1078 | } |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1079 | auto temperature = |
| 1080 | std::visit(ipmi::VariantToDoubleVisitor(), result.at("Value")); |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 1081 | double absTemp = std::abs(temperature); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1082 | |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 1083 | auto findFactor = result.find("Scale"); |
| 1084 | double factor = 0.0; |
| 1085 | if (findFactor != result.end()) |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1086 | { |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 1087 | factor = std::visit(ipmi::VariantToDoubleVisitor(), findFactor->second); |
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 | double scale = std::pow(10, factor); |
| 1090 | |
| 1091 | auto tempDegrees = absTemp * scale; |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1092 | // Max absolute temp as per ipmi spec is 127. |
| 1093 | constexpr auto maxTemp = 127; |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1094 | if (tempDegrees > maxTemp) |
| 1095 | { |
| 1096 | tempDegrees = maxTemp; |
| 1097 | } |
| 1098 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1099 | return std::make_tuple(true, (temperature < 0), |
| 1100 | static_cast<uint8_t>(tempDegrees)); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1101 | } |
| 1102 | |
Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1103 | std::tuple<std::vector<std::tuple<uint7_t, bool, uint8_t>>, uint8_t> read( |
| 1104 | ipmi::Context::ptr& ctx, const std::string& type, uint8_t instance, |
| 1105 | size_t count) |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1106 | { |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1107 | std::vector<std::tuple<uint7_t, bool, uint8_t>> response{}; |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1108 | |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 1109 | auto data = parseJSONConfig(gDCMISensorsConfig); |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1110 | static const std::vector<nlohmann::json> empty{}; |
| 1111 | std::vector<nlohmann::json> readings = data.value(type, empty); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1112 | for (const auto& j : readings) |
| 1113 | { |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1114 | // Max of 8 response data sets |
| 1115 | if (response.size() == count) |
| 1116 | { |
| 1117 | break; |
| 1118 | } |
| 1119 | |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1120 | uint8_t instanceNum = j.value("instance", 0); |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1121 | // Not in the instance range we're interested in |
| 1122 | if (instanceNum < instance) |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1123 | { |
| 1124 | continue; |
| 1125 | } |
| 1126 | |
| 1127 | std::string path = j.value("dbus", ""); |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1128 | std::string service{}; |
| 1129 | boost::system::error_code ec = ipmi::getService( |
| 1130 | ctx, "xyz.openbmc_project.Sensor.Value", path, service); |
| 1131 | if (ec.value()) |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1132 | { |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1133 | // not found on dbus |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1134 | continue; |
| 1135 | } |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1136 | |
| 1137 | const auto& [ok, sign, temp] = readTemp(ctx, service, path); |
| 1138 | if (ok) |
| 1139 | { |
| 1140 | response.emplace_back(uint7_t{temp}, sign, instanceNum); |
| 1141 | } |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 1142 | } |
| 1143 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1144 | auto totalInstances = |
| 1145 | static_cast<uint8_t>(std::min(readings.size(), maxInstances)); |
| 1146 | return std::make_tuple(response, totalInstances); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1147 | } |
| 1148 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1149 | } // namespace temp_readings |
| 1150 | } // namespace dcmi |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1151 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1152 | ipmi::RspType<uint8_t, // total instances for entity id |
| 1153 | uint8_t, // number of instances in this reply |
| 1154 | std::vector< // zero or more of the following two bytes |
| 1155 | std::tuple<uint7_t, // temperature value |
| 1156 | bool, // sign bit |
| 1157 | uint8_t // entity instance |
| 1158 | >>> |
| 1159 | getTempReadings(ipmi::Context::ptr& ctx, uint8_t sensorType, |
| 1160 | uint8_t entityId, uint8_t entityInstance, |
| 1161 | uint8_t instanceStart) |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1162 | { |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1163 | auto it = dcmi::entityIdToName.find(entityId); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1164 | if (it == dcmi::entityIdToName.end()) |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1165 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1166 | lg2::error("Unknown Entity ID: {ENTITY_ID}", "ENTITY_ID", entityId); |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1167 | return ipmi::responseInvalidFieldRequest(); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1168 | } |
| 1169 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1170 | if (sensorType != dcmi::temperatureSensorType) |
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("Invalid sensor type: {SENSOR_TYPE}", "SENSOR_TYPE", |
| 1173 | sensorType); |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1174 | return ipmi::responseInvalidFieldRequest(); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1175 | } |
| 1176 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1177 | uint8_t requestedRecords = (entityInstance == 0) ? dcmi::maxRecords : 1; |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1178 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1179 | // Read requested instances |
| 1180 | const auto& [temps, totalInstances] = dcmi::temp_readings::read( |
| 1181 | ctx, it->second, instanceStart, requestedRecords); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1182 | |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame] | 1183 | auto numInstances = static_cast<uint8_t>(temps.size()); |
| 1184 | |
| 1185 | return ipmi::responseSuccess(totalInstances, numInstances, temps); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1186 | } |
| 1187 | |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1188 | ipmi::RspType<> setDCMIConfParams(ipmi::Context::ptr& ctx, uint8_t parameter, |
| 1189 | uint8_t setSelector, |
| 1190 | ipmi::message::Payload& payload) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1191 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1192 | if (setSelector) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1193 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1194 | return ipmi::responseInvalidFieldRequest(); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1195 | } |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1196 | // Take action based on the Parameter Selector |
| 1197 | switch (static_cast<dcmi::DCMIConfigParameters>(parameter)) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1198 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1199 | case dcmi::DCMIConfigParameters::ActivateDHCP: |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1200 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1201 | uint7_t reserved{}; |
| 1202 | bool activate{}; |
| 1203 | if (payload.unpack(activate, reserved) || !payload.fullyUnpacked()) |
| 1204 | { |
| 1205 | return ipmi::responseReqDataLenInvalid(); |
| 1206 | } |
| 1207 | if (reserved) |
| 1208 | { |
| 1209 | return ipmi::responseInvalidFieldRequest(); |
| 1210 | } |
| 1211 | std::optional<EthernetInterface::DHCPConf> dhcpEnabled = |
| 1212 | dcmi::getDHCPEnabled(ctx); |
| 1213 | if (!dhcpEnabled) |
| 1214 | { |
| 1215 | return ipmi::responseUnspecifiedError(); |
| 1216 | } |
| 1217 | if (activate && |
| 1218 | (dhcpEnabled.value() != EthernetInterface::DHCPConf::none)) |
| 1219 | { |
| 1220 | // When these conditions are met we have to trigger DHCP |
| 1221 | // protocol restart using the latest parameter settings, |
| 1222 | // but as per n/w manager design, each time when we |
| 1223 | // update n/w parameters, n/w service is restarted. So |
| 1224 | // we no need to take any action in this case. |
| 1225 | } |
| 1226 | break; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1227 | } |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1228 | case dcmi::DCMIConfigParameters::DiscoveryConfig: |
| 1229 | { |
| 1230 | bool option12{}; |
| 1231 | uint6_t reserved1{}; |
| 1232 | bool randBackOff{}; |
| 1233 | if (payload.unpack(option12, reserved1, randBackOff) || |
| 1234 | !payload.fullyUnpacked()) |
| 1235 | { |
| 1236 | return ipmi::responseReqDataLenInvalid(); |
| 1237 | } |
| 1238 | // Systemd-networkd doesn't support Random Back off |
| 1239 | if (reserved1 || randBackOff) |
| 1240 | { |
| 1241 | return ipmi::responseInvalidFieldRequest(); |
| 1242 | } |
| 1243 | dcmi::setDHCPOption(ctx, dcmi::dhcpOpt12Enabled, option12); |
| 1244 | break; |
| 1245 | } |
| 1246 | // Systemd-networkd doesn't allow to configure DHCP timigs |
| 1247 | case dcmi::DCMIConfigParameters::DHCPTiming1: |
| 1248 | case dcmi::DCMIConfigParameters::DHCPTiming2: |
| 1249 | case dcmi::DCMIConfigParameters::DHCPTiming3: |
| 1250 | default: |
| 1251 | return ipmi::responseInvalidFieldRequest(); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1252 | } |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1253 | return ipmi::responseSuccess(); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1254 | } |
| 1255 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1256 | ipmi::RspType<ipmi::message::Payload> getDCMIConfParams( |
| 1257 | ipmi::Context::ptr& ctx, uint8_t parameter, uint8_t setSelector) |
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 | if (setSelector) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1260 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1261 | return ipmi::responseInvalidFieldRequest(); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1262 | } |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1263 | ipmi::message::Payload payload; |
| 1264 | payload.pack(dcmi::specMajorVersion, dcmi::specMinorVersion, |
| 1265 | dcmi::configParameterRevision); |
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 | // Take action based on the Parameter Selector |
| 1268 | switch (static_cast<dcmi::DCMIConfigParameters>(parameter)) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1269 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1270 | case dcmi::DCMIConfigParameters::ActivateDHCP: |
| 1271 | payload.pack(dcmi::activateDhcpReply); |
| 1272 | break; |
| 1273 | case dcmi::DCMIConfigParameters::DiscoveryConfig: |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1274 | { |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1275 | uint8_t discovery{}; |
| 1276 | std::optional<bool> enabled = |
| 1277 | dcmi::getDHCPOption(ctx, dcmi::dhcpOpt12Enabled); |
| 1278 | if (!enabled.has_value()) |
| 1279 | { |
| 1280 | return ipmi::responseUnspecifiedError(); |
| 1281 | } |
| 1282 | if (enabled.value()) |
| 1283 | { |
| 1284 | discovery = dcmi::option12Mask; |
| 1285 | } |
| 1286 | payload.pack(discovery); |
| 1287 | break; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1288 | } |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1289 | // Get below values from Systemd-networkd source code |
| 1290 | case dcmi::DCMIConfigParameters::DHCPTiming1: |
| 1291 | payload.pack(dcmi::dhcpTiming1); |
| 1292 | break; |
| 1293 | case dcmi::DCMIConfigParameters::DHCPTiming2: |
| 1294 | payload.pack(dcmi::dhcpTiming2); |
| 1295 | break; |
| 1296 | case dcmi::DCMIConfigParameters::DHCPTiming3: |
| 1297 | payload.pack(dcmi::dhcpTiming3); |
| 1298 | break; |
| 1299 | default: |
| 1300 | return ipmi::responseInvalidFieldRequest(); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1301 | } |
| 1302 | |
Thang Tran | af762de | 2023-12-18 11:19:28 +0700 | [diff] [blame] | 1303 | return ipmi::responseSuccess(payload); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1304 | } |
| 1305 | |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1306 | static std::optional<uint16_t> readPower(ipmi::Context::ptr& ctx) |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1307 | { |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1308 | std::ifstream sensorFile(POWER_READING_SENSOR); |
| 1309 | std::string objectPath; |
| 1310 | if (!sensorFile.is_open()) |
| 1311 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1312 | lg2::error( |
| 1313 | "Power reading configuration file not found: {POWER_SENSOR_FILE}", |
| 1314 | "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR}); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1315 | return std::nullopt; |
| 1316 | } |
| 1317 | |
| 1318 | auto data = nlohmann::json::parse(sensorFile, nullptr, false); |
| 1319 | if (data.is_discarded()) |
| 1320 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1321 | lg2::error("Error in parsing configuration file: {POWER_SENSOR_FILE}", |
| 1322 | "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR}); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1323 | return std::nullopt; |
| 1324 | } |
| 1325 | |
| 1326 | objectPath = data.value("path", ""); |
| 1327 | if (objectPath.empty()) |
| 1328 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1329 | lg2::error( |
| 1330 | "Power sensor D-Bus object path is empty: {POWER_SENSOR_FILE}", |
| 1331 | "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR}); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1332 | return std::nullopt; |
| 1333 | } |
| 1334 | |
| 1335 | // Return default value if failed to read from D-Bus object |
| 1336 | std::string service{}; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1337 | boost::system::error_code ec = |
| 1338 | ipmi::getService(ctx, dcmi::sensorValueIntf, objectPath, service); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1339 | if (ec.value()) |
| 1340 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1341 | lg2::error("Failed to fetch service for D-Bus object, " |
| 1342 | "object path: {OBJECT_PATH}, interface: {INTERFACE}", |
| 1343 | "OBJECT_PATH", objectPath, "INTERFACE", |
| 1344 | dcmi::sensorValueIntf); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1345 | return std::nullopt; |
| 1346 | } |
| 1347 | |
| 1348 | // Read the sensor value and scale properties |
| 1349 | double value{}; |
| 1350 | ec = ipmi::getDbusProperty(ctx, service, objectPath, dcmi::sensorValueIntf, |
| 1351 | dcmi::sensorValueProp, value); |
| 1352 | if (ec.value()) |
| 1353 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1354 | lg2::error("Failed to read power value from D-Bus object, " |
| 1355 | "object path: {OBJECT_PATH}, interface: {INTERFACE}", |
| 1356 | "OBJECT_PATH", objectPath, "INTERFACE", |
| 1357 | dcmi::sensorValueIntf); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1358 | return std::nullopt; |
| 1359 | } |
| 1360 | auto power = static_cast<uint16_t>(value); |
| 1361 | return power; |
| 1362 | } |
| 1363 | |
| 1364 | ipmi::RspType<uint16_t, // current power |
| 1365 | uint16_t, // minimum power |
| 1366 | uint16_t, // maximum power |
| 1367 | uint16_t, // average power |
| 1368 | uint32_t, // timestamp |
| 1369 | uint32_t, // sample period ms |
| 1370 | uint6_t, // reserved |
| 1371 | bool, // power measurement active |
| 1372 | bool // reserved |
| 1373 | > |
| 1374 | getPowerReading(ipmi::Context::ptr& ctx, uint8_t mode, uint8_t attributes, |
| 1375 | uint8_t reserved) |
| 1376 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 1377 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 1378 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1379 | lg2::error("DCMI Power management is unsupported!"); |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1380 | return ipmi::responseInvalidCommand(); |
| 1381 | } |
| 1382 | if (reserved) |
| 1383 | { |
| 1384 | return ipmi::responseInvalidFieldRequest(); |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 1385 | } |
| 1386 | |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1387 | enum class PowerMode : uint8_t |
| 1388 | { |
| 1389 | SystemPowerStatistics = 1, |
| 1390 | EnhancedSystemPowerStatistics = 2, |
| 1391 | }; |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1392 | |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1393 | if (static_cast<PowerMode>(mode) != PowerMode::SystemPowerStatistics) |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1394 | { |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1395 | return ipmi::responseInvalidFieldRequest(); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1396 | } |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1397 | if (attributes) |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1398 | { |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1399 | return ipmi::responseInvalidFieldRequest(); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1400 | } |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1401 | |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1402 | std::optional<uint16_t> powerResp = readPower(ctx); |
| 1403 | if (!powerResp) |
| 1404 | { |
| 1405 | return ipmi::responseUnspecifiedError(); |
| 1406 | } |
| 1407 | auto& power = powerResp.value(); |
| 1408 | |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1409 | // TODO: openbmc/openbmc#2819 |
Gunnar Mills | 8466b79 | 2018-03-23 12:18:12 -0500 | [diff] [blame] | 1410 | // Minimum, Maximum, Average power, TimeFrame, TimeStamp, |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1411 | // PowerReadingState readings need to be populated |
| 1412 | // after Telemetry changes. |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1413 | constexpr uint32_t samplePeriod = 1; |
| 1414 | constexpr uint6_t reserved1 = 0; |
| 1415 | constexpr bool measurementActive = true; |
| 1416 | constexpr bool reserved2 = false; |
| 1417 | auto timestamp = static_cast<uint32_t>(time(nullptr)); |
| 1418 | return ipmi::responseSuccess(power, power, power, power, timestamp, |
| 1419 | samplePeriod, reserved1, measurementActive, |
| 1420 | reserved2); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1421 | } |
| 1422 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1423 | namespace dcmi |
| 1424 | { |
| 1425 | namespace sensor_info |
| 1426 | { |
| 1427 | |
Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1428 | std::tuple<std::vector<uint16_t>, uint8_t> read( |
| 1429 | const std::string& type, uint8_t instance, const nlohmann::json& config, |
| 1430 | uint8_t count) |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1431 | { |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1432 | std::vector<uint16_t> responses{}; |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1433 | |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1434 | static const std::vector<nlohmann::json> empty{}; |
| 1435 | std::vector<nlohmann::json> readings = config.value(type, empty); |
| 1436 | uint8_t totalInstances = std::min(readings.size(), maxInstances); |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1437 | for (const auto& reading : readings) |
| 1438 | { |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1439 | // limit to requested count |
| 1440 | if (responses.size() == count) |
| 1441 | { |
| 1442 | break; |
| 1443 | } |
| 1444 | |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1445 | uint8_t instanceNum = reading.value("instance", 0); |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1446 | // Not in the instance range we're interested in |
| 1447 | if (instanceNum < instance) |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1448 | { |
| 1449 | continue; |
| 1450 | } |
| 1451 | |
Thang Tran | 5ea83fa | 2023-10-16 14:37:56 +0700 | [diff] [blame] | 1452 | uint16_t recordId = reading.value("record_id", 0); |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1453 | responses.emplace_back(recordId); |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1454 | } |
| 1455 | |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1456 | return std::make_tuple(responses, totalInstances); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | } // namespace sensor_info |
| 1460 | } // namespace dcmi |
| 1461 | |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1462 | ipmi::RspType<uint8_t, // total available instances |
| 1463 | uint8_t, // number of records in this response |
| 1464 | std::vector<uint16_t> // records |
| 1465 | > |
| 1466 | getSensorInfo(uint8_t sensorType, uint8_t entityId, uint8_t entityInstance, |
| 1467 | uint8_t instanceStart) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1468 | { |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1469 | auto it = dcmi::entityIdToName.find(entityId); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1470 | if (it == dcmi::entityIdToName.end()) |
| 1471 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1472 | lg2::error("Unknown Entity ID: {ENTITY_ID}", "ENTITY_ID", entityId); |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1473 | return ipmi::responseInvalidFieldRequest(); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1474 | } |
| 1475 | |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1476 | if (sensorType != dcmi::temperatureSensorType) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1477 | { |
George Liu | 7fa2871 | 2024-07-17 19:26:23 +0800 | [diff] [blame] | 1478 | lg2::error("Invalid sensor type: {SENSOR_TYPE}", "SENSOR_TYPE", |
| 1479 | sensorType); |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1480 | return ipmi::responseInvalidFieldRequest(); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1481 | } |
| 1482 | |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1483 | nlohmann::json config = dcmi::parseJSONConfig(dcmi::gDCMISensorsConfig); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1484 | |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1485 | uint8_t requestedRecords = (entityInstance == 0) ? dcmi::maxRecords : 1; |
| 1486 | // Read requested instances |
| 1487 | const auto& [sensors, totalInstances] = dcmi::sensor_info::read( |
| 1488 | it->second, instanceStart, config, requestedRecords); |
| 1489 | uint8_t numRecords = sensors.size(); |
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 | return ipmi::responseSuccess(totalInstances, numRecords, sensors); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1492 | } |
| 1493 | |
George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 1494 | void registerNetFnDcmiFunctions() |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 1495 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1496 | // <Get Power Limit> |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 1497 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1498 | ipmi::dcmi::cmdGetPowerLimit, ipmi::Privilege::User, |
| 1499 | getPowerLimit); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 1500 | |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 1501 | // <Set Power Limit> |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 1502 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1503 | ipmi::dcmi::cmdSetPowerLimit, |
| 1504 | ipmi::Privilege::Operator, setPowerLimit); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 1505 | |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 1506 | // <Activate/Deactivate Power Limit> |
Vernon Mauery | d4222fd | 2023-07-27 11:26:51 -0700 | [diff] [blame] | 1507 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1508 | ipmi::dcmi::cmdActDeactivatePwrLimit, |
| 1509 | ipmi::Privilege::Operator, applyPowerLimit); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 1510 | |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 1511 | // <Get Asset Tag> |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 1512 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1513 | ipmi::dcmi::cmdGetAssetTag, ipmi::Privilege::User, |
| 1514 | getAssetTag); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 1515 | |
| 1516 | // <Set Asset Tag> |
Vernon Mauery | dca4720 | 2023-07-27 11:32:01 -0700 | [diff] [blame] | 1517 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1518 | ipmi::dcmi::cmdSetAssetTag, ipmi::Privilege::Operator, |
| 1519 | setAssetTag); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1520 | |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 1521 | // <Get Management Controller Identifier String> |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 1522 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1523 | ipmi::dcmi::cmdGetMgmtCntlrIdString, |
| 1524 | ipmi::Privilege::User, getMgmntCtrlIdStr); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1525 | |
| 1526 | // <Set Management Controller Identifier String> |
Vernon Mauery | efb5ae5 | 2023-07-27 11:35:43 -0700 | [diff] [blame] | 1527 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1528 | ipmi::dcmi::cmdSetMgmtCntlrIdString, |
| 1529 | ipmi::Privilege::Admin, setMgmntCtrlIdStr); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1530 | |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1531 | // <Get DCMI capabilities> |
Vernon Mauery | f038dc0 | 2023-07-27 14:06:11 -0700 | [diff] [blame] | 1532 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1533 | ipmi::dcmi::cmdGetDcmiCapabilitiesInfo, |
| 1534 | ipmi::Privilege::User, getDCMICapabilities); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1535 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1536 | // <Get Power Reading> |
Vernon Mauery | 056fab1 | 2023-07-27 14:25:24 -0700 | [diff] [blame] | 1537 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1538 | ipmi::dcmi::cmdGetPowerReading, ipmi::Privilege::User, |
| 1539 | getPowerReading); |
| 1540 | |
adarshgrami | 042e9db | 2022-09-15 10:34:34 +0530 | [diff] [blame] | 1541 | // The Get sensor should get the senor details dynamically when |
| 1542 | // FEATURE_DYNAMIC_SENSORS is enabled. |
| 1543 | #ifndef FEATURE_DYNAMIC_SENSORS |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1544 | // <Get Sensor Info> |
Vernon Mauery | 53d0cf1 | 2023-07-27 14:32:44 -0700 | [diff] [blame] | 1545 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1546 | ipmi::dcmi::cmdGetDcmiSensorInfo, |
| 1547 | ipmi::Privilege::Operator, getSensorInfo); |
Thang Tran | 3dad826 | 2023-08-17 15:20:56 +0700 | [diff] [blame] | 1548 | |
| 1549 | // <Get Temperature Readings> |
| 1550 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1551 | ipmi::dcmi::cmdGetTemperatureReadings, |
| 1552 | ipmi::Privilege::User, getTempReadings); |
adarshgrami | 042e9db | 2022-09-15 10:34:34 +0530 | [diff] [blame] | 1553 | #endif |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1554 | // <Get DCMI Configuration Parameters> |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1555 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1556 | ipmi::dcmi::cmdGetDcmiConfigParameters, |
| 1557 | ipmi::Privilege::User, getDCMIConfParams); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1558 | |
| 1559 | // <Set DCMI Configuration Parameters> |
Vernon Mauery | 6475b5c | 2023-07-27 14:52:51 -0700 | [diff] [blame] | 1560 | registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI, |
| 1561 | ipmi::dcmi::cmdSetDcmiConfigParameters, |
| 1562 | ipmi::Privilege::Admin, setDCMIConfParams); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1563 | |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 1564 | return; |
| 1565 | } |