diff options
Diffstat (limited to 'sensorhandler.cpp')
-rw-r--r-- | sensorhandler.cpp | 472 |
1 files changed, 251 insertions, 221 deletions
diff --git a/sensorhandler.cpp b/sensorhandler.cpp index 609fdfd..41d393b 100644 --- a/sensorhandler.cpp +++ b/sensorhandler.cpp @@ -1,42 +1,46 @@ +#include "sensorhandler.h" + +#include "fruread.hpp" +#include "ipmid.hpp" +#include "types.hpp" +#include "utils.hpp" + #include <mapper.h> #include <math.h> #include <stdio.h> #include <string.h> -#include <set> +#include <systemd/sd-bus.h> + #include <bitset> +#include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/log.hpp> +#include <set> +#include <xyz/openbmc_project/Common/error.hpp> #include <xyz/openbmc_project/Sensor/Value/server.hpp> -#include <systemd/sd-bus.h> + #include "host-ipmid/ipmid-api.h" -#include <phosphor-logging/log.hpp> -#include <phosphor-logging/elog-errors.hpp> -#include "fruread.hpp" -#include "ipmid.hpp" -#include "sensorhandler.h" -#include "types.hpp" -#include "utils.hpp" -#include "xyz/openbmc_project/Common/error.hpp" static constexpr uint8_t fruInventoryDevice = 0x10; static constexpr uint8_t IPMIFruInventory = 0x02; static constexpr uint8_t BMCSlaveAddress = 0x20; -extern int updateSensorRecordFromSSRAESC(const void *); -extern sd_bus *bus; +extern int updateSensorRecordFromSSRAESC(const void*); +extern sd_bus* bus; extern const ipmi::sensor::IdInfoMap sensors; extern const FruMap frus; - using namespace phosphor::logging; using InternalFailure = sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; -void register_netfn_sen_functions() __attribute__((constructor)); +void register_netfn_sen_functions() __attribute__((constructor)); -struct sensorTypemap_t { +struct sensorTypemap_t +{ uint8_t number; uint8_t typecode; char dbusname[32]; -} ; +}; sensorTypemap_t g_SensorTypeMap[] = { @@ -47,7 +51,8 @@ sensorTypemap_t g_SensorTypeMap[] = { {0x07, 0x6F, "CORE"}, {0x07, 0x6F, "CPU"}, {0x0F, 0x6F, "BootProgress"}, - {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09 + {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor + // type code os 0x09 {0xC3, 0x6F, "BootCount"}, {0x1F, 0x6F, "OperatingSystemStatus"}, {0x12, 0x6F, "SYSTEM_EVENT"}, @@ -60,47 +65,53 @@ sensorTypemap_t g_SensorTypeMap[] = { {0xFF, 0x00, ""}, }; - -struct sensor_data_t { +struct sensor_data_t +{ uint8_t sennum; -} __attribute__ ((packed)) ; +} __attribute__((packed)); -struct sensorreadingresp_t { +struct sensorreadingresp_t +{ uint8_t value; uint8_t operation; uint8_t indication[2]; -} __attribute__ ((packed)) ; +} __attribute__((packed)); -int get_bus_for_path(const char *path, char **busname) { +int get_bus_for_path(const char* path, char** busname) +{ return mapper_get_service(bus, path, busname); } -int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) { - char *busname = NULL; - const char *iface = "org.openbmc.managers.System"; - const char *objname = "/org/openbmc/managers/System"; - char *str1 = NULL, *str2, *str3; +int legacy_dbus_openbmc_path(const char* type, const uint8_t num, + dbus_interface_t* interface) +{ + char* busname = NULL; + const char* iface = "org.openbmc.managers.System"; + const char* objname = "/org/openbmc/managers/System"; + char *str1 = NULL, *str2, *str3; sd_bus_error error = SD_BUS_ERROR_NULL; - sd_bus_message *reply = NULL; - + sd_bus_message* reply = NULL; int r; r = get_bus_for_path(objname, &busname); - if (r < 0) { - fprintf(stderr, "Failed to get %s busname: %s\n", - objname, strerror(-r)); + if (r < 0) + { + fprintf(stderr, "Failed to get %s busname: %s\n", objname, + strerror(-r)); goto final; } - r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId", + r = sd_bus_call_method(bus, busname, objname, iface, "getObjectFromByteId", &error, &reply, "sy", type, num); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); goto final; } r = sd_bus_message_read(reply, "(ss)", &str2, &str3); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to get a response: %s", strerror(-r)); goto final; } @@ -113,9 +124,9 @@ int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface } r = get_bus_for_path(str2, &str1); - if (r < 0) { - fprintf(stderr, "Failed to get %s busname: %s\n", - str2, strerror(-r)); + if (r < 0) + { + fprintf(stderr, "Failed to get %s busname: %s\n", str2, strerror(-r)); goto final; } @@ -141,7 +152,8 @@ final: // Use a lookup table to find the interface name of a specific sensor // This will be used until an alternative is found. this is the first // step for mapping IPMI -int find_openbmc_path(uint8_t num, dbus_interface_t *interface) { +int find_openbmc_path(uint8_t num, dbus_interface_t* interface) +{ int rc; // When the sensor map does not contain the sensor requested, @@ -156,10 +168,10 @@ int find_openbmc_path(uint8_t num, dbus_interface_t *interface) { char* busname = nullptr; rc = get_bus_for_path(info.sensorPath.c_str(), &busname); - if (rc < 0) { + if (rc < 0) + { fprintf(stderr, "Failed to get %s busname: %s\n", - info.sensorPath.c_str(), - busname); + info.sensorPath.c_str(), busname); goto final; } @@ -170,7 +182,8 @@ int find_openbmc_path(uint8_t num, dbus_interface_t *interface) { // works for the Value interface but may not suffice for more complex // sensors. // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103 - strcpy(interface->interface, info.propertyInterfaces.begin()->first.c_str()); + strcpy(interface->interface, + info.propertyInterfaces.begin()->first.c_str()); interface->sensornumber = num; final: @@ -178,45 +191,51 @@ final: return rc; } - ///////////////////////////////////////////////////////////////////// // // Routines used by ipmi commands wanting to interact on the dbus // ///////////////////////////////////////////////////////////////////// -int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) { - +int set_sensor_dbus_state_s(uint8_t number, const char* method, + const char* value) +{ dbus_interface_t a; int r; sd_bus_error error = SD_BUS_ERROR_NULL; - sd_bus_message *m=NULL; + sd_bus_message* m = NULL; - fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n", - number, method, value); + fprintf(ipmidbus, + "Attempting to set a dbus Variant Sensor 0x%02x via %s with a " + "value of %s\n", + number, method, value); r = find_openbmc_path(number, &a); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); return 0; } - r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); - if (r < 0) { + r = sd_bus_message_new_method_call(bus, &m, a.bus, a.path, a.interface, + method); + if (r < 0) + { fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); goto final; } r = sd_bus_message_append(m, "v", "s", value); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); goto final; } - r = sd_bus_call(bus, m, 0, &error, NULL); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to call the method: %s", strerror(-r)); } @@ -226,39 +245,46 @@ final: return 0; } -int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) { - +int set_sensor_dbus_state_y(uint8_t number, const char* method, + const uint8_t value) +{ dbus_interface_t a; int r; sd_bus_error error = SD_BUS_ERROR_NULL; - sd_bus_message *m=NULL; + sd_bus_message* m = NULL; - fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n", - number, method, value); + fprintf(ipmidbus, + "Attempting to set a dbus Variant Sensor 0x%02x via %s with a " + "value of 0x%02x\n", + number, method, value); r = find_openbmc_path(number, &a); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); return 0; } - r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); - if (r < 0) { + r = sd_bus_message_new_method_call(bus, &m, a.bus, a.path, a.interface, + method); + if (r < 0) + { fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); goto final; } r = sd_bus_message_append(m, "v", "i", value); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); goto final; } - r = sd_bus_call(bus, m, 0, &error, NULL); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "12 Failed to call the method: %s", strerror(-r)); } @@ -269,14 +295,17 @@ final: return 0; } -uint8_t dbus_to_sensor_type(char *p) { +uint8_t dbus_to_sensor_type(char* p) +{ - sensorTypemap_t *s = g_SensorTypeMap; - char r=0; - while (s->number != 0xFF) { - if (!strcmp(s->dbusname,p)) { + sensorTypemap_t* s = g_SensorTypeMap; + char r = 0; + while (s->number != 0xFF) + { + if (!strcmp(s->dbusname, p)) + { r = s->typecode; - break; + break; } s++; } @@ -287,75 +316,79 @@ uint8_t dbus_to_sensor_type(char *p) { return r; } +uint8_t get_type_from_interface(dbus_interface_t dbus_if) +{ -uint8_t get_type_from_interface(dbus_interface_t dbus_if) { - - char *p; + char* p; uint8_t type; // This is where sensors that do not exist in dbus but do // exist in the host code stop. This should indicate it // is not a supported sensor - if (dbus_if.interface[0] == 0) { return 0;} + if (dbus_if.interface[0] == 0) + { + return 0; + } // Fetch type from interface itself. if (dbus_if.sensortype != 0) { type = dbus_if.sensortype; - } else { + } + else + { // Non InventoryItems - p = strrchr (dbus_if.path, '/'); - type = dbus_to_sensor_type(p+1); + p = strrchr(dbus_if.path, '/'); + type = dbus_to_sensor_type(p + 1); } return type; - } +} // Replaces find_sensor -uint8_t find_type_for_sensor_number(uint8_t num) { +uint8_t find_type_for_sensor_number(uint8_t num) +{ int r; dbus_interface_t dbus_if; r = find_openbmc_path(num, &dbus_if); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "Could not find sensor %d\n", num); return 0; } return get_type_from_interface(dbus_if); } - - - - ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, ipmi_response_t response, - ipmi_data_len_t data_len, ipmi_context_t context) + ipmi_request_t request, + ipmi_response_t response, + ipmi_data_len_t data_len, + ipmi_context_t context) { - sensor_data_t *reqptr = (sensor_data_t*)request; + sensor_data_t* reqptr = (sensor_data_t*)request; ipmi_ret_t rc = IPMI_CC_OK; - printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum); + printf("IPMI GET_SENSOR_TYPE [0x%02X]\n", reqptr->sennum); // TODO Not sure what the System-event-sensor is suppose to return // need to ask Hostboot team - unsigned char buf[] = {0x00,0x6F}; + unsigned char buf[] = {0x00, 0x6F}; buf[0] = find_type_for_sensor_number(reqptr->sennum); // HACK UNTIL Dbus gets updated or we find a better way - if (buf[0] == 0) { + if (buf[0] == 0) + { rc = IPMI_CC_SENSOR_INVALID; } - *data_len = sizeof(buf); memcpy(response, &buf, *data_len); return rc; } -const std::set<std::string> analogSensorInterfaces = -{ +const std::set<std::string> analogSensorInterfaces = { "xyz.openbmc_project.Sensor.Value", "xyz.openbmc_project.Control.FanPwm", }; @@ -365,10 +398,10 @@ bool isAnalogSensor(const std::string& interface) return (analogSensorInterfaces.count(interface)); } -ipmi_ret_t setSensorReading(void *request) +ipmi_ret_t setSensorReading(void* request) { ipmi::sensor::SetSensorReadingReq cmdData = - *(static_cast<ipmi::sensor::SetSensorReadingReq *>(request)); + *(static_cast<ipmi::sensor::SetSensorReadingReq*>(request)); // Check if the Sensor Number is present const auto iter = sensors.find(cmdData.number); @@ -380,7 +413,7 @@ ipmi_ret_t setSensorReading(void *request) try { if (ipmi::sensor::Mutability::Write != - (iter->second.mutability & ipmi::sensor::Mutability::Write)) + (iter->second.mutability & ipmi::sensor::Mutability::Write)) { log<level::ERR>("Sensor Set operation is not allowed", entry("SENSOR_NUM=%d", cmdData.number)); @@ -390,9 +423,9 @@ ipmi_ret_t setSensorReading(void *request) } catch (InternalFailure& e) { - log<level::ERR>("Set sensor failed", - entry("SENSOR_NUM=%d", cmdData.number)); - commit<InternalFailure>(); + log<level::ERR>("Set sensor failed", + entry("SENSOR_NUM=%d", cmdData.number)); + commit<InternalFailure>(); } catch (const std::runtime_error& e) { @@ -403,10 +436,10 @@ ipmi_ret_t setSensorReading(void *request) } ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, ipmi_response_t response, - ipmi_data_len_t data_len, ipmi_context_t context) + ipmi_request_t request, ipmi_response_t response, + ipmi_data_len_t data_len, ipmi_context_t context) { - sensor_data_t *reqptr = (sensor_data_t*)request; + sensor_data_t* reqptr = (sensor_data_t*)request; log<level::DEBUG>("IPMI SET_SENSOR", entry("SENSOR_NUM=0x%02x", reqptr->sennum)); @@ -418,30 +451,29 @@ ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, */ auto ipmiRC = setSensorReading(request); - if(ipmiRC == IPMI_CC_SENSOR_INVALID) + if (ipmiRC == IPMI_CC_SENSOR_INVALID) { updateSensorRecordFromSSRAESC(reqptr); ipmiRC = IPMI_CC_OK; } - *data_len=0; + *data_len = 0; return ipmiRC; } -ipmi_ret_t legacyGetSensorReading(uint8_t sensorNum, - ipmi_response_t response, +ipmi_ret_t legacyGetSensorReading(uint8_t sensorNum, ipmi_response_t response, ipmi_data_len_t data_len) { int r; dbus_interface_t a; - sd_bus *bus = ipmid_get_sd_bus_connection(); + sd_bus* bus = ipmid_get_sd_bus_connection(); ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID; uint8_t type = 0; - sd_bus_message *reply = NULL; + sd_bus_message* reply = NULL; int reading = 0; char* assertion = NULL; - sensorreadingresp_t *resp = (sensorreadingresp_t*) response; - *data_len=0; + sensorreadingresp_t* resp = (sensorreadingresp_t*)response; + *data_len = 0; r = find_openbmc_path(sensorNum, &a); if (r < 0) @@ -453,76 +485,84 @@ ipmi_ret_t legacyGetSensorReading(uint8_t sensorNum, type = get_type_from_interface(a); if (type == 0) { - sd_journal_print(LOG_ERR, "Failed to find Sensor 0x%02x\n", - sensorNum); + sd_journal_print(LOG_ERR, "Failed to find Sensor 0x%02x\n", sensorNum); return IPMI_CC_SENSOR_INVALID; } - switch(type) { + switch (type) + { case 0xC2: - r = sd_bus_get_property(bus,a.bus, a.path, a.interface, - "value", NULL, &reply, "i"); + r = sd_bus_get_property(bus, a.bus, a.path, a.interface, "value", + NULL, &reply, "i"); if (r < 0) { - sd_journal_print(LOG_ERR, "Failed to call sd_bus_get_property:" - " %d, %s\n", r, strerror(-r)); + sd_journal_print(LOG_ERR, + "Failed to call sd_bus_get_property:" + " %d, %s\n", + r, strerror(-r)); sd_journal_print(LOG_ERR, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface); break; } r = sd_bus_message_read(reply, "i", &reading); - if (r < 0) { + if (r < 0) + { sd_journal_print(LOG_ERR, "Failed to read sensor: %s\n", strerror(-r)); break; } rc = IPMI_CC_OK; - *data_len=sizeof(sensorreadingresp_t); + *data_len = sizeof(sensorreadingresp_t); - resp->value = (uint8_t)reading; - resp->operation = 0; + resp->value = (uint8_t)reading; + resp->operation = 0; resp->indication[0] = 0; resp->indication[1] = 0; break; case 0xC8: - r = sd_bus_get_property(bus,a.bus, a.path, a.interface, - "value", NULL, &reply, "i"); + r = sd_bus_get_property(bus, a.bus, a.path, a.interface, "value", + NULL, &reply, "i"); if (r < 0) { - sd_journal_print(LOG_ERR, "Failed to call sd_bus_get_property:" - " %d, %s\n", r, strerror(-r)); + sd_journal_print(LOG_ERR, + "Failed to call sd_bus_get_property:" + " %d, %s\n", + r, strerror(-r)); sd_journal_print(LOG_ERR, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface); break; } r = sd_bus_message_read(reply, "i", &reading); - if (r < 0) { + if (r < 0) + { sd_journal_print(LOG_ERR, "Failed to read sensor: %s\n", strerror(-r)); break; } rc = IPMI_CC_OK; - *data_len=sizeof(sensorreadingresp_t); + *data_len = sizeof(sensorreadingresp_t); - resp->value = 0; - resp->operation = 0; + resp->value = 0; + resp->operation = 0; resp->indication[0] = (uint8_t)reading; resp->indication[1] = 0; break; - //TODO openbmc/openbmc#2154 Move this sensor to right place. + // TODO openbmc/openbmc#2154 Move this sensor to right place. case 0xCA: - r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value", + r = sd_bus_get_property(bus, a.bus, a.path, a.interface, "value", NULL, &reply, "s"); if (r < 0) { - sd_journal_print(LOG_ERR, "Failed to call sd_bus_get_property:" - " %d, %s\n", r, strerror(-r)); + sd_journal_print(LOG_ERR, + "Failed to call sd_bus_get_property:" + " %d, %s\n", + r, strerror(-r)); sd_journal_print(LOG_ERR, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface); break; @@ -537,11 +577,11 @@ ipmi_ret_t legacyGetSensorReading(uint8_t sensorNum, } rc = IPMI_CC_OK; - *data_len=sizeof(sensorreadingresp_t); + *data_len = sizeof(sensorreadingresp_t); - resp->value = 0; - resp->operation = 0; - if (strcmp(assertion,"Enabled") == 0) + resp->value = 0; + resp->operation = 0; + if (strcmp(assertion, "Enabled") == 0) { resp->indication[0] = 0x02; } @@ -564,12 +604,14 @@ ipmi_ret_t legacyGetSensorReading(uint8_t sensorNum, } ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, ipmi_response_t response, - ipmi_data_len_t data_len, ipmi_context_t context) + ipmi_request_t request, + ipmi_response_t response, + ipmi_data_len_t data_len, + ipmi_context_t context) { - sensor_data_t *reqptr = (sensor_data_t*)request; - sensorreadingresp_t *resp = (sensorreadingresp_t*) response; - ipmi::sensor::GetSensorResponse getResponse {}; + sensor_data_t* reqptr = (sensor_data_t*)request; + sensorreadingresp_t* resp = (sensorreadingresp_t*)response; + ipmi::sensor::GetSensorResponse getResponse{}; static constexpr auto scanningEnabledBit = 6; const auto iter = sensors.find(reqptr->sennum); @@ -578,14 +620,14 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return legacyGetSensorReading(reqptr->sennum, response, data_len); } if (ipmi::sensor::Mutability::Read != - (iter->second.mutability & ipmi::sensor::Mutability::Read)) + (iter->second.mutability & ipmi::sensor::Mutability::Read)) { return IPMI_CC_ILLEGAL_COMMAND; } try { - getResponse = iter->second.getFunc(iter->second); + getResponse = iter->second.getFunc(iter->second); *data_len = getResponse.size(); memcpy(resp, getResponse.data(), *data_len); resp->operation = 1 << scanningEnabledBit; @@ -614,10 +656,8 @@ void getSensorThresholds(uint8_t sensorNum, auto service = ipmi::getService(bus, info.sensorInterface, info.sensorPath); - auto warnThresholds = ipmi::getAllDbusProperties(bus, - service, - info.sensorPath, - warningThreshIntf); + auto warnThresholds = ipmi::getAllDbusProperties( + bus, service, info.sensorPath, warningThreshIntf); double warnLow = mapbox::util::apply_visitor(ipmi::VariantToDoubleVisitor(), warnThresholds["WarningLow"]); @@ -627,25 +667,23 @@ void getSensorThresholds(uint8_t sensorNum, if (warnLow != 0) { warnLow *= pow(10, info.scale - info.exponentR); - response->lowerNonCritical = static_cast<uint8_t>(( - warnLow - info.scaledOffset) / info.coefficientM); + response->lowerNonCritical = static_cast<uint8_t>( + (warnLow - info.scaledOffset) / info.coefficientM); response->validMask |= static_cast<uint8_t>( - ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK); + ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK); } if (warnHigh != 0) { warnHigh *= pow(10, info.scale - info.exponentR); - response->upperNonCritical = static_cast<uint8_t>(( - warnHigh - info.scaledOffset) / info.coefficientM); + response->upperNonCritical = static_cast<uint8_t>( + (warnHigh - info.scaledOffset) / info.coefficientM); response->validMask |= static_cast<uint8_t>( - ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK); + ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK); } - auto critThresholds = ipmi::getAllDbusProperties(bus, - service, - info.sensorPath, - criticalThreshIntf); + auto critThresholds = ipmi::getAllDbusProperties( + bus, service, info.sensorPath, criticalThreshIntf); double critLow = mapbox::util::apply_visitor(ipmi::VariantToDoubleVisitor(), critThresholds["CriticalLow"]); double critHigh = mapbox::util::apply_visitor( @@ -654,25 +692,27 @@ void getSensorThresholds(uint8_t sensorNum, if (critLow != 0) { critLow *= pow(10, info.scale - info.exponentR); - response->lowerCritical = static_cast<uint8_t>(( - critLow - info.scaledOffset) / info.coefficientM); + response->lowerCritical = static_cast<uint8_t>( + (critLow - info.scaledOffset) / info.coefficientM); response->validMask |= static_cast<uint8_t>( - ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK); + ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK); } if (critHigh != 0) { critHigh *= pow(10, info.scale - info.exponentR); - response->upperCritical = static_cast<uint8_t>(( - critHigh - info.scaledOffset)/ info.coefficientM); + response->upperCritical = static_cast<uint8_t>( + (critHigh - info.scaledOffset) / info.coefficientM); response->validMask |= static_cast<uint8_t>( - ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK); + ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK); } } ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, ipmi_response_t response, - ipmi_data_len_t data_len, ipmi_context_t context) + ipmi_request_t request, + ipmi_response_t response, + ipmi_data_len_t data_len, + ipmi_context_t context) { constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value"; @@ -682,7 +722,7 @@ ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return IPMI_CC_REQ_DATA_LEN_INVALID; } - auto sensorNum = *(reinterpret_cast<const uint8_t *>(request)); + auto sensorNum = *(reinterpret_cast<const uint8_t*>(request)); *data_len = 0; const auto iter = sensors.find(sensorNum); @@ -693,11 +733,11 @@ ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd, const auto info = iter->second; - //Proceed only if the sensor value interface is implemented. + // Proceed only if the sensor value interface is implemented. if (info.propertyInterfaces.find(valueInterface) == info.propertyInterfaces.end()) { - //return with valid mask as 0 + // return with valid mask as 0 return IPMI_CC_OK; } @@ -710,7 +750,7 @@ ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd, } catch (std::exception& e) { - //Mask if the property is not present + // Mask if the property is not present responseData->validMask = 0; } @@ -724,7 +764,7 @@ ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, { ipmi_ret_t rc = IPMI_CC_INVALID; - printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); + printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n", netfn, cmd); *data_len = 0; return rc; @@ -776,8 +816,8 @@ ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return IPMI_CC_OK; } -void setUnitFieldsForObject(const ipmi::sensor::Info *info, - get_sdr::SensorDataFullRecordBody *body) +void setUnitFieldsForObject(const ipmi::sensor::Info* info, + get_sdr::SensorDataFullRecordBody* body) { namespace server = sdbusplus::xyz::openbmc_project::Sensor::server; try @@ -791,7 +831,8 @@ void setUnitFieldsForObject(const ipmi::sensor::Info *info, body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C; break; case server::Value::Unit::RPMS: - body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions + body->sensor_units_2_base = + get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions get_sdr::body::set_rate_unit(0b100, body); // per minute break; case server::Value::Unit::Volts: @@ -821,8 +862,8 @@ void setUnitFieldsForObject(const ipmi::sensor::Info *info, } } -ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body, - const ipmi::sensor::Info *info, +ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody* body, + const ipmi::sensor::Info* info, ipmi_data_len_t data_len) { /* Functional sensor case */ @@ -864,11 +905,11 @@ ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response, { auto req = reinterpret_cast<get_sdr::GetSdrReq*>(request); auto resp = reinterpret_cast<get_sdr::GetSdrResp*>(response); - get_sdr::SensorDataFruRecord record {}; + get_sdr::SensorDataFruRecord record{}; auto dataLength = 0; auto fru = frus.begin(); - uint8_t fruID {}; + uint8_t fruID{}; auto recordID = get_sdr::request::get_record_id(req); fruID = recordID - FRU_RECORD_ID_START; @@ -896,21 +937,18 @@ ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response, record.body.deviceTypeModifier = IPMIFruInventory; /* Device ID string */ - auto deviceID = fru->second[0].path.substr( - fru->second[0].path.find_last_of('/') + 1, - fru->second[0].path.length()); - + auto deviceID = + fru->second[0].path.substr(fru->second[0].path.find_last_of('/') + 1, + fru->second[0].path.length()); if (deviceID.length() > get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH) { get_sdr::body::set_device_id_strlen( - get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH, - &(record.body)); + get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH, &(record.body)); } else { - get_sdr::body::set_device_id_strlen(deviceID.length(), - &(record.body)); + get_sdr::body::set_device_id_strlen(deviceID.length(), &(record.body)); } strncpy(record.body.deviceID, deviceID.c_str(), @@ -918,12 +956,13 @@ ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response, if (++fru == frus.end()) { - get_sdr::response::set_next_record_id(END_OF_RECORD, resp); // last record + get_sdr::response::set_next_record_id(END_OF_RECORD, + resp); // last record } else { get_sdr::response::set_next_record_id( - (FRU_RECORD_ID_START + fru->first), resp); + (FRU_RECORD_ID_START + fru->first), resp); } if (req->bytes_to_read > (sizeof(*resp) - req->offset)) @@ -932,7 +971,7 @@ ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response, } else { - dataLength = req->bytes_to_read; + dataLength = req->bytes_to_read; } if (dataLength <= 0) @@ -940,9 +979,8 @@ ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response, return IPMI_CC_REQ_DATA_LEN_INVALID; } - memcpy(resp->record_data, - reinterpret_cast<uint8_t*>(&record) + req->offset, - (dataLength)); + memcpy(resp->record_data, reinterpret_cast<uint8_t*>(&record) + req->offset, + (dataLength)); *data_len = dataLength; *data_len += 2; // additional 2 bytes for next record ID @@ -955,8 +993,8 @@ ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_data_len_t data_len, ipmi_context_t context) { ipmi_ret_t ret = IPMI_CC_OK; - get_sdr::GetSdrReq *req = (get_sdr::GetSdrReq*)request; - get_sdr::GetSdrResp *resp = (get_sdr::GetSdrResp*)response; + get_sdr::GetSdrReq* req = (get_sdr::GetSdrReq*)request; + get_sdr::GetSdrResp* resp = (get_sdr::GetSdrResp*)response; get_sdr::SensorDataFullRecord record = {0}; if (req != NULL) { @@ -1011,9 +1049,9 @@ ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, { // we have reached till end of sensor, so assign the next record id // to 256(Max Sensor ID = 255) + FRU ID(may start with 0). - auto next_record_id = (frus.size()) ? - frus.begin()->first + FRU_RECORD_ID_START : - END_OF_RECORD; + auto next_record_id = + (frus.size()) ? frus.begin()->first + FRU_RECORD_ID_START + : END_OF_RECORD; get_sdr::response::set_next_record_id(next_record_id, resp); } @@ -1030,43 +1068,35 @@ ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return ret; } - void register_netfn_sen_functions() { // <Wildcard Command> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, - nullptr, ipmi_sen_wildcard, - PRIVILEGE_USER); + ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, nullptr, + ipmi_sen_wildcard, PRIVILEGE_USER); // <Get Sensor Type> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, - nullptr, ipmi_sen_get_sensor_type, - PRIVILEGE_USER); + ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, nullptr, + ipmi_sen_get_sensor_type, PRIVILEGE_USER); // <Set Sensor Reading and Event Status> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, - nullptr, ipmi_sen_set_sensor, - PRIVILEGE_OPERATOR); + ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, nullptr, + ipmi_sen_set_sensor, PRIVILEGE_OPERATOR); // <Get Sensor Reading> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, - nullptr, ipmi_sen_get_sensor_reading, - PRIVILEGE_USER); + ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, nullptr, + ipmi_sen_get_sensor_reading, PRIVILEGE_USER); // <Reserve Device SDR Repository> ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_RESERVE_DEVICE_SDR_REPO, - nullptr, ipmi_sen_reserve_sdr, - PRIVILEGE_USER); + nullptr, ipmi_sen_reserve_sdr, PRIVILEGE_USER); // <Get Device SDR Info> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR_INFO, - nullptr, ipmi_sen_get_sdr_info, - PRIVILEGE_USER); + ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR_INFO, nullptr, + ipmi_sen_get_sdr_info, PRIVILEGE_USER); // <Get Device SDR> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR, - nullptr, ipmi_sen_get_sdr, - PRIVILEGE_USER); + ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR, nullptr, + ipmi_sen_get_sdr, PRIVILEGE_USER); // <Get Sensor Thresholds> ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_THRESHOLDS, |