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