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