dbus-sdr: sensorcommands: Add a basic handler to set sensor readings

FEATURE_DYNAMIC_SENSORS_WRITE is used to enable the set sensor handler.
To enable the sensor writes add `--enable-dynamic_sensors_write` to the
compile flags.

Convert sensor writes to double from raw IPMI value.
The 8-bit value in the IPMI Set Sensor command is not a
literal value. It is a floating point value encoded using
the m, b, rExp, and bExp that are reported in the SDR.

Convert the raw 8-bit value to a floating point value according to the
IPMI spec. This implementation only supports linear sensors.
sdr_convert_sensor_reading() from ipmitool is a good reference should
you need a more feature complete implementation in the future [1].

  [1]: https://github.com/ipmitool/ipmitool/blob/42a023ff0726c80e8cc7d30315b987fe568a981d/lib/ipmi_sdr.c#L360

Interpreting bSigned correctly if IPMI indicates the byte is signed
Breaking up the complicated math expression into multiple lines
Making sure std::pow uses the correct type override of double
Adding the input byte to the logging

Tested:

// Before
$ ipmitool sensor list | grep fan
fan0_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan1_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan2_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan3_pwm         | 68.600     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan4_pwm         | 89.768     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan0_tach        | 8428.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan1_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan2_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan3_tach        | 8918.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan4_tach        | 8134.000   | RPM        | ok    | na        | na        | na        | na        | na        | na

// After setting fan3 to 0 pwm.
$ ipmitool sensor list | grep fan
fan0_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan1_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan2_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan3_pwm         | 3.920      | unspecified | ok    | na        | na        | na        | na        | na        | na
fan4_pwm         | 89.768     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan0_tach        | 8428.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan1_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan2_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan3_tach        | 0.000      | RPM        | ok    | na        | na        | na        | na        | na        | na
fan4_tach        | 8134.000   | RPM        | ok    | na        | na        | na        | na        | na        | na       | na        | na        | na        | na

Signed-off-by: Peter Lundgren <peterlundgren@google.com>
Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: Ib26c443480382224092a83662e060df3b759da5c
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/configure.ac b/configure.ac
index e29b538..dcf5e79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -266,6 +266,25 @@
       )
 AM_CONDITIONAL([FEATURE_IPMI_WHITELIST], [test x$ipmi_whitelist = xtrue])
 
+# Dynamic sensors stack write permission is disabled by default; offer a way to enable it
+# Change to true if you wish to allow external IPMI users to modify your sensor
+# values, and you are OK with the security implications of doing so.
+AC_ARG_ENABLE([dynamic_sensors_write],
+    [ --enable-dynamic_sensors_write   Enable/disable Dynamic Sensors writes],
+    [case "${enableval}" in
+      yes) dynamic_sensors_write=true ;;
+      no) dynamic_sensors_write=false ;;
+      *) AC_MSG_ERROR([bad value ${enableval} for --enable-dynamic_sensors_write]) ;;
+      esac],[dynamic_sensors_write=false]
+      )
+
+AS_IF([test x$dynamic_sensors_write = xtrue],
+    AC_MSG_NOTICE([Enabling dynamic sensors write feature])
+    [cpp_flags="$cpp_flags -DFEATURE_DYNAMIC_SENSORS_WRITE"]
+    AC_SUBST([CPPFLAGS], [$cpp_flags]),
+    AC_MSG_WARN([Disabling dynamic sensors write feature])
+)
+
 # Dynamic sensors stack is enabled by default; offer a way to disable it
 AC_ARG_ENABLE([dynamic_sensors],
     [ --enable-dynamic_sensors   Enable/disable Dynamic Sensors stack],