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