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