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