Fix detection of invalid 'GetSensorReading'
This change fixes incorrect way to determine Get Sensor Reading value
availability.
In previous implementation proper value of '0' was treated as error.
IPMI spec defines 'reading/state unavailable' bit, which ME uses to
inform user about sensor reading being absent.
This change monitors that bit to determine outcome of Get Sensor Reading
call.
Alternative considered was to also look at 'sensor scanning disabled',
but after reading more documentation and checking ME implementation it
turns out that it affects only threshold events generation.
Testing:
- verified that 'nan' is set for unavailable sensor (PSU with PMBUS
cable cut-off)
- verified that for available sensor reporting '0', '0' value is
present instead of 'nan'
Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com>
Change-Id: Iaa940b808e36b9606fe78f7cef7bab2593275889
diff --git a/include/IpmbSensor.hpp b/include/IpmbSensor.hpp
index e1b1ddb..3b3ee15 100644
--- a/include/IpmbSensor.hpp
+++ b/include/IpmbSensor.hpp
@@ -37,6 +37,42 @@
elevenBitShift,
};
+namespace ipmi
+{
+namespace sensor
+{
+constexpr uint8_t netFn = 0x04;
+constexpr uint8_t getSensorReading = 0x2d;
+
+static bool isValid(const std::vector<uint8_t>& data)
+{
+ constexpr auto ReadingUnavailableBit = 5;
+
+ // Proper 'Get Sensor Reading' response has at least 4 bytes, including
+ // Completion Code. Our IPMB stack strips Completion Code from payload so we
+ // compare here against the rest of payload
+ if (data.size() < 3)
+ {
+ return false;
+ }
+
+ // Per IPMI 'Get Sensor Reading' specification
+ if (data[1] & (1 << ReadingUnavailableBit))
+ {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace sensor
+namespace me_bridge
+{
+constexpr uint8_t netFn = 0x2e;
+constexpr uint8_t sendRawPmbus = 0xd9;
+} // namespace me_bridge
+} // namespace ipmi
+
struct IpmbSensor : public Sensor
{
IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,