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 | #include "utils.hpp" |
| 7 | |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 8 | #include <ipmid/api.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | |
| 10 | #include <bitset> |
| 11 | #include <cmath> |
| 12 | #include <fstream> |
| 13 | #include <nlohmann/json.hpp> |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 14 | #include <phosphor-logging/elog-errors.hpp> |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 15 | #include <phosphor-logging/log.hpp> |
| 16 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 17 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 18 | #include <xyz/openbmc_project/Common/error.hpp> |
| 19 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 20 | using namespace phosphor::logging; |
| 21 | using InternalFailure = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 22 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 23 | |
| 24 | void register_netfn_dcmi_functions() __attribute__((constructor)); |
| 25 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 26 | constexpr auto PCAP_PATH = "/xyz/openbmc_project/control/host0/power_cap"; |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 27 | constexpr auto PCAP_INTERFACE = "xyz.openbmc_project.Control.Power.Cap"; |
| 28 | |
| 29 | constexpr auto POWER_CAP_PROP = "PowerCap"; |
| 30 | constexpr auto POWER_CAP_ENABLE_PROP = "PowerCapEnable"; |
| 31 | |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 32 | constexpr auto DCMI_PARAMETER_REVISION = 2; |
| 33 | constexpr auto DCMI_SPEC_MAJOR_VERSION = 1; |
| 34 | constexpr auto DCMI_SPEC_MINOR_VERSION = 5; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 35 | constexpr auto DCMI_CONFIG_PARAMETER_REVISION = 1; |
| 36 | constexpr auto DCMI_RAND_BACK_OFF_MASK = 0x80; |
| 37 | constexpr auto DCMI_OPTION_60_43_MASK = 0x02; |
| 38 | constexpr auto DCMI_OPTION_12_MASK = 0x01; |
| 39 | constexpr auto DCMI_ACTIVATE_DHCP_MASK = 0x01; |
| 40 | constexpr auto DCMI_ACTIVATE_DHCP_REPLY = 0x00; |
| 41 | constexpr auto DCMI_SET_CONF_PARAM_REQ_PACKET_MAX_SIZE = 0x05; |
| 42 | constexpr auto DCMI_SET_CONF_PARAM_REQ_PACKET_MIN_SIZE = 0x04; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 43 | constexpr auto DHCP_TIMING1 = 0x04; // 4 sec |
| 44 | constexpr auto DHCP_TIMING2_UPPER = 0x00; // 2 min |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 45 | constexpr auto DHCP_TIMING2_LOWER = 0x78; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 46 | constexpr auto DHCP_TIMING3_UPPER = 0x00; // 64 sec |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 47 | constexpr auto DHCP_TIMING3_LOWER = 0x40; |
| 48 | // When DHCP Option 12 is enabled the string "SendHostName=true" will be |
| 49 | // added into n/w configuration file and the parameter |
| 50 | // SendHostNameEnabled will set to true. |
| 51 | constexpr auto DHCP_OPT12_ENABLED = "SendHostNameEnabled"; |
| 52 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 53 | constexpr auto SENSOR_VALUE_INTF = "xyz.openbmc_project.Sensor.Value"; |
| 54 | constexpr auto SENSOR_VALUE_PROP = "Value"; |
| 55 | constexpr auto SENSOR_SCALE_PROP = "Scale"; |
| 56 | |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 57 | using namespace phosphor::logging; |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 58 | namespace variant_ns = sdbusplus::message::variant_ns; |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 59 | |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 60 | namespace dcmi |
| 61 | { |
| 62 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 63 | // Refer Table 6-14, DCMI Entity ID Extension, DCMI v1.5 spec |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 64 | static const std::map<uint8_t, std::string> entityIdToName{ |
| 65 | {0x40, "inlet"}, {0x37, "inlet"}, {0x41, "cpu"}, |
| 66 | {0x03, "cpu"}, {0x42, "baseboard"}, {0x07, "baseboard"}}; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 67 | |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 68 | bool isDCMIPowerMgmtSupported() |
| 69 | { |
| 70 | auto data = parseJSONConfig(gDCMICapabilitiesConfig); |
| 71 | |
| 72 | return (gDCMIPowerMgmtSupported == data.value(gDCMIPowerMgmtCapability, 0)); |
| 73 | } |
| 74 | |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 75 | uint32_t getPcap(sdbusplus::bus::bus& bus) |
| 76 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 77 | auto settingService = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 78 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 79 | auto method = bus.new_method_call(settingService.c_str(), PCAP_PATH, |
| 80 | "org.freedesktop.DBus.Properties", "Get"); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 81 | |
| 82 | method.append(PCAP_INTERFACE, POWER_CAP_PROP); |
| 83 | auto reply = bus.call(method); |
| 84 | |
| 85 | if (reply.is_method_error()) |
| 86 | { |
| 87 | log<level::ERR>("Error in getPcap prop"); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 88 | elog<InternalFailure>(); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 89 | } |
| 90 | sdbusplus::message::variant<uint32_t> pcap; |
| 91 | reply.read(pcap); |
| 92 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 93 | return variant_ns::get<uint32_t>(pcap); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | bool getPcapEnabled(sdbusplus::bus::bus& bus) |
| 97 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 98 | auto settingService = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 99 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 100 | auto method = bus.new_method_call(settingService.c_str(), PCAP_PATH, |
| 101 | "org.freedesktop.DBus.Properties", "Get"); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 102 | |
| 103 | method.append(PCAP_INTERFACE, POWER_CAP_ENABLE_PROP); |
| 104 | auto reply = bus.call(method); |
| 105 | |
| 106 | if (reply.is_method_error()) |
| 107 | { |
| 108 | log<level::ERR>("Error in getPcapEnabled prop"); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 109 | elog<InternalFailure>(); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 110 | } |
| 111 | sdbusplus::message::variant<bool> pcapEnabled; |
| 112 | reply.read(pcapEnabled); |
| 113 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 114 | return variant_ns::get<bool>(pcapEnabled); |
Andrew Geissler | 50c0c8f | 2017-07-11 16:18:51 -0500 | [diff] [blame] | 115 | } |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 116 | |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 117 | void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap) |
| 118 | { |
| 119 | auto service = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH); |
| 120 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 121 | auto method = bus.new_method_call(service.c_str(), PCAP_PATH, |
| 122 | "org.freedesktop.DBus.Properties", "Set"); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 123 | |
| 124 | method.append(PCAP_INTERFACE, POWER_CAP_PROP); |
| 125 | method.append(sdbusplus::message::variant<uint32_t>(powerCap)); |
| 126 | |
| 127 | auto reply = bus.call(method); |
| 128 | |
| 129 | if (reply.is_method_error()) |
| 130 | { |
| 131 | log<level::ERR>("Error in setPcap property"); |
| 132 | elog<InternalFailure>(); |
| 133 | } |
| 134 | } |
| 135 | |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 136 | void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled) |
| 137 | { |
| 138 | auto service = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH); |
| 139 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 140 | auto method = bus.new_method_call(service.c_str(), PCAP_PATH, |
| 141 | "org.freedesktop.DBus.Properties", "Set"); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 142 | |
| 143 | method.append(PCAP_INTERFACE, POWER_CAP_ENABLE_PROP); |
| 144 | method.append(sdbusplus::message::variant<bool>(enabled)); |
| 145 | |
| 146 | auto reply = bus.call(method); |
| 147 | |
| 148 | if (reply.is_method_error()) |
| 149 | { |
| 150 | log<level::ERR>("Error in setPcapEnabled property"); |
| 151 | elog<InternalFailure>(); |
| 152 | } |
| 153 | } |
| 154 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 155 | void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree) |
| 156 | { |
| 157 | static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; |
| 158 | static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; |
| 159 | static constexpr auto mapperIface = "xyz.openbmc_project.ObjectMapper"; |
| 160 | static constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory/"; |
| 161 | |
| 162 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 163 | auto depth = 0; |
| 164 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 165 | auto mapperCall = bus.new_method_call(mapperBusName, mapperObjPath, |
| 166 | mapperIface, "GetSubTree"); |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 167 | |
| 168 | mapperCall.append(inventoryRoot); |
| 169 | mapperCall.append(depth); |
| 170 | mapperCall.append(std::vector<std::string>({dcmi::assetTagIntf})); |
| 171 | |
| 172 | auto mapperReply = bus.call(mapperCall); |
| 173 | if (mapperReply.is_method_error()) |
| 174 | { |
| 175 | log<level::ERR>("Error in mapper call"); |
| 176 | elog<InternalFailure>(); |
| 177 | } |
| 178 | |
| 179 | mapperReply.read(objectTree); |
| 180 | |
| 181 | if (objectTree.empty()) |
| 182 | { |
| 183 | log<level::ERR>("AssetTag property is not populated"); |
| 184 | elog<InternalFailure>(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | std::string readAssetTag() |
| 189 | { |
| 190 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 191 | dcmi::assettag::ObjectTree objectTree; |
| 192 | |
| 193 | // Read the object tree with the inventory root to figure out the object |
| 194 | // that has implemented the Asset tag interface. |
| 195 | readAssetTagObjectTree(objectTree); |
| 196 | |
| 197 | auto method = bus.new_method_call( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 198 | (objectTree.begin()->second.begin()->first).c_str(), |
| 199 | (objectTree.begin()->first).c_str(), dcmi::propIntf, "Get"); |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 200 | method.append(dcmi::assetTagIntf); |
| 201 | method.append(dcmi::assetTagProp); |
| 202 | |
| 203 | auto reply = bus.call(method); |
| 204 | if (reply.is_method_error()) |
| 205 | { |
| 206 | log<level::ERR>("Error in reading asset tag"); |
| 207 | elog<InternalFailure>(); |
| 208 | } |
| 209 | |
| 210 | sdbusplus::message::variant<std::string> assetTag; |
| 211 | reply.read(assetTag); |
| 212 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 213 | return variant_ns::get<std::string>(assetTag); |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 214 | } |
| 215 | |
Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 216 | void writeAssetTag(const std::string& assetTag) |
| 217 | { |
| 218 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 219 | dcmi::assettag::ObjectTree objectTree; |
| 220 | |
| 221 | // Read the object tree with the inventory root to figure out the object |
| 222 | // that has implemented the Asset tag interface. |
| 223 | readAssetTagObjectTree(objectTree); |
| 224 | |
| 225 | auto method = bus.new_method_call( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 226 | (objectTree.begin()->second.begin()->first).c_str(), |
| 227 | (objectTree.begin()->first).c_str(), dcmi::propIntf, "Set"); |
Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 228 | method.append(dcmi::assetTagIntf); |
| 229 | method.append(dcmi::assetTagProp); |
| 230 | method.append(sdbusplus::message::variant<std::string>(assetTag)); |
| 231 | |
| 232 | auto reply = bus.call(method); |
| 233 | if (reply.is_method_error()) |
| 234 | { |
| 235 | log<level::ERR>("Error in writing asset tag"); |
| 236 | elog<InternalFailure>(); |
| 237 | } |
| 238 | } |
| 239 | |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 240 | std::string getHostName(void) |
| 241 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 242 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 243 | |
| 244 | auto service = ipmi::getService(bus, networkConfigIntf, networkConfigObj); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 245 | auto value = ipmi::getDbusProperty(bus, service, networkConfigObj, |
| 246 | networkConfigIntf, hostNameProp); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 247 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 248 | return variant_ns::get<std::string>(value); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 249 | } |
| 250 | |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 251 | bool getDHCPEnabled() |
| 252 | { |
| 253 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 254 | |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 255 | auto ethdevice = ipmi::getChannelName(ethernetDefaultChannelNum); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 256 | auto ethernetObj = |
| 257 | ipmi::getDbusObject(bus, ethernetIntf, networkRoot, ethdevice); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 258 | auto service = ipmi::getService(bus, ethernetIntf, ethernetObj.first); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 259 | auto value = ipmi::getDbusProperty(bus, service, ethernetObj.first, |
| 260 | ethernetIntf, "DHCPEnabled"); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 261 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 262 | return variant_ns::get<bool>(value); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | bool getDHCPOption(std::string prop) |
| 266 | { |
| 267 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 268 | |
| 269 | auto service = ipmi::getService(bus, dhcpIntf, dhcpObj); |
| 270 | auto value = ipmi::getDbusProperty(bus, service, dhcpObj, dhcpIntf, prop); |
| 271 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 272 | return variant_ns::get<bool>(value); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 273 | } |
| 274 | |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 275 | void setDHCPOption(std::string prop, bool value) |
| 276 | { |
| 277 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 278 | |
| 279 | auto service = ipmi::getService(bus, dhcpIntf, dhcpObj); |
| 280 | ipmi::setDbusProperty(bus, service, dhcpObj, dhcpIntf, prop, value); |
| 281 | } |
| 282 | |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 283 | Json parseJSONConfig(const std::string& configFile) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 284 | { |
| 285 | std::ifstream jsonFile(configFile); |
| 286 | if (!jsonFile.is_open()) |
| 287 | { |
| 288 | log<level::ERR>("Temperature readings JSON file not found"); |
| 289 | elog<InternalFailure>(); |
| 290 | } |
| 291 | |
| 292 | auto data = Json::parse(jsonFile, nullptr, false); |
| 293 | if (data.is_discarded()) |
| 294 | { |
| 295 | log<level::ERR>("Temperature readings JSON parser failure"); |
| 296 | elog<InternalFailure>(); |
| 297 | } |
| 298 | |
| 299 | return data; |
| 300 | } |
| 301 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 302 | } // namespace dcmi |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 303 | |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 304 | ipmi_ret_t getPowerLimit(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 305 | ipmi_request_t request, ipmi_response_t response, |
| 306 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 307 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 308 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 309 | { |
| 310 | *data_len = 0; |
| 311 | log<level::ERR>("DCMI Power management is unsupported!"); |
| 312 | return IPMI_CC_INVALID; |
| 313 | } |
| 314 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 315 | auto requestData = |
| 316 | reinterpret_cast<const dcmi::GetPowerLimitRequest*>(request); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 317 | std::vector<uint8_t> outPayload(sizeof(dcmi::GetPowerLimitResponse)); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 318 | auto responseData = |
| 319 | reinterpret_cast<dcmi::GetPowerLimitResponse*>(outPayload.data()); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 320 | |
| 321 | if (requestData->groupID != dcmi::groupExtId) |
| 322 | { |
| 323 | *data_len = 0; |
| 324 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 325 | } |
| 326 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 327 | sdbusplus::bus::bus sdbus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 328 | uint32_t pcapValue = 0; |
| 329 | bool pcapEnable = false; |
| 330 | |
| 331 | try |
| 332 | { |
| 333 | pcapValue = dcmi::getPcap(sdbus); |
| 334 | pcapEnable = dcmi::getPcapEnabled(sdbus); |
| 335 | } |
| 336 | catch (InternalFailure& e) |
| 337 | { |
| 338 | *data_len = 0; |
| 339 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 340 | } |
| 341 | |
| 342 | responseData->groupID = dcmi::groupExtId; |
| 343 | |
| 344 | /* |
| 345 | * Exception action if power limit is exceeded and cannot be controlled |
| 346 | * with the correction time limit is hardcoded to Hard Power Off system |
| 347 | * and log event to SEL. |
| 348 | */ |
| 349 | constexpr auto exception = 0x01; |
| 350 | responseData->exceptionAction = exception; |
| 351 | |
| 352 | responseData->powerLimit = static_cast<uint16_t>(pcapValue); |
| 353 | |
| 354 | /* |
| 355 | * Correction time limit and Statistics sampling period is currently not |
| 356 | * populated. |
| 357 | */ |
| 358 | |
| 359 | *data_len = outPayload.size(); |
| 360 | memcpy(response, outPayload.data(), *data_len); |
| 361 | |
| 362 | if (pcapEnable) |
| 363 | { |
| 364 | return IPMI_CC_OK; |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | return IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT; |
| 369 | } |
| 370 | } |
| 371 | |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 372 | ipmi_ret_t setPowerLimit(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 373 | ipmi_request_t request, ipmi_response_t response, |
| 374 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 375 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 376 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 377 | { |
| 378 | *data_len = 0; |
| 379 | log<level::ERR>("DCMI Power management is unsupported!"); |
| 380 | return IPMI_CC_INVALID; |
| 381 | } |
| 382 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 383 | auto requestData = |
| 384 | reinterpret_cast<const dcmi::SetPowerLimitRequest*>(request); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 385 | std::vector<uint8_t> outPayload(sizeof(dcmi::SetPowerLimitResponse)); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 386 | auto responseData = |
| 387 | reinterpret_cast<dcmi::SetPowerLimitResponse*>(outPayload.data()); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 388 | |
| 389 | if (requestData->groupID != dcmi::groupExtId) |
| 390 | { |
| 391 | *data_len = 0; |
| 392 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 393 | } |
| 394 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 395 | sdbusplus::bus::bus sdbus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 396 | |
| 397 | // Only process the power limit requested in watts. |
| 398 | try |
| 399 | { |
| 400 | dcmi::setPcap(sdbus, requestData->powerLimit); |
| 401 | } |
| 402 | catch (InternalFailure& e) |
| 403 | { |
| 404 | *data_len = 0; |
| 405 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 406 | } |
| 407 | |
| 408 | log<level::INFO>("Set Power Cap", |
| 409 | entry("POWERCAP=%u", requestData->powerLimit)); |
| 410 | |
| 411 | responseData->groupID = dcmi::groupExtId; |
| 412 | memcpy(response, outPayload.data(), outPayload.size()); |
| 413 | *data_len = outPayload.size(); |
| 414 | |
| 415 | return IPMI_CC_OK; |
| 416 | } |
| 417 | |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 418 | ipmi_ret_t applyPowerLimit(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 419 | ipmi_request_t request, ipmi_response_t response, |
| 420 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 421 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 422 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 423 | { |
| 424 | *data_len = 0; |
| 425 | log<level::ERR>("DCMI Power management is unsupported!"); |
| 426 | return IPMI_CC_INVALID; |
| 427 | } |
| 428 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 429 | auto requestData = |
| 430 | reinterpret_cast<const dcmi::ApplyPowerLimitRequest*>(request); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 431 | std::vector<uint8_t> outPayload(sizeof(dcmi::ApplyPowerLimitResponse)); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 432 | auto responseData = |
| 433 | reinterpret_cast<dcmi::ApplyPowerLimitResponse*>(outPayload.data()); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 434 | |
| 435 | if (requestData->groupID != dcmi::groupExtId) |
| 436 | { |
| 437 | *data_len = 0; |
| 438 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 439 | } |
| 440 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 441 | sdbusplus::bus::bus sdbus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 442 | |
| 443 | try |
| 444 | { |
| 445 | dcmi::setPcapEnable(sdbus, |
| 446 | static_cast<bool>(requestData->powerLimitAction)); |
| 447 | } |
| 448 | catch (InternalFailure& e) |
| 449 | { |
| 450 | *data_len = 0; |
| 451 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 452 | } |
| 453 | |
| 454 | log<level::INFO>("Set Power Cap Enable", |
| 455 | entry("POWERCAPENABLE=%u", requestData->powerLimitAction)); |
| 456 | |
| 457 | responseData->groupID = dcmi::groupExtId; |
| 458 | memcpy(response, outPayload.data(), outPayload.size()); |
| 459 | *data_len = outPayload.size(); |
| 460 | |
| 461 | return IPMI_CC_OK; |
| 462 | } |
| 463 | |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 464 | ipmi_ret_t getAssetTag(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 465 | ipmi_request_t request, ipmi_response_t response, |
| 466 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 467 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 468 | auto requestData = |
| 469 | reinterpret_cast<const dcmi::GetAssetTagRequest*>(request); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 470 | std::vector<uint8_t> outPayload(sizeof(dcmi::GetAssetTagResponse)); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 471 | auto responseData = |
| 472 | reinterpret_cast<dcmi::GetAssetTagResponse*>(outPayload.data()); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 473 | |
| 474 | if (requestData->groupID != dcmi::groupExtId) |
| 475 | { |
| 476 | *data_len = 0; |
| 477 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 478 | } |
| 479 | |
| 480 | // Verify offset to read and number of bytes to read are not exceeding the |
| 481 | // range. |
| 482 | if ((requestData->offset > dcmi::assetTagMaxOffset) || |
| 483 | (requestData->bytes > dcmi::maxBytes) || |
| 484 | ((requestData->offset + requestData->bytes) > dcmi::assetTagMaxSize)) |
| 485 | { |
| 486 | *data_len = 0; |
| 487 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 488 | } |
| 489 | |
| 490 | std::string assetTag; |
| 491 | |
| 492 | try |
| 493 | { |
| 494 | assetTag = dcmi::readAssetTag(); |
| 495 | } |
| 496 | catch (InternalFailure& e) |
| 497 | { |
| 498 | *data_len = 0; |
| 499 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 500 | } |
| 501 | |
| 502 | responseData->groupID = dcmi::groupExtId; |
| 503 | |
| 504 | // Return if the asset tag is not populated. |
| 505 | if (!assetTag.size()) |
| 506 | { |
| 507 | responseData->tagLength = 0; |
| 508 | memcpy(response, outPayload.data(), outPayload.size()); |
| 509 | *data_len = outPayload.size(); |
| 510 | return IPMI_CC_OK; |
| 511 | } |
| 512 | |
| 513 | // If the asset tag is longer than 63 bytes, restrict it to 63 bytes to suit |
| 514 | // Get Asset Tag command. |
| 515 | if (assetTag.size() > dcmi::assetTagMaxSize) |
| 516 | { |
| 517 | assetTag.resize(dcmi::assetTagMaxSize); |
| 518 | } |
| 519 | |
| 520 | // If the requested offset is beyond the asset tag size. |
| 521 | if (requestData->offset >= assetTag.size()) |
| 522 | { |
| 523 | *data_len = 0; |
| 524 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 525 | } |
| 526 | |
| 527 | auto returnData = assetTag.substr(requestData->offset, requestData->bytes); |
| 528 | |
| 529 | responseData->tagLength = assetTag.size(); |
| 530 | |
| 531 | memcpy(response, outPayload.data(), outPayload.size()); |
| 532 | memcpy(static_cast<uint8_t*>(response) + outPayload.size(), |
| 533 | returnData.data(), returnData.size()); |
| 534 | *data_len = outPayload.size() + returnData.size(); |
| 535 | |
| 536 | return IPMI_CC_OK; |
| 537 | } |
| 538 | |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 539 | ipmi_ret_t setAssetTag(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 540 | ipmi_request_t request, ipmi_response_t response, |
| 541 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 542 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 543 | auto requestData = |
| 544 | reinterpret_cast<const dcmi::SetAssetTagRequest*>(request); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 545 | std::vector<uint8_t> outPayload(sizeof(dcmi::SetAssetTagResponse)); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 546 | auto responseData = |
| 547 | reinterpret_cast<dcmi::SetAssetTagResponse*>(outPayload.data()); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 548 | |
| 549 | if (requestData->groupID != dcmi::groupExtId) |
| 550 | { |
| 551 | *data_len = 0; |
| 552 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 553 | } |
| 554 | |
| 555 | // Verify offset to read and number of bytes to read are not exceeding the |
| 556 | // range. |
| 557 | if ((requestData->offset > dcmi::assetTagMaxOffset) || |
| 558 | (requestData->bytes > dcmi::maxBytes) || |
| 559 | ((requestData->offset + requestData->bytes) > dcmi::assetTagMaxSize)) |
| 560 | { |
| 561 | *data_len = 0; |
| 562 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 563 | } |
| 564 | |
| 565 | std::string assetTag; |
| 566 | |
| 567 | try |
| 568 | { |
| 569 | assetTag = dcmi::readAssetTag(); |
| 570 | |
| 571 | if (requestData->offset > assetTag.size()) |
| 572 | { |
| 573 | *data_len = 0; |
| 574 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 575 | } |
| 576 | |
| 577 | assetTag.replace(requestData->offset, |
| 578 | assetTag.size() - requestData->offset, |
| 579 | static_cast<const char*>(request) + |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 580 | sizeof(dcmi::SetAssetTagRequest), |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 581 | requestData->bytes); |
| 582 | |
| 583 | dcmi::writeAssetTag(assetTag); |
| 584 | |
| 585 | responseData->groupID = dcmi::groupExtId; |
| 586 | responseData->tagLength = assetTag.size(); |
| 587 | memcpy(response, outPayload.data(), outPayload.size()); |
| 588 | *data_len = outPayload.size(); |
| 589 | |
| 590 | return IPMI_CC_OK; |
| 591 | } |
| 592 | catch (InternalFailure& e) |
| 593 | { |
| 594 | *data_len = 0; |
| 595 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 596 | } |
| 597 | } |
| 598 | |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 599 | ipmi_ret_t getMgmntCtrlIdStr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 600 | ipmi_request_t request, ipmi_response_t response, |
| 601 | ipmi_data_len_t data_len, ipmi_context_t context) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 602 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 603 | auto requestData = |
| 604 | reinterpret_cast<const dcmi::GetMgmntCtrlIdStrRequest*>(request); |
| 605 | auto responseData = |
| 606 | reinterpret_cast<dcmi::GetMgmntCtrlIdStrResponse*>(response); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 607 | std::string hostName; |
| 608 | |
| 609 | *data_len = 0; |
| 610 | |
| 611 | if (requestData->groupID != dcmi::groupExtId || |
| 612 | requestData->bytes > dcmi::maxBytes || |
| 613 | requestData->offset + requestData->bytes > dcmi::maxCtrlIdStrLen) |
| 614 | { |
| 615 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 616 | } |
| 617 | |
| 618 | try |
| 619 | { |
| 620 | hostName = dcmi::getHostName(); |
| 621 | } |
| 622 | catch (InternalFailure& e) |
| 623 | { |
| 624 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 625 | } |
| 626 | |
| 627 | if (requestData->offset > hostName.length()) |
| 628 | { |
| 629 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 630 | } |
| 631 | auto responseStr = hostName.substr(requestData->offset, requestData->bytes); |
| 632 | auto responseStrLen = std::min(static_cast<std::size_t>(requestData->bytes), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 633 | responseStr.length() + 1); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 634 | responseData->groupID = dcmi::groupExtId; |
| 635 | responseData->strLen = hostName.length(); |
| 636 | std::copy(begin(responseStr), end(responseStr), responseData->data); |
| 637 | |
| 638 | *data_len = sizeof(*responseData) + responseStrLen; |
| 639 | return IPMI_CC_OK; |
| 640 | } |
| 641 | |
| 642 | ipmi_ret_t setMgmntCtrlIdStr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 643 | ipmi_request_t request, ipmi_response_t response, |
| 644 | ipmi_data_len_t data_len, ipmi_context_t context) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 645 | { |
| 646 | static std::array<char, dcmi::maxCtrlIdStrLen + 1> newCtrlIdStr; |
| 647 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 648 | auto requestData = |
| 649 | reinterpret_cast<const dcmi::SetMgmntCtrlIdStrRequest*>(request); |
| 650 | auto responseData = |
| 651 | reinterpret_cast<dcmi::SetMgmntCtrlIdStrResponse*>(response); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 652 | |
| 653 | *data_len = 0; |
| 654 | |
| 655 | if (requestData->groupID != dcmi::groupExtId || |
| 656 | requestData->bytes > dcmi::maxBytes || |
| 657 | requestData->offset + requestData->bytes > dcmi::maxCtrlIdStrLen + 1 || |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 658 | (requestData->offset + requestData->bytes == |
| 659 | dcmi::maxCtrlIdStrLen + 1 && |
| 660 | requestData->data[requestData->bytes - 1] != '\0')) |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 661 | { |
| 662 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 663 | } |
| 664 | |
| 665 | try |
| 666 | { |
| 667 | /* if there is no old value and offset is not 0 */ |
| 668 | if (newCtrlIdStr[0] == '\0' && requestData->offset != 0) |
| 669 | { |
| 670 | /* read old ctrlIdStr */ |
| 671 | auto hostName = dcmi::getHostName(); |
| 672 | hostName.resize(dcmi::maxCtrlIdStrLen); |
| 673 | std::copy(begin(hostName), end(hostName), begin(newCtrlIdStr)); |
| 674 | newCtrlIdStr[hostName.length()] = '\0'; |
| 675 | } |
| 676 | |
| 677 | /* replace part of string and mark byte after the last as \0 */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 678 | auto restStrIter = |
| 679 | std::copy_n(requestData->data, requestData->bytes, |
| 680 | begin(newCtrlIdStr) + requestData->offset); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 681 | /* if the last written byte is not 64th - add '\0' */ |
| 682 | if (requestData->offset + requestData->bytes <= dcmi::maxCtrlIdStrLen) |
| 683 | { |
| 684 | *restStrIter = '\0'; |
| 685 | } |
| 686 | |
| 687 | /* if input data contains '\0' whole string is sent - update hostname */ |
| 688 | auto it = std::find(requestData->data, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 689 | requestData->data + requestData->bytes, '\0'); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 690 | if (it != requestData->data + requestData->bytes) |
| 691 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 692 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 693 | ipmi::setDbusProperty(bus, dcmi::networkServiceName, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 694 | dcmi::networkConfigObj, |
| 695 | dcmi::networkConfigIntf, dcmi::hostNameProp, |
| 696 | std::string(newCtrlIdStr.data())); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | catch (InternalFailure& e) |
| 700 | { |
| 701 | *data_len = 0; |
| 702 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 703 | } |
| 704 | |
| 705 | responseData->groupID = dcmi::groupExtId; |
| 706 | responseData->offset = requestData->offset + requestData->bytes; |
| 707 | *data_len = sizeof(*responseData); |
| 708 | return IPMI_CC_OK; |
| 709 | } |
| 710 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 711 | // List of the capabilities under each parameter |
| 712 | dcmi::DCMICaps dcmiCaps = { |
| 713 | // Supported DCMI Capabilities |
| 714 | {dcmi::DCMICapParameters::SUPPORTED_DCMI_CAPS, |
| 715 | {3, |
| 716 | {{"PowerManagement", 2, 0, 1}, |
| 717 | {"OOBSecondaryLan", 3, 2, 1}, |
| 718 | {"SerialTMODE", 3, 1, 1}, |
| 719 | {"InBandSystemInterfaceChannel", 3, 0, 1}}}}, |
| 720 | // Mandatory Platform Attributes |
| 721 | {dcmi::DCMICapParameters::MANDATORY_PLAT_ATTRIBUTES, |
| 722 | {5, |
| 723 | {{"SELAutoRollOver", 1, 15, 1}, |
| 724 | {"FlushEntireSELUponRollOver", 1, 14, 1}, |
| 725 | {"RecordLevelSELFlushUponRollOver", 1, 13, 1}, |
| 726 | {"NumberOfSELEntries", 1, 0, 12}, |
| 727 | {"TempMonitoringSamplingFreq", 5, 0, 8}}}}, |
| 728 | // Optional Platform Attributes |
| 729 | {dcmi::DCMICapParameters::OPTIONAL_PLAT_ATTRIBUTES, |
| 730 | {2, |
| 731 | {{"PowerMgmtDeviceSlaveAddress", 1, 1, 7}, |
| 732 | {"BMCChannelNumber", 2, 4, 4}, |
| 733 | {"DeviceRivision", 2, 0, 4}}}}, |
| 734 | // Manageability Access Attributes |
| 735 | {dcmi::DCMICapParameters::MANAGEABILITY_ACCESS_ATTRIBUTES, |
| 736 | {3, |
| 737 | {{"MandatoryPrimaryLanOOBSupport", 1, 0, 8}, |
| 738 | {"OptionalSecondaryLanOOBSupport", 2, 0, 8}, |
| 739 | {"OptionalSerialOOBMTMODECapability", 3, 0, 8}}}}}; |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 740 | |
| 741 | ipmi_ret_t getDCMICapabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 742 | ipmi_request_t request, ipmi_response_t response, |
| 743 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 744 | { |
| 745 | |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 746 | std::ifstream dcmiCapFile(dcmi::gDCMICapabilitiesConfig); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 747 | if (!dcmiCapFile.is_open()) |
| 748 | { |
| 749 | log<level::ERR>("DCMI Capabilities file not found"); |
| 750 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 751 | } |
| 752 | |
| 753 | auto data = nlohmann::json::parse(dcmiCapFile, nullptr, false); |
| 754 | if (data.is_discarded()) |
| 755 | { |
| 756 | log<level::ERR>("DCMI Capabilities JSON parser failure"); |
| 757 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 758 | } |
| 759 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 760 | auto requestData = |
| 761 | reinterpret_cast<const dcmi::GetDCMICapRequest*>(request); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 762 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 763 | // get list of capabilities in a parameter |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 764 | auto caps = |
| 765 | dcmiCaps.find(static_cast<dcmi::DCMICapParameters>(requestData->param)); |
| 766 | if (caps == dcmiCaps.end()) |
| 767 | { |
| 768 | log<level::ERR>("Invalid input parameter"); |
| 769 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 770 | } |
| 771 | |
| 772 | if (requestData->groupID != dcmi::groupExtId) |
| 773 | { |
| 774 | *data_len = 0; |
| 775 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 776 | } |
| 777 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 778 | auto responseData = reinterpret_cast<dcmi::GetDCMICapResponse*>(response); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 779 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 780 | // For each capabilities in a parameter fill the data from |
| 781 | // the json file based on the capability name. |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 782 | for (auto cap : caps->second.capList) |
| 783 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 784 | // If the data is beyond first byte boundary, insert in a |
| 785 | // 16bit pattern for example number of SEL entries are represented |
| 786 | // in 12bits. |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 787 | if ((cap.length + cap.position) > 8) |
| 788 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 789 | // Read the value corresponding to capability name and assign to |
| 790 | // 16bit bitset. |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 791 | std::bitset<16> val(data.value(cap.name.c_str(), 0)); |
| 792 | val <<= cap.position; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 793 | reinterpret_cast<uint16_t*>( |
| 794 | responseData |
| 795 | ->data)[(cap.bytePosition - 1) / sizeof(uint16_t)] |= |
| 796 | val.to_ulong(); |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 797 | } |
| 798 | else |
| 799 | { |
| 800 | responseData->data[cap.bytePosition - 1] |= |
| 801 | data.value(cap.name.c_str(), 0) << cap.position; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | responseData->groupID = dcmi::groupExtId; |
| 806 | responseData->major = DCMI_SPEC_MAJOR_VERSION; |
| 807 | responseData->minor = DCMI_SPEC_MINOR_VERSION; |
| 808 | responseData->paramRevision = DCMI_PARAMETER_REVISION; |
| 809 | *data_len = sizeof(*responseData) + caps->second.size; |
| 810 | |
| 811 | return IPMI_CC_OK; |
| 812 | } |
| 813 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 814 | namespace dcmi |
| 815 | { |
| 816 | namespace temp_readings |
| 817 | { |
| 818 | |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 819 | Temperature readTemp(const std::string& dbusService, |
| 820 | const std::string& dbusPath) |
| 821 | { |
| 822 | // Read the temperature value from d-bus object. Need some conversion. |
| 823 | // As per the interface xyz.openbmc_project.Sensor.Value, the temperature |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 824 | // is an double and in degrees C. It needs to be scaled by using the |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 825 | // formula Value * 10^Scale. The ipmi spec has the temperature as a uint8_t, |
| 826 | // with a separate single bit for the sign. |
| 827 | |
| 828 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 829 | auto result = ipmi::getAllDbusProperties( |
| 830 | bus, dbusService, dbusPath, "xyz.openbmc_project.Sensor.Value"); |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 831 | auto temperature = sdbusplus::message::variant_ns::visit( |
| 832 | ipmi::VariantToDoubleVisitor(), result.at("Value")); |
| 833 | double absTemp = std::abs(temperature); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 834 | |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 835 | auto findFactor = result.find("Scale"); |
| 836 | double factor = 0.0; |
| 837 | if (findFactor != result.end()) |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 838 | { |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 839 | factor = sdbusplus::message::variant_ns::visit( |
| 840 | ipmi::VariantToDoubleVisitor(), findFactor->second); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 841 | } |
James Feist | 9cc0ea5 | 2018-10-09 10:53:11 -0700 | [diff] [blame] | 842 | double scale = std::pow(10, factor); |
| 843 | |
| 844 | auto tempDegrees = absTemp * scale; |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 845 | // Max absolute temp as per ipmi spec is 128. |
| 846 | if (tempDegrees > maxTemp) |
| 847 | { |
| 848 | tempDegrees = maxTemp; |
| 849 | } |
| 850 | |
| 851 | return std::make_tuple(static_cast<uint8_t>(tempDegrees), |
| 852 | (temperature < 0)); |
| 853 | } |
| 854 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 855 | std::tuple<Response, NumInstances> read(const std::string& type, |
| 856 | uint8_t instance) |
| 857 | { |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 858 | Response response{}; |
| 859 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 860 | |
| 861 | if (!instance) |
| 862 | { |
| 863 | log<level::ERR>("Expected non-zero instance"); |
| 864 | elog<InternalFailure>(); |
| 865 | } |
| 866 | |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 867 | auto data = parseJSONConfig(gDCMISensorsConfig); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 868 | static const std::vector<Json> empty{}; |
| 869 | std::vector<Json> readings = data.value(type, empty); |
| 870 | size_t numInstances = readings.size(); |
| 871 | for (const auto& j : readings) |
| 872 | { |
| 873 | uint8_t instanceNum = j.value("instance", 0); |
| 874 | // Not the instance we're interested in |
| 875 | if (instanceNum != instance) |
| 876 | { |
| 877 | continue; |
| 878 | } |
| 879 | |
| 880 | std::string path = j.value("dbus", ""); |
| 881 | std::string service; |
| 882 | try |
| 883 | { |
| 884 | service = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 885 | ipmi::getService(bus, "xyz.openbmc_project.Sensor.Value", path); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 886 | } |
| 887 | catch (std::exception& e) |
| 888 | { |
| 889 | log<level::DEBUG>(e.what()); |
| 890 | return std::make_tuple(response, numInstances); |
| 891 | } |
| 892 | |
| 893 | response.instance = instance; |
| 894 | uint8_t temp{}; |
| 895 | bool sign{}; |
| 896 | std::tie(temp, sign) = readTemp(service, path); |
| 897 | response.temperature = temp; |
| 898 | response.sign = sign; |
| 899 | |
| 900 | // Found the instance we're interested in |
| 901 | break; |
| 902 | } |
| 903 | |
| 904 | if (numInstances > maxInstances) |
| 905 | { |
| 906 | numInstances = maxInstances; |
| 907 | } |
| 908 | return std::make_tuple(response, numInstances); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | std::tuple<ResponseList, NumInstances> readAll(const std::string& type, |
| 912 | uint8_t instanceStart) |
| 913 | { |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 914 | ResponseList response{}; |
| 915 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 916 | |
| 917 | size_t numInstances = 0; |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 918 | auto data = parseJSONConfig(gDCMISensorsConfig); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 919 | static const std::vector<Json> empty{}; |
| 920 | std::vector<Json> readings = data.value(type, empty); |
| 921 | numInstances = readings.size(); |
| 922 | for (const auto& j : readings) |
| 923 | { |
| 924 | try |
| 925 | { |
| 926 | // Max of 8 response data sets |
| 927 | if (response.size() == maxDataSets) |
| 928 | { |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | uint8_t instanceNum = j.value("instance", 0); |
| 933 | // Not in the instance range we're interested in |
| 934 | if (instanceNum < instanceStart) |
| 935 | { |
| 936 | continue; |
| 937 | } |
| 938 | |
| 939 | std::string path = j.value("dbus", ""); |
| 940 | auto service = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 941 | ipmi::getService(bus, "xyz.openbmc_project.Sensor.Value", path); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 942 | |
| 943 | Response r{}; |
| 944 | r.instance = instanceNum; |
| 945 | uint8_t temp{}; |
| 946 | bool sign{}; |
| 947 | std::tie(temp, sign) = readTemp(service, path); |
| 948 | r.temperature = temp; |
| 949 | r.sign = sign; |
| 950 | response.push_back(r); |
| 951 | } |
| 952 | catch (std::exception& e) |
| 953 | { |
| 954 | log<level::DEBUG>(e.what()); |
| 955 | continue; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | if (numInstances > maxInstances) |
| 960 | { |
| 961 | numInstances = maxInstances; |
| 962 | } |
| 963 | return std::make_tuple(response, numInstances); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 964 | } |
| 965 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 966 | } // namespace temp_readings |
| 967 | } // namespace dcmi |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 968 | |
| 969 | ipmi_ret_t getTempReadings(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 970 | ipmi_request_t request, ipmi_response_t response, |
| 971 | ipmi_data_len_t data_len, ipmi_context_t context) |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 972 | { |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 973 | auto requestData = |
| 974 | reinterpret_cast<const dcmi::GetTempReadingsRequest*>(request); |
| 975 | auto responseData = |
| 976 | reinterpret_cast<dcmi::GetTempReadingsResponseHdr*>(response); |
| 977 | |
| 978 | if (*data_len != sizeof(dcmi::GetTempReadingsRequest)) |
| 979 | { |
| 980 | log<level::ERR>("Malformed request data", |
| 981 | entry("DATA_SIZE=%d", *data_len)); |
| 982 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 983 | } |
| 984 | *data_len = 0; |
| 985 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 986 | auto it = dcmi::entityIdToName.find(requestData->entityId); |
| 987 | if (it == dcmi::entityIdToName.end()) |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 988 | { |
| 989 | log<level::ERR>("Unknown Entity ID", |
| 990 | entry("ENTITY_ID=%d", requestData->entityId)); |
| 991 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 992 | } |
| 993 | |
| 994 | if (requestData->groupID != dcmi::groupExtId) |
| 995 | { |
| 996 | log<level::ERR>("Invalid Group ID", |
| 997 | entry("GROUP_ID=%d", requestData->groupID)); |
| 998 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 999 | } |
| 1000 | |
| 1001 | if (requestData->sensorType != dcmi::temperatureSensorType) |
| 1002 | { |
| 1003 | log<level::ERR>("Invalid sensor type", |
| 1004 | entry("SENSOR_TYPE=%d", requestData->sensorType)); |
| 1005 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1006 | } |
| 1007 | |
| 1008 | dcmi::temp_readings::ResponseList temps{}; |
| 1009 | try |
| 1010 | { |
| 1011 | if (!requestData->entityInstance) |
| 1012 | { |
| 1013 | // Read all instances |
| 1014 | std::tie(temps, responseData->numInstances) = |
| 1015 | dcmi::temp_readings::readAll(it->second, |
| 1016 | requestData->instanceStart); |
| 1017 | } |
| 1018 | else |
| 1019 | { |
| 1020 | // Read one instance |
| 1021 | temps.resize(1); |
| 1022 | std::tie(temps[0], responseData->numInstances) = |
| 1023 | dcmi::temp_readings::read(it->second, |
| 1024 | requestData->entityInstance); |
| 1025 | } |
| 1026 | responseData->numDataSets = temps.size(); |
| 1027 | } |
| 1028 | catch (InternalFailure& e) |
| 1029 | { |
| 1030 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1031 | } |
| 1032 | |
| 1033 | responseData->groupID = dcmi::groupExtId; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1034 | size_t payloadSize = temps.size() * sizeof(dcmi::temp_readings::Response); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1035 | if (!temps.empty()) |
| 1036 | { |
| 1037 | memcpy(responseData + 1, // copy payload right after the response header |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1038 | temps.data(), payloadSize); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1039 | } |
| 1040 | *data_len = sizeof(dcmi::GetTempReadingsResponseHdr) + payloadSize; |
| 1041 | |
| 1042 | return IPMI_CC_OK; |
| 1043 | } |
| 1044 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1045 | int64_t getPowerReading(sdbusplus::bus::bus& bus) |
| 1046 | { |
| 1047 | std::ifstream sensorFile(POWER_READING_SENSOR); |
| 1048 | std::string objectPath; |
| 1049 | if (!sensorFile.is_open()) |
| 1050 | { |
| 1051 | log<level::ERR>("Power reading configuration file not found", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1052 | entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR)); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1053 | elog<InternalFailure>(); |
| 1054 | } |
| 1055 | |
| 1056 | auto data = nlohmann::json::parse(sensorFile, nullptr, false); |
| 1057 | if (data.is_discarded()) |
| 1058 | { |
| 1059 | log<level::ERR>("Error in parsing configuration file", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1060 | entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR)); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1061 | elog<InternalFailure>(); |
| 1062 | } |
| 1063 | |
| 1064 | objectPath = data.value("path", ""); |
| 1065 | if (objectPath.empty()) |
| 1066 | { |
| 1067 | log<level::ERR>("Power sensor D-Bus object path is empty", |
| 1068 | entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR)); |
| 1069 | elog<InternalFailure>(); |
| 1070 | } |
| 1071 | |
Marri Devender Rao | ce6a795 | 2018-02-11 08:45:00 -0600 | [diff] [blame] | 1072 | // Return default value if failed to read from D-Bus object |
| 1073 | int64_t power = 0; |
| 1074 | try |
| 1075 | { |
| 1076 | auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1077 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1078 | // Read the sensor value and scale properties |
| 1079 | auto properties = ipmi::getAllDbusProperties(bus, service, objectPath, |
| 1080 | SENSOR_VALUE_INTF); |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 1081 | auto value = variant_ns::get<int64_t>(properties[SENSOR_VALUE_PROP]); |
| 1082 | auto scale = variant_ns::get<int64_t>(properties[SENSOR_SCALE_PROP]); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1083 | |
Marri Devender Rao | ce6a795 | 2018-02-11 08:45:00 -0600 | [diff] [blame] | 1084 | // Power reading needs to be scaled with the Scale value using the |
| 1085 | // formula Value * 10^Scale. |
| 1086 | power = value * std::pow(10, scale); |
| 1087 | } |
| 1088 | catch (std::exception& e) |
| 1089 | { |
| 1090 | log<level::INFO>("Failure to read power value from D-Bus object", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1091 | entry("OBJECT_PATH=%s", objectPath.c_str()), |
| 1092 | entry("INTERFACE=%s", SENSOR_VALUE_INTF)); |
Marri Devender Rao | ce6a795 | 2018-02-11 08:45:00 -0600 | [diff] [blame] | 1093 | } |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1094 | return power; |
| 1095 | } |
| 1096 | |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1097 | ipmi_ret_t setDCMIConfParams(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1098 | ipmi_request_t request, ipmi_response_t response, |
| 1099 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 1100 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1101 | auto requestData = |
| 1102 | reinterpret_cast<const dcmi::SetConfParamsRequest*>(request); |
| 1103 | auto responseData = |
| 1104 | reinterpret_cast<dcmi::SetConfParamsResponse*>(response); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1105 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1106 | if (requestData->groupID != dcmi::groupExtId || |
| 1107 | *data_len < DCMI_SET_CONF_PARAM_REQ_PACKET_MIN_SIZE || |
| 1108 | *data_len > DCMI_SET_CONF_PARAM_REQ_PACKET_MAX_SIZE) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1109 | { |
Gunnar Mills | 8466b79 | 2018-03-23 12:18:12 -0500 | [diff] [blame] | 1110 | log<level::ERR>("Invalid Group ID or Invalid Requested Packet size", |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1111 | entry("GROUP_ID=%d", requestData->groupID), |
| 1112 | entry("PACKET SIZE=%d", *data_len)); |
| 1113 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1114 | } |
| 1115 | |
| 1116 | *data_len = 0; |
| 1117 | |
| 1118 | try |
| 1119 | { |
| 1120 | // Take action based on the Parameter Selector |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1121 | switch ( |
| 1122 | static_cast<dcmi::DCMIConfigParameters>(requestData->paramSelect)) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1123 | { |
| 1124 | case dcmi::DCMIConfigParameters::ActivateDHCP: |
| 1125 | |
| 1126 | if ((requestData->data[0] & DCMI_ACTIVATE_DHCP_MASK) && |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1127 | dcmi::getDHCPEnabled()) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1128 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1129 | // When these conditions are met we have to trigger DHCP |
| 1130 | // protocol restart using the latest parameter settings, but |
| 1131 | // as per n/w manager design, each time when we update n/w |
| 1132 | // parameters, n/w service is restarted. So we no need to |
| 1133 | // take any action in this case. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1134 | } |
| 1135 | break; |
| 1136 | |
| 1137 | case dcmi::DCMIConfigParameters::DiscoveryConfig: |
| 1138 | |
| 1139 | if (requestData->data[0] & DCMI_OPTION_12_MASK) |
| 1140 | { |
| 1141 | dcmi::setDHCPOption(DHCP_OPT12_ENABLED, true); |
| 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | dcmi::setDHCPOption(DHCP_OPT12_ENABLED, false); |
| 1146 | } |
| 1147 | |
| 1148 | // Systemd-networkd doesn't support Random Back off |
| 1149 | if (requestData->data[0] & DCMI_RAND_BACK_OFF_MASK) |
| 1150 | { |
| 1151 | return IPMI_CC_INVALID; |
| 1152 | } |
| 1153 | break; |
| 1154 | // Systemd-networkd doesn't allow to configure DHCP timigs |
| 1155 | case dcmi::DCMIConfigParameters::DHCPTiming1: |
| 1156 | case dcmi::DCMIConfigParameters::DHCPTiming2: |
| 1157 | case dcmi::DCMIConfigParameters::DHCPTiming3: |
| 1158 | default: |
| 1159 | return IPMI_CC_INVALID; |
| 1160 | } |
| 1161 | } |
| 1162 | catch (std::exception& e) |
| 1163 | { |
| 1164 | log<level::ERR>(e.what()); |
| 1165 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1166 | } |
| 1167 | responseData->groupID = dcmi::groupExtId; |
| 1168 | *data_len = sizeof(dcmi::SetConfParamsResponse); |
| 1169 | |
| 1170 | return IPMI_CC_OK; |
| 1171 | } |
| 1172 | |
| 1173 | ipmi_ret_t getDCMIConfParams(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1174 | ipmi_request_t request, ipmi_response_t response, |
| 1175 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 1176 | { |
| 1177 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1178 | auto requestData = |
| 1179 | reinterpret_cast<const dcmi::GetConfParamsRequest*>(request); |
| 1180 | auto responseData = |
| 1181 | reinterpret_cast<dcmi::GetConfParamsResponse*>(response); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1182 | |
| 1183 | responseData->data[0] = 0x00; |
| 1184 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1185 | if (requestData->groupID != dcmi::groupExtId || |
| 1186 | *data_len != sizeof(dcmi::GetConfParamsRequest)) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1187 | { |
Gunnar Mills | 8466b79 | 2018-03-23 12:18:12 -0500 | [diff] [blame] | 1188 | log<level::ERR>("Invalid Group ID or Invalid Requested Packet size", |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1189 | entry("GROUP_ID=%d", requestData->groupID), |
| 1190 | entry("PACKET SIZE=%d", *data_len)); |
| 1191 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1192 | } |
| 1193 | |
| 1194 | *data_len = 0; |
| 1195 | |
| 1196 | try |
| 1197 | { |
| 1198 | // Take action based on the Parameter Selector |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1199 | switch ( |
| 1200 | static_cast<dcmi::DCMIConfigParameters>(requestData->paramSelect)) |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1201 | { |
| 1202 | case dcmi::DCMIConfigParameters::ActivateDHCP: |
| 1203 | responseData->data[0] = DCMI_ACTIVATE_DHCP_REPLY; |
| 1204 | *data_len = sizeof(dcmi::GetConfParamsResponse) + 1; |
| 1205 | break; |
| 1206 | case dcmi::DCMIConfigParameters::DiscoveryConfig: |
| 1207 | if (dcmi::getDHCPOption(DHCP_OPT12_ENABLED)) |
| 1208 | { |
| 1209 | responseData->data[0] |= DCMI_OPTION_12_MASK; |
| 1210 | } |
| 1211 | *data_len = sizeof(dcmi::GetConfParamsResponse) + 1; |
| 1212 | break; |
| 1213 | // Get below values from Systemd-networkd source code |
| 1214 | case dcmi::DCMIConfigParameters::DHCPTiming1: |
| 1215 | responseData->data[0] = DHCP_TIMING1; |
| 1216 | *data_len = sizeof(dcmi::GetConfParamsResponse) + 1; |
| 1217 | break; |
| 1218 | case dcmi::DCMIConfigParameters::DHCPTiming2: |
| 1219 | responseData->data[0] = DHCP_TIMING2_LOWER; |
| 1220 | responseData->data[1] = DHCP_TIMING2_UPPER; |
| 1221 | *data_len = sizeof(dcmi::GetConfParamsResponse) + 2; |
| 1222 | break; |
| 1223 | case dcmi::DCMIConfigParameters::DHCPTiming3: |
| 1224 | responseData->data[0] = DHCP_TIMING3_LOWER; |
| 1225 | responseData->data[1] = DHCP_TIMING3_UPPER; |
| 1226 | *data_len = sizeof(dcmi::GetConfParamsResponse) + 2; |
| 1227 | break; |
| 1228 | default: |
| 1229 | *data_len = 0; |
| 1230 | return IPMI_CC_INVALID; |
| 1231 | } |
| 1232 | } |
| 1233 | catch (std::exception& e) |
| 1234 | { |
| 1235 | log<level::ERR>(e.what()); |
| 1236 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1237 | } |
| 1238 | |
| 1239 | responseData->groupID = dcmi::groupExtId; |
| 1240 | responseData->major = DCMI_SPEC_MAJOR_VERSION; |
| 1241 | responseData->minor = DCMI_SPEC_MINOR_VERSION; |
| 1242 | responseData->paramRevision = DCMI_CONFIG_PARAMETER_REVISION; |
| 1243 | |
| 1244 | return IPMI_CC_OK; |
| 1245 | } |
| 1246 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1247 | ipmi_ret_t getPowerReading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1248 | ipmi_request_t request, ipmi_response_t response, |
| 1249 | ipmi_data_len_t data_len, ipmi_context_t context) |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1250 | { |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 1251 | if (!dcmi::isDCMIPowerMgmtSupported()) |
| 1252 | { |
| 1253 | *data_len = 0; |
| 1254 | log<level::ERR>("DCMI Power management is unsupported!"); |
| 1255 | return IPMI_CC_INVALID; |
| 1256 | } |
| 1257 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1258 | ipmi_ret_t rc = IPMI_CC_OK; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1259 | auto requestData = |
| 1260 | reinterpret_cast<const dcmi::GetPowerReadingRequest*>(request); |
| 1261 | auto responseData = |
| 1262 | reinterpret_cast<dcmi::GetPowerReadingResponse*>(response); |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1263 | |
| 1264 | if (requestData->groupID != dcmi::groupExtId) |
| 1265 | { |
| 1266 | *data_len = 0; |
| 1267 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1268 | } |
| 1269 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1270 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1271 | int64_t power = 0; |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1272 | try |
| 1273 | { |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1274 | power = getPowerReading(bus); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1275 | } |
| 1276 | catch (InternalFailure& e) |
| 1277 | { |
| 1278 | log<level::ERR>("Error in reading power sensor value", |
| 1279 | entry("INTERFACE=%s", SENSOR_VALUE_INTF), |
| 1280 | entry("PROPERTY=%s", SENSOR_VALUE_PROP)); |
| 1281 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1282 | } |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1283 | responseData->groupID = dcmi::groupExtId; |
| 1284 | |
| 1285 | // TODO: openbmc/openbmc#2819 |
Gunnar Mills | 8466b79 | 2018-03-23 12:18:12 -0500 | [diff] [blame] | 1286 | // Minimum, Maximum, Average power, TimeFrame, TimeStamp, |
Marri Devender Rao | 9c966e0 | 2018-01-22 05:55:10 -0600 | [diff] [blame] | 1287 | // PowerReadingState readings need to be populated |
| 1288 | // after Telemetry changes. |
| 1289 | uint16_t totalPower = static_cast<uint16_t>(power); |
| 1290 | responseData->currentPower = totalPower; |
| 1291 | responseData->minimumPower = totalPower; |
| 1292 | responseData->maximumPower = totalPower; |
| 1293 | responseData->averagePower = totalPower; |
| 1294 | |
| 1295 | *data_len = sizeof(*responseData); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1296 | return rc; |
| 1297 | } |
| 1298 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1299 | namespace dcmi |
| 1300 | { |
| 1301 | namespace sensor_info |
| 1302 | { |
| 1303 | |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1304 | Response createFromJson(const Json& config) |
| 1305 | { |
| 1306 | Response response{}; |
| 1307 | uint16_t recordId = config.value("record_id", 0); |
| 1308 | response.recordIdLsb = recordId & 0xFF; |
| 1309 | response.recordIdMsb = (recordId >> 8) & 0xFF; |
| 1310 | return response; |
| 1311 | } |
| 1312 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1313 | std::tuple<Response, NumInstances> read(const std::string& type, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1314 | uint8_t instance, const Json& config) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1315 | { |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1316 | Response response{}; |
| 1317 | |
| 1318 | if (!instance) |
| 1319 | { |
| 1320 | log<level::ERR>("Expected non-zero instance"); |
| 1321 | elog<InternalFailure>(); |
| 1322 | } |
| 1323 | |
| 1324 | static const std::vector<Json> empty{}; |
| 1325 | std::vector<Json> readings = config.value(type, empty); |
| 1326 | size_t numInstances = readings.size(); |
| 1327 | for (const auto& reading : readings) |
| 1328 | { |
| 1329 | uint8_t instanceNum = reading.value("instance", 0); |
| 1330 | // Not the instance we're interested in |
| 1331 | if (instanceNum != instance) |
| 1332 | { |
| 1333 | continue; |
| 1334 | } |
| 1335 | |
| 1336 | response = createFromJson(reading); |
| 1337 | |
| 1338 | // Found the instance we're interested in |
| 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | if (numInstances > maxInstances) |
| 1343 | { |
| 1344 | log<level::DEBUG>("Trimming IPMI num instances", |
| 1345 | entry("NUM_INSTANCES=%d", numInstances)); |
| 1346 | numInstances = maxInstances; |
| 1347 | } |
| 1348 | return std::make_tuple(response, numInstances); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1349 | } |
| 1350 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1351 | std::tuple<ResponseList, NumInstances> |
| 1352 | readAll(const std::string& type, uint8_t instanceStart, const Json& config) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1353 | { |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 1354 | ResponseList responses{}; |
| 1355 | |
| 1356 | size_t numInstances = 0; |
| 1357 | static const std::vector<Json> empty{}; |
| 1358 | std::vector<Json> readings = config.value(type, empty); |
| 1359 | numInstances = readings.size(); |
| 1360 | for (const auto& reading : readings) |
| 1361 | { |
| 1362 | try |
| 1363 | { |
| 1364 | // Max of 8 records |
| 1365 | if (responses.size() == maxRecords) |
| 1366 | { |
| 1367 | break; |
| 1368 | } |
| 1369 | |
| 1370 | uint8_t instanceNum = reading.value("instance", 0); |
| 1371 | // Not in the instance range we're interested in |
| 1372 | if (instanceNum < instanceStart) |
| 1373 | { |
| 1374 | continue; |
| 1375 | } |
| 1376 | |
| 1377 | Response response = createFromJson(reading); |
| 1378 | responses.push_back(response); |
| 1379 | } |
| 1380 | catch (std::exception& e) |
| 1381 | { |
| 1382 | log<level::DEBUG>(e.what()); |
| 1383 | continue; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | if (numInstances > maxInstances) |
| 1388 | { |
| 1389 | log<level::DEBUG>("Trimming IPMI num instances", |
| 1390 | entry("NUM_INSTANCES=%d", numInstances)); |
| 1391 | numInstances = maxInstances; |
| 1392 | } |
| 1393 | return std::make_tuple(responses, numInstances); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | } // namespace sensor_info |
| 1397 | } // namespace dcmi |
| 1398 | |
| 1399 | ipmi_ret_t getSensorInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1400 | ipmi_request_t request, ipmi_response_t response, |
| 1401 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 1402 | { |
| 1403 | auto requestData = |
| 1404 | reinterpret_cast<const dcmi::GetSensorInfoRequest*>(request); |
| 1405 | auto responseData = |
| 1406 | reinterpret_cast<dcmi::GetSensorInfoResponseHdr*>(response); |
| 1407 | |
| 1408 | if (*data_len != sizeof(dcmi::GetSensorInfoRequest)) |
| 1409 | { |
| 1410 | log<level::ERR>("Malformed request data", |
| 1411 | entry("DATA_SIZE=%d", *data_len)); |
| 1412 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1413 | } |
| 1414 | *data_len = 0; |
| 1415 | |
| 1416 | auto it = dcmi::entityIdToName.find(requestData->entityId); |
| 1417 | if (it == dcmi::entityIdToName.end()) |
| 1418 | { |
| 1419 | log<level::ERR>("Unknown Entity ID", |
| 1420 | entry("ENTITY_ID=%d", requestData->entityId)); |
| 1421 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1422 | } |
| 1423 | |
| 1424 | if (requestData->groupID != dcmi::groupExtId) |
| 1425 | { |
| 1426 | log<level::ERR>("Invalid Group ID", |
| 1427 | entry("GROUP_ID=%d", requestData->groupID)); |
| 1428 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1429 | } |
| 1430 | |
| 1431 | if (requestData->sensorType != dcmi::temperatureSensorType) |
| 1432 | { |
| 1433 | log<level::ERR>("Invalid sensor type", |
| 1434 | entry("SENSOR_TYPE=%d", requestData->sensorType)); |
| 1435 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1436 | } |
| 1437 | |
| 1438 | dcmi::sensor_info::ResponseList sensors{}; |
| 1439 | static dcmi::Json config{}; |
| 1440 | static bool parsed = false; |
| 1441 | |
| 1442 | try |
| 1443 | { |
| 1444 | if (!parsed) |
| 1445 | { |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 1446 | config = dcmi::parseJSONConfig(dcmi::gDCMISensorsConfig); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1447 | parsed = true; |
| 1448 | } |
| 1449 | |
| 1450 | if (!requestData->entityInstance) |
| 1451 | { |
| 1452 | // Read all instances |
| 1453 | std::tie(sensors, responseData->numInstances) = |
| 1454 | dcmi::sensor_info::readAll(it->second, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1455 | requestData->instanceStart, config); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1456 | } |
| 1457 | else |
| 1458 | { |
| 1459 | // Read one instance |
| 1460 | sensors.resize(1); |
| 1461 | std::tie(sensors[0], responseData->numInstances) = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1462 | dcmi::sensor_info::read(it->second, requestData->entityInstance, |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1463 | config); |
| 1464 | } |
| 1465 | responseData->numRecords = sensors.size(); |
| 1466 | } |
| 1467 | catch (InternalFailure& e) |
| 1468 | { |
| 1469 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1470 | } |
| 1471 | |
| 1472 | responseData->groupID = dcmi::groupExtId; |
| 1473 | size_t payloadSize = sensors.size() * sizeof(dcmi::sensor_info::Response); |
| 1474 | if (!sensors.empty()) |
| 1475 | { |
| 1476 | memcpy(responseData + 1, // copy payload right after the response header |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1477 | sensors.data(), payloadSize); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1478 | } |
| 1479 | *data_len = sizeof(dcmi::GetSensorInfoResponseHdr) + payloadSize; |
| 1480 | |
| 1481 | return IPMI_CC_OK; |
| 1482 | } |
| 1483 | |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 1484 | void register_netfn_dcmi_functions() |
| 1485 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1486 | // <Get Power Limit> |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 1487 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1488 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_POWER_LIMIT, NULL, |
| 1489 | getPowerLimit, PRIVILEGE_USER); |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 1490 | |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 1491 | // <Set Power Limit> |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 1492 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1493 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_POWER_LIMIT, NULL, |
| 1494 | setPowerLimit, PRIVILEGE_OPERATOR); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 1495 | |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 1496 | // <Activate/Deactivate Power Limit> |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 1497 | |
| 1498 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::APPLY_POWER_LIMIT, |
| 1499 | NULL, applyPowerLimit, PRIVILEGE_OPERATOR); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 1500 | |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 1501 | // <Get Asset Tag> |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 1502 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1503 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_ASSET_TAG, NULL, |
| 1504 | getAssetTag, PRIVILEGE_USER); |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 1505 | |
| 1506 | // <Set Asset Tag> |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 1507 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1508 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_ASSET_TAG, NULL, |
| 1509 | setAssetTag, PRIVILEGE_OPERATOR); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1510 | |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 1511 | // <Get Management Controller Identifier String> |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1512 | |
| 1513 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_MGMNT_CTRL_ID_STR, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1514 | NULL, getMgmntCtrlIdStr, PRIVILEGE_USER); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1515 | |
| 1516 | // <Set Management Controller Identifier String> |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1517 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_MGMNT_CTRL_ID_STR, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1518 | NULL, setMgmntCtrlIdStr, PRIVILEGE_ADMIN); |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 1519 | |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 1520 | // <Get DCMI capabilities> |
| 1521 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_CAPABILITIES, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1522 | NULL, getDCMICapabilities, PRIVILEGE_USER); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 1523 | |
| 1524 | // <Get Temperature Readings> |
| 1525 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_TEMP_READINGS, |
| 1526 | NULL, getTempReadings, PRIVILEGE_USER); |
| 1527 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 1528 | // <Get Power Reading> |
| 1529 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_POWER_READING, |
| 1530 | NULL, getPowerReading, PRIVILEGE_USER); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1531 | |
| 1532 | // <Get Sensor Info> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1533 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_SENSOR_INFO, NULL, |
| 1534 | getSensorInfo, PRIVILEGE_USER); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 1535 | |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1536 | // <Get DCMI Configuration Parameters> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1537 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_CONF_PARAMS, NULL, |
| 1538 | getDCMIConfParams, PRIVILEGE_USER); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1539 | |
| 1540 | // <Set DCMI Configuration Parameters> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1541 | ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_CONF_PARAMS, NULL, |
| 1542 | setDCMIConfParams, PRIVILEGE_ADMIN); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 1543 | |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 1544 | return; |
| 1545 | } |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1546 | // 956379 |