blob: e9cc39accdc7d2e39c8060e05ee99cab3d0fc703 [file] [log] [blame]
Patrick Venture0b02be92018-08-31 11:55:55 -07001#include "config.h"
2
Tom Josephbe5eaa12017-07-12 19:54:44 +05303#include "dcmihandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Johnathan Mantey74a21022018-12-13 13:17:56 -08005#include "user_channel/channel_layer.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include "utils.hpp"
7
William A. Kennington III194375f2018-12-14 02:14:33 -08008#include <ipmid/api.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07009
10#include <bitset>
11#include <cmath>
12#include <fstream>
13#include <nlohmann/json.hpp>
Tom Josephbe5eaa12017-07-12 19:54:44 +053014#include <phosphor-logging/elog-errors.hpp>
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050015#include <phosphor-logging/log.hpp>
16#include <sdbusplus/bus.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070017#include <sdbusplus/message/types.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070018#include <xyz/openbmc_project/Common/error.hpp>
19
Tom Josephbe5eaa12017-07-12 19:54:44 +053020using namespace phosphor::logging;
21using InternalFailure =
Patrick Venture0b02be92018-08-31 11:55:55 -070022 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Chris Austen1810bec2015-10-13 12:12:39 -050023
24void register_netfn_dcmi_functions() __attribute__((constructor));
25
Patrick Venture0b02be92018-08-31 11:55:55 -070026constexpr auto PCAP_PATH = "/xyz/openbmc_project/control/host0/power_cap";
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050027constexpr auto PCAP_INTERFACE = "xyz.openbmc_project.Control.Power.Cap";
28
29constexpr auto POWER_CAP_PROP = "PowerCap";
30constexpr auto POWER_CAP_ENABLE_PROP = "PowerCapEnable";
31
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -060032constexpr auto DCMI_PARAMETER_REVISION = 2;
33constexpr auto DCMI_SPEC_MAJOR_VERSION = 1;
34constexpr auto DCMI_SPEC_MINOR_VERSION = 5;
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060035constexpr auto DCMI_CONFIG_PARAMETER_REVISION = 1;
36constexpr auto DCMI_RAND_BACK_OFF_MASK = 0x80;
37constexpr auto DCMI_OPTION_60_43_MASK = 0x02;
38constexpr auto DCMI_OPTION_12_MASK = 0x01;
39constexpr auto DCMI_ACTIVATE_DHCP_MASK = 0x01;
40constexpr auto DCMI_ACTIVATE_DHCP_REPLY = 0x00;
41constexpr auto DCMI_SET_CONF_PARAM_REQ_PACKET_MAX_SIZE = 0x05;
42constexpr auto DCMI_SET_CONF_PARAM_REQ_PACKET_MIN_SIZE = 0x04;
Patrick Venture0b02be92018-08-31 11:55:55 -070043constexpr auto DHCP_TIMING1 = 0x04; // 4 sec
44constexpr auto DHCP_TIMING2_UPPER = 0x00; // 2 min
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060045constexpr auto DHCP_TIMING2_LOWER = 0x78;
Patrick Venture0b02be92018-08-31 11:55:55 -070046constexpr auto DHCP_TIMING3_UPPER = 0x00; // 64 sec
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060047constexpr 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.
51constexpr auto DHCP_OPT12_ENABLED = "SendHostNameEnabled";
52
Marri Devender Rao66c5fda2018-01-18 10:48:37 -060053constexpr auto SENSOR_VALUE_INTF = "xyz.openbmc_project.Sensor.Value";
54constexpr auto SENSOR_VALUE_PROP = "Value";
55constexpr auto SENSOR_SCALE_PROP = "Scale";
56
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050057using namespace phosphor::logging;
William A. Kennington III4c008022018-10-12 17:18:14 -070058namespace variant_ns = sdbusplus::message::variant_ns;
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050059
Tom Josephb9d86f42017-07-26 18:03:47 +053060namespace dcmi
61{
62
Deepak Kodihalli0b459552018-02-06 06:25:12 -060063// Refer Table 6-14, DCMI Entity ID Extension, DCMI v1.5 spec
Patrick Venture0b02be92018-08-31 11:55:55 -070064static const std::map<uint8_t, std::string> entityIdToName{
65 {0x40, "inlet"}, {0x37, "inlet"}, {0x41, "cpu"},
66 {0x03, "cpu"}, {0x42, "baseboard"}, {0x07, "baseboard"}};
Deepak Kodihalli0b459552018-02-06 06:25:12 -060067
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +030068bool isDCMIPowerMgmtSupported()
69{
70 auto data = parseJSONConfig(gDCMICapabilitiesConfig);
71
72 return (gDCMIPowerMgmtSupported == data.value(gDCMIPowerMgmtCapability, 0));
73}
74
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050075uint32_t getPcap(sdbusplus::bus::bus& bus)
76{
Patrick Venture0b02be92018-08-31 11:55:55 -070077 auto settingService = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH);
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050078
Patrick Venture0b02be92018-08-31 11:55:55 -070079 auto method = bus.new_method_call(settingService.c_str(), PCAP_PATH,
80 "org.freedesktop.DBus.Properties", "Get");
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050081
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 Josephb9d86f42017-07-26 18:03:47 +053088 elog<InternalFailure>();
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050089 }
90 sdbusplus::message::variant<uint32_t> pcap;
91 reply.read(pcap);
92
William A. Kennington III4c008022018-10-12 17:18:14 -070093 return variant_ns::get<uint32_t>(pcap);
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050094}
95
96bool getPcapEnabled(sdbusplus::bus::bus& bus)
97{
Patrick Venture0b02be92018-08-31 11:55:55 -070098 auto settingService = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH);
Andrew Geissler50c0c8f2017-07-11 16:18:51 -050099
Patrick Venture0b02be92018-08-31 11:55:55 -0700100 auto method = bus.new_method_call(settingService.c_str(), PCAP_PATH,
101 "org.freedesktop.DBus.Properties", "Get");
Andrew Geissler50c0c8f2017-07-11 16:18:51 -0500102
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 Josephb9d86f42017-07-26 18:03:47 +0530109 elog<InternalFailure>();
Andrew Geissler50c0c8f2017-07-11 16:18:51 -0500110 }
111 sdbusplus::message::variant<bool> pcapEnabled;
112 reply.read(pcapEnabled);
113
William A. Kennington III4c008022018-10-12 17:18:14 -0700114 return variant_ns::get<bool>(pcapEnabled);
Andrew Geissler50c0c8f2017-07-11 16:18:51 -0500115}
Chris Austen1810bec2015-10-13 12:12:39 -0500116
Tom Joseph46fa37d2017-07-26 18:11:55 +0530117void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap)
118{
119 auto service = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH);
120
Patrick Venture0b02be92018-08-31 11:55:55 -0700121 auto method = bus.new_method_call(service.c_str(), PCAP_PATH,
122 "org.freedesktop.DBus.Properties", "Set");
Tom Joseph46fa37d2017-07-26 18:11:55 +0530123
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 Joseph6c8d51b2017-07-26 18:18:06 +0530136void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled)
137{
138 auto service = ipmi::getService(bus, PCAP_INTERFACE, PCAP_PATH);
139
Patrick Venture0b02be92018-08-31 11:55:55 -0700140 auto method = bus.new_method_call(service.c_str(), PCAP_PATH,
141 "org.freedesktop.DBus.Properties", "Set");
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530142
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 Josephbe5eaa12017-07-12 19:54:44 +0530155void 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 Venture0b02be92018-08-31 11:55:55 -0700165 auto mapperCall = bus.new_method_call(mapperBusName, mapperObjPath,
166 mapperIface, "GetSubTree");
Tom Josephbe5eaa12017-07-12 19:54:44 +0530167
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
188std::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 Venture0b02be92018-08-31 11:55:55 -0700198 (objectTree.begin()->second.begin()->first).c_str(),
199 (objectTree.begin()->first).c_str(), dcmi::propIntf, "Get");
Tom Josephbe5eaa12017-07-12 19:54:44 +0530200 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 III4c008022018-10-12 17:18:14 -0700213 return variant_ns::get<std::string>(assetTag);
Tom Josephbe5eaa12017-07-12 19:54:44 +0530214}
215
Tom Josephbe5b9892017-07-15 00:55:23 +0530216void 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 Venture0b02be92018-08-31 11:55:55 -0700226 (objectTree.begin()->second.begin()->first).c_str(),
227 (objectTree.begin()->first).c_str(), dcmi::propIntf, "Set");
Tom Josephbe5b9892017-07-15 00:55:23 +0530228 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 Vovchenko8f7a6f62017-08-17 00:31:14 +0300240std::string getHostName(void)
241{
Patrick Venture0b02be92018-08-31 11:55:55 -0700242 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300243
244 auto service = ipmi::getService(bus, networkConfigIntf, networkConfigObj);
Patrick Venture0b02be92018-08-31 11:55:55 -0700245 auto value = ipmi::getDbusProperty(bus, service, networkConfigObj,
246 networkConfigIntf, hostNameProp);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300247
William A. Kennington III4c008022018-10-12 17:18:14 -0700248 return variant_ns::get<std::string>(value);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300249}
250
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600251bool getDHCPEnabled()
252{
253 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
254
Johnathan Mantey74a21022018-12-13 13:17:56 -0800255 auto ethdevice = ipmi::getChannelName(ethernetDefaultChannelNum);
Patrick Venture0b02be92018-08-31 11:55:55 -0700256 auto ethernetObj =
257 ipmi::getDbusObject(bus, ethernetIntf, networkRoot, ethdevice);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600258 auto service = ipmi::getService(bus, ethernetIntf, ethernetObj.first);
Patrick Venture0b02be92018-08-31 11:55:55 -0700259 auto value = ipmi::getDbusProperty(bus, service, ethernetObj.first,
260 ethernetIntf, "DHCPEnabled");
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600261
William A. Kennington III4c008022018-10-12 17:18:14 -0700262 return variant_ns::get<bool>(value);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600263}
264
265bool 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 III4c008022018-10-12 17:18:14 -0700272 return variant_ns::get<bool>(value);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600273}
274
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600275void 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 Pakhomova2573622018-11-02 19:00:18 +0300283Json parseJSONConfig(const std::string& configFile)
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600284{
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 Josephbe5eaa12017-07-12 19:54:44 +0530302} // namespace dcmi
Chris Austen1810bec2015-10-13 12:12:39 -0500303
Tom Josephb9d86f42017-07-26 18:03:47 +0530304ipmi_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 Pakhomov2c2af2c2018-11-06 16:06:10 +0300308 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 Venture0b02be92018-08-31 11:55:55 -0700315 auto requestData =
316 reinterpret_cast<const dcmi::GetPowerLimitRequest*>(request);
Tom Josephb9d86f42017-07-26 18:03:47 +0530317 std::vector<uint8_t> outPayload(sizeof(dcmi::GetPowerLimitResponse));
Patrick Venture0b02be92018-08-31 11:55:55 -0700318 auto responseData =
319 reinterpret_cast<dcmi::GetPowerLimitResponse*>(outPayload.data());
Tom Josephb9d86f42017-07-26 18:03:47 +0530320
321 if (requestData->groupID != dcmi::groupExtId)
322 {
323 *data_len = 0;
324 return IPMI_CC_INVALID_FIELD_REQUEST;
325 }
326
Patrick Venture0b02be92018-08-31 11:55:55 -0700327 sdbusplus::bus::bus sdbus{ipmid_get_sd_bus_connection()};
Tom Josephb9d86f42017-07-26 18:03:47 +0530328 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 Joseph46fa37d2017-07-26 18:11:55 +0530372ipmi_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 Pakhomov2c2af2c2018-11-06 16:06:10 +0300376 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 Venture0b02be92018-08-31 11:55:55 -0700383 auto requestData =
384 reinterpret_cast<const dcmi::SetPowerLimitRequest*>(request);
Tom Joseph46fa37d2017-07-26 18:11:55 +0530385 std::vector<uint8_t> outPayload(sizeof(dcmi::SetPowerLimitResponse));
Patrick Venture0b02be92018-08-31 11:55:55 -0700386 auto responseData =
387 reinterpret_cast<dcmi::SetPowerLimitResponse*>(outPayload.data());
Tom Joseph46fa37d2017-07-26 18:11:55 +0530388
389 if (requestData->groupID != dcmi::groupExtId)
390 {
391 *data_len = 0;
392 return IPMI_CC_INVALID_FIELD_REQUEST;
393 }
394
Patrick Venture0b02be92018-08-31 11:55:55 -0700395 sdbusplus::bus::bus sdbus{ipmid_get_sd_bus_connection()};
Tom Joseph46fa37d2017-07-26 18:11:55 +0530396
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 Joseph6c8d51b2017-07-26 18:18:06 +0530418ipmi_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 Pakhomov2c2af2c2018-11-06 16:06:10 +0300422 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 Venture0b02be92018-08-31 11:55:55 -0700429 auto requestData =
430 reinterpret_cast<const dcmi::ApplyPowerLimitRequest*>(request);
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530431 std::vector<uint8_t> outPayload(sizeof(dcmi::ApplyPowerLimitResponse));
Patrick Venture0b02be92018-08-31 11:55:55 -0700432 auto responseData =
433 reinterpret_cast<dcmi::ApplyPowerLimitResponse*>(outPayload.data());
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530434
435 if (requestData->groupID != dcmi::groupExtId)
436 {
437 *data_len = 0;
438 return IPMI_CC_INVALID_FIELD_REQUEST;
439 }
440
Patrick Venture0b02be92018-08-31 11:55:55 -0700441 sdbusplus::bus::bus sdbus{ipmid_get_sd_bus_connection()};
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530442
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 Joseph6f6dd4d2017-07-12 20:07:11 +0530464ipmi_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 Venture0b02be92018-08-31 11:55:55 -0700468 auto requestData =
469 reinterpret_cast<const dcmi::GetAssetTagRequest*>(request);
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530470 std::vector<uint8_t> outPayload(sizeof(dcmi::GetAssetTagResponse));
Patrick Venture0b02be92018-08-31 11:55:55 -0700471 auto responseData =
472 reinterpret_cast<dcmi::GetAssetTagResponse*>(outPayload.data());
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530473
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 Joseph545dd232017-07-12 20:20:49 +0530539ipmi_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 Venture0b02be92018-08-31 11:55:55 -0700543 auto requestData =
544 reinterpret_cast<const dcmi::SetAssetTagRequest*>(request);
Tom Joseph545dd232017-07-12 20:20:49 +0530545 std::vector<uint8_t> outPayload(sizeof(dcmi::SetAssetTagResponse));
Patrick Venture0b02be92018-08-31 11:55:55 -0700546 auto responseData =
547 reinterpret_cast<dcmi::SetAssetTagResponse*>(outPayload.data());
Tom Joseph545dd232017-07-12 20:20:49 +0530548
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 Venture0b02be92018-08-31 11:55:55 -0700580 sizeof(dcmi::SetAssetTagRequest),
Tom Joseph545dd232017-07-12 20:20:49 +0530581 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 Vovchenko8f7a6f62017-08-17 00:31:14 +0300599ipmi_ret_t getMgmntCtrlIdStr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -0700600 ipmi_request_t request, ipmi_response_t response,
601 ipmi_data_len_t data_len, ipmi_context_t context)
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300602{
Patrick Venture0b02be92018-08-31 11:55:55 -0700603 auto requestData =
604 reinterpret_cast<const dcmi::GetMgmntCtrlIdStrRequest*>(request);
605 auto responseData =
606 reinterpret_cast<dcmi::GetMgmntCtrlIdStrResponse*>(response);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300607 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 Venture0b02be92018-08-31 11:55:55 -0700633 responseStr.length() + 1);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300634 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
642ipmi_ret_t setMgmntCtrlIdStr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -0700643 ipmi_request_t request, ipmi_response_t response,
644 ipmi_data_len_t data_len, ipmi_context_t context)
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300645{
646 static std::array<char, dcmi::maxCtrlIdStrLen + 1> newCtrlIdStr;
647
Patrick Venture0b02be92018-08-31 11:55:55 -0700648 auto requestData =
649 reinterpret_cast<const dcmi::SetMgmntCtrlIdStrRequest*>(request);
650 auto responseData =
651 reinterpret_cast<dcmi::SetMgmntCtrlIdStrResponse*>(response);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300652
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 Venture0b02be92018-08-31 11:55:55 -0700658 (requestData->offset + requestData->bytes ==
659 dcmi::maxCtrlIdStrLen + 1 &&
660 requestData->data[requestData->bytes - 1] != '\0'))
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300661 {
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 Venture0b02be92018-08-31 11:55:55 -0700678 auto restStrIter =
679 std::copy_n(requestData->data, requestData->bytes,
680 begin(newCtrlIdStr) + requestData->offset);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300681 /* 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 Venture0b02be92018-08-31 11:55:55 -0700689 requestData->data + requestData->bytes, '\0');
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300690 if (it != requestData->data + requestData->bytes)
691 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700692 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300693 ipmi::setDbusProperty(bus, dcmi::networkServiceName,
Patrick Venture0b02be92018-08-31 11:55:55 -0700694 dcmi::networkConfigObj,
695 dcmi::networkConfigIntf, dcmi::hostNameProp,
696 std::string(newCtrlIdStr.data()));
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300697 }
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 Venture0b02be92018-08-31 11:55:55 -0700711// List of the capabilities under each parameter
712dcmi::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 Subhashchandrane29be412018-01-16 05:11:56 -0600740
741ipmi_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 Pakhomova2573622018-11-02 19:00:18 +0300746 std::ifstream dcmiCapFile(dcmi::gDCMICapabilitiesConfig);
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600747 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 Venture0b02be92018-08-31 11:55:55 -0700760 auto requestData =
761 reinterpret_cast<const dcmi::GetDCMICapRequest*>(request);
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600762
Patrick Venture0b02be92018-08-31 11:55:55 -0700763 // get list of capabilities in a parameter
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600764 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 Venture0b02be92018-08-31 11:55:55 -0700778 auto responseData = reinterpret_cast<dcmi::GetDCMICapResponse*>(response);
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600779
Patrick Venture0b02be92018-08-31 11:55:55 -0700780 // For each capabilities in a parameter fill the data from
781 // the json file based on the capability name.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600782 for (auto cap : caps->second.capList)
783 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700784 // 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 Subhashchandrane29be412018-01-16 05:11:56 -0600787 if ((cap.length + cap.position) > 8)
788 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700789 // Read the value corresponding to capability name and assign to
790 // 16bit bitset.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600791 std::bitset<16> val(data.value(cap.name.c_str(), 0));
792 val <<= cap.position;
Patrick Venture0b02be92018-08-31 11:55:55 -0700793 reinterpret_cast<uint16_t*>(
794 responseData
795 ->data)[(cap.bytePosition - 1) / sizeof(uint16_t)] |=
796 val.to_ulong();
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600797 }
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 Kodihalliee717d72018-01-24 04:53:09 -0600814namespace dcmi
815{
816namespace temp_readings
817{
818
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600819Temperature 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 Feist9cc0ea52018-10-09 10:53:11 -0700824 // is an double and in degrees C. It needs to be scaled by using the
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600825 // 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 Venture0b02be92018-08-31 11:55:55 -0700829 auto result = ipmi::getAllDbusProperties(
830 bus, dbusService, dbusPath, "xyz.openbmc_project.Sensor.Value");
James Feist9cc0ea52018-10-09 10:53:11 -0700831 auto temperature = sdbusplus::message::variant_ns::visit(
832 ipmi::VariantToDoubleVisitor(), result.at("Value"));
833 double absTemp = std::abs(temperature);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600834
James Feist9cc0ea52018-10-09 10:53:11 -0700835 auto findFactor = result.find("Scale");
836 double factor = 0.0;
837 if (findFactor != result.end())
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600838 {
James Feist9cc0ea52018-10-09 10:53:11 -0700839 factor = sdbusplus::message::variant_ns::visit(
840 ipmi::VariantToDoubleVisitor(), findFactor->second);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600841 }
James Feist9cc0ea52018-10-09 10:53:11 -0700842 double scale = std::pow(10, factor);
843
844 auto tempDegrees = absTemp * scale;
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600845 // 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 Kodihalliee717d72018-01-24 04:53:09 -0600855std::tuple<Response, NumInstances> read(const std::string& type,
856 uint8_t instance)
857{
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600858 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 Pakhomova2573622018-11-02 19:00:18 +0300867 auto data = parseJSONConfig(gDCMISensorsConfig);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600868 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 Venture0b02be92018-08-31 11:55:55 -0700885 ipmi::getService(bus, "xyz.openbmc_project.Sensor.Value", path);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600886 }
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 Kodihalliee717d72018-01-24 04:53:09 -0600909}
910
911std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
912 uint8_t instanceStart)
913{
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600914 ResponseList response{};
915 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
916
917 size_t numInstances = 0;
Kirill Pakhomova2573622018-11-02 19:00:18 +0300918 auto data = parseJSONConfig(gDCMISensorsConfig);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600919 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 Venture0b02be92018-08-31 11:55:55 -0700941 ipmi::getService(bus, "xyz.openbmc_project.Sensor.Value", path);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600942
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 Kodihalliee717d72018-01-24 04:53:09 -0600964}
965
Patrick Venture0b02be92018-08-31 11:55:55 -0700966} // namespace temp_readings
967} // namespace dcmi
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600968
969ipmi_ret_t getTempReadings(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -0700970 ipmi_request_t request, ipmi_response_t response,
971 ipmi_data_len_t data_len, ipmi_context_t context)
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600972{
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600973 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 Kodihalli0b459552018-02-06 06:25:12 -0600986 auto it = dcmi::entityIdToName.find(requestData->entityId);
987 if (it == dcmi::entityIdToName.end())
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600988 {
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 Venture0b02be92018-08-31 11:55:55 -07001034 size_t payloadSize = temps.size() * sizeof(dcmi::temp_readings::Response);
Deepak Kodihalliee717d72018-01-24 04:53:09 -06001035 if (!temps.empty())
1036 {
1037 memcpy(responseData + 1, // copy payload right after the response header
Patrick Venture0b02be92018-08-31 11:55:55 -07001038 temps.data(), payloadSize);
Deepak Kodihalliee717d72018-01-24 04:53:09 -06001039 }
1040 *data_len = sizeof(dcmi::GetTempReadingsResponseHdr) + payloadSize;
1041
1042 return IPMI_CC_OK;
1043}
1044
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001045int64_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 Venture0b02be92018-08-31 11:55:55 -07001052 entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR));
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001053 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 Venture0b02be92018-08-31 11:55:55 -07001060 entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR));
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001061 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 Raoce6a7952018-02-11 08:45:00 -06001072 // 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 Rao66c5fda2018-01-18 10:48:37 -06001077
Patrick Venture0b02be92018-08-31 11:55:55 -07001078 // Read the sensor value and scale properties
1079 auto properties = ipmi::getAllDbusProperties(bus, service, objectPath,
1080 SENSOR_VALUE_INTF);
William A. Kennington III4c008022018-10-12 17:18:14 -07001081 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 Rao66c5fda2018-01-18 10:48:37 -06001083
Marri Devender Raoce6a7952018-02-11 08:45:00 -06001084 // 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 Venture0b02be92018-08-31 11:55:55 -07001091 entry("OBJECT_PATH=%s", objectPath.c_str()),
1092 entry("INTERFACE=%s", SENSOR_VALUE_INTF));
Marri Devender Raoce6a7952018-02-11 08:45:00 -06001093 }
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001094 return power;
1095}
1096
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001097ipmi_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 Venture0b02be92018-08-31 11:55:55 -07001101 auto requestData =
1102 reinterpret_cast<const dcmi::SetConfParamsRequest*>(request);
1103 auto responseData =
1104 reinterpret_cast<dcmi::SetConfParamsResponse*>(response);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001105
Patrick Venture0b02be92018-08-31 11:55:55 -07001106 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 Goruganti22be97b2018-02-07 01:19:59 -06001109 {
Gunnar Mills8466b792018-03-23 12:18:12 -05001110 log<level::ERR>("Invalid Group ID or Invalid Requested Packet size",
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001111 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 Venture0b02be92018-08-31 11:55:55 -07001121 switch (
1122 static_cast<dcmi::DCMIConfigParameters>(requestData->paramSelect))
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001123 {
1124 case dcmi::DCMIConfigParameters::ActivateDHCP:
1125
1126 if ((requestData->data[0] & DCMI_ACTIVATE_DHCP_MASK) &&
Patrick Venture0b02be92018-08-31 11:55:55 -07001127 dcmi::getDHCPEnabled())
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001128 {
Patrick Venture0b02be92018-08-31 11:55:55 -07001129 // 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 Goruganti22be97b2018-02-07 01:19:59 -06001134 }
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
1173ipmi_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 Venture0b02be92018-08-31 11:55:55 -07001178 auto requestData =
1179 reinterpret_cast<const dcmi::GetConfParamsRequest*>(request);
1180 auto responseData =
1181 reinterpret_cast<dcmi::GetConfParamsResponse*>(response);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001182
1183 responseData->data[0] = 0x00;
1184
Patrick Venture0b02be92018-08-31 11:55:55 -07001185 if (requestData->groupID != dcmi::groupExtId ||
1186 *data_len != sizeof(dcmi::GetConfParamsRequest))
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001187 {
Gunnar Mills8466b792018-03-23 12:18:12 -05001188 log<level::ERR>("Invalid Group ID or Invalid Requested Packet size",
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001189 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 Venture0b02be92018-08-31 11:55:55 -07001199 switch (
1200 static_cast<dcmi::DCMIConfigParameters>(requestData->paramSelect))
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001201 {
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 Rao66c5fda2018-01-18 10:48:37 -06001247ipmi_ret_t getPowerReading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -07001248 ipmi_request_t request, ipmi_response_t response,
1249 ipmi_data_len_t data_len, ipmi_context_t context)
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001250{
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +03001251 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 Rao66c5fda2018-01-18 10:48:37 -06001258 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Venture0b02be92018-08-31 11:55:55 -07001259 auto requestData =
1260 reinterpret_cast<const dcmi::GetPowerReadingRequest*>(request);
1261 auto responseData =
1262 reinterpret_cast<dcmi::GetPowerReadingResponse*>(response);
Marri Devender Rao9c966e02018-01-22 05:55:10 -06001263
1264 if (requestData->groupID != dcmi::groupExtId)
1265 {
1266 *data_len = 0;
1267 return IPMI_CC_INVALID_FIELD_REQUEST;
1268 }
1269
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001270 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Marri Devender Rao9c966e02018-01-22 05:55:10 -06001271 int64_t power = 0;
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001272 try
1273 {
Marri Devender Rao9c966e02018-01-22 05:55:10 -06001274 power = getPowerReading(bus);
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001275 }
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 Rao9c966e02018-01-22 05:55:10 -06001283 responseData->groupID = dcmi::groupExtId;
1284
1285 // TODO: openbmc/openbmc#2819
Gunnar Mills8466b792018-03-23 12:18:12 -05001286 // Minimum, Maximum, Average power, TimeFrame, TimeStamp,
Marri Devender Rao9c966e02018-01-22 05:55:10 -06001287 // 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 Rao66c5fda2018-01-18 10:48:37 -06001296 return rc;
1297}
1298
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001299namespace dcmi
1300{
1301namespace sensor_info
1302{
1303
Deepak Kodihallidd4cff12018-02-06 06:48:29 -06001304Response 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 Kodihalli0b459552018-02-06 06:25:12 -06001313std::tuple<Response, NumInstances> read(const std::string& type,
Patrick Venture0b02be92018-08-31 11:55:55 -07001314 uint8_t instance, const Json& config)
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001315{
Deepak Kodihallidd4cff12018-02-06 06:48:29 -06001316 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 Kodihalli0b459552018-02-06 06:25:12 -06001349}
1350
Patrick Venture0b02be92018-08-31 11:55:55 -07001351std::tuple<ResponseList, NumInstances>
1352 readAll(const std::string& type, uint8_t instanceStart, const Json& config)
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001353{
Deepak Kodihallidd4cff12018-02-06 06:48:29 -06001354 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 Kodihalli0b459552018-02-06 06:25:12 -06001394}
1395
1396} // namespace sensor_info
1397} // namespace dcmi
1398
1399ipmi_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 Pakhomova2573622018-11-02 19:00:18 +03001446 config = dcmi::parseJSONConfig(dcmi::gDCMISensorsConfig);
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001447 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 Venture0b02be92018-08-31 11:55:55 -07001455 requestData->instanceStart, config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001456 }
1457 else
1458 {
1459 // Read one instance
1460 sensors.resize(1);
1461 std::tie(sensors[0], responseData->numInstances) =
Patrick Venture0b02be92018-08-31 11:55:55 -07001462 dcmi::sensor_info::read(it->second, requestData->entityInstance,
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001463 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 Venture0b02be92018-08-31 11:55:55 -07001477 sensors.data(), payloadSize);
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001478 }
1479 *data_len = sizeof(dcmi::GetSensorInfoResponseHdr) + payloadSize;
1480
1481 return IPMI_CC_OK;
1482}
1483
Chris Austen1810bec2015-10-13 12:12:39 -05001484void register_netfn_dcmi_functions()
1485{
Tom05732372016-09-06 17:21:23 +05301486 // <Get Power Limit>
Ratan Gupta11ddbd22017-08-05 11:59:39 +05301487
Patrick Venture0b02be92018-08-31 11:55:55 -07001488 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_POWER_LIMIT, NULL,
1489 getPowerLimit, PRIVILEGE_USER);
Tom Joseph6f6dd4d2017-07-12 20:07:11 +05301490
Tom Joseph46fa37d2017-07-26 18:11:55 +05301491 // <Set Power Limit>
Ratan Gupta11ddbd22017-08-05 11:59:39 +05301492
Patrick Venture0b02be92018-08-31 11:55:55 -07001493 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_POWER_LIMIT, NULL,
1494 setPowerLimit, PRIVILEGE_OPERATOR);
Tom Joseph46fa37d2017-07-26 18:11:55 +05301495
Tom Joseph6c8d51b2017-07-26 18:18:06 +05301496 // <Activate/Deactivate Power Limit>
Ratan Gupta11ddbd22017-08-05 11:59:39 +05301497
1498 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::APPLY_POWER_LIMIT,
1499 NULL, applyPowerLimit, PRIVILEGE_OPERATOR);
Tom Joseph6c8d51b2017-07-26 18:18:06 +05301500
Tom Joseph6f6dd4d2017-07-12 20:07:11 +05301501 // <Get Asset Tag>
Ratan Gupta11ddbd22017-08-05 11:59:39 +05301502
Patrick Venture0b02be92018-08-31 11:55:55 -07001503 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_ASSET_TAG, NULL,
1504 getAssetTag, PRIVILEGE_USER);
Tom Joseph545dd232017-07-12 20:20:49 +05301505
1506 // <Set Asset Tag>
Ratan Gupta11ddbd22017-08-05 11:59:39 +05301507
Patrick Venture0b02be92018-08-31 11:55:55 -07001508 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_ASSET_TAG, NULL,
1509 setAssetTag, PRIVILEGE_OPERATOR);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +03001510
Gunnar Mills8991dd62017-10-25 17:11:29 -05001511 // <Get Management Controller Identifier String>
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +03001512
1513 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_MGMNT_CTRL_ID_STR,
Patrick Venture0b02be92018-08-31 11:55:55 -07001514 NULL, getMgmntCtrlIdStr, PRIVILEGE_USER);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +03001515
1516 // <Set Management Controller Identifier String>
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +03001517 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_MGMNT_CTRL_ID_STR,
Patrick Venture0b02be92018-08-31 11:55:55 -07001518 NULL, setMgmntCtrlIdStr, PRIVILEGE_ADMIN);
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +03001519
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -06001520 // <Get DCMI capabilities>
1521 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_CAPABILITIES,
Patrick Venture0b02be92018-08-31 11:55:55 -07001522 NULL, getDCMICapabilities, PRIVILEGE_USER);
Deepak Kodihalliee717d72018-01-24 04:53:09 -06001523
1524 // <Get Temperature Readings>
1525 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_TEMP_READINGS,
1526 NULL, getTempReadings, PRIVILEGE_USER);
1527
Marri Devender Rao66c5fda2018-01-18 10:48:37 -06001528 // <Get Power Reading>
1529 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_POWER_READING,
1530 NULL, getPowerReading, PRIVILEGE_USER);
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001531
1532 // <Get Sensor Info>
Patrick Venture0b02be92018-08-31 11:55:55 -07001533 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_SENSOR_INFO, NULL,
1534 getSensorInfo, PRIVILEGE_USER);
Deepak Kodihalli0b459552018-02-06 06:25:12 -06001535
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001536 // <Get DCMI Configuration Parameters>
Patrick Venture0b02be92018-08-31 11:55:55 -07001537 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::GET_CONF_PARAMS, NULL,
1538 getDCMIConfParams, PRIVILEGE_USER);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001539
1540 // <Set DCMI Configuration Parameters>
Patrick Venture0b02be92018-08-31 11:55:55 -07001541 ipmi_register_callback(NETFUN_GRPEXT, dcmi::Commands::SET_CONF_PARAMS, NULL,
1542 setDCMIConfParams, PRIVILEGE_ADMIN);
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -06001543
Chris Austen1810bec2015-10-13 12:12:39 -05001544 return;
1545}
Tom05732372016-09-06 17:21:23 +05301546// 956379