Allow more than 256 IPMI sensors in a system

Systems with more than 255 IPMI sensors report strange values for
sensors assigned beyond the 255 limit for a single LUN. This is due to
the sensor number assignment rolling over to 0, and then applying the
most recent SDR values to the sensor calculation.

This change assigns up to 255 sensors to a single LUN (0xFF is
reserved). When the 256th sensor is assigned the sensor gets placed in
the LUN. LUNs 0, 1, and 3 are used, as LUN 2 is special.

Another guard has been created that throws an exception when more than
765 sensors have been assigned. This makes it obvious to the system
designer the limit for IPMI sensors has been reached.

Tested:
Forced the maxmimum number of sensors in the system to be 63 per LUN.

"ipmitool sdr elist" returned correct values for every sensor even
when the sensor number displayed in the printout matched the value of
a sensor printed earlier.

"ipmitool sensor get P3V3" returns a valid reading. In my test "P3V3"
was in LUN1.

"ipmitool raw 4 0x20 0" reported 63 sensors for LUN0, and that LUN0
and LUN1 had sensors.

"ipmitool raw -l 1 4 0x20 0" reported the remaining sensor count.

"ipmitool raw 0xa 0x2d 0" returns the correct value for LUN0 Sensor 0

"ipmitool raw -l 1 0xa 0x2d 0" returns the correct value for LUN1
Sensor 0

Change-Id: Ic1708b66339e57b1b765f5a9a684e829a0ec8fba
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/include/sensorcommands.hpp b/include/sensorcommands.hpp
index c0d7853..a7f9fb2 100644
--- a/include/sensorcommands.hpp
+++ b/include/sensorcommands.hpp
@@ -121,7 +121,8 @@
 namespace ipmi
 {
 extern SensorSubTree sensorTree;
-static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string& connection,
+static ipmi_ret_t getSensorConnection(ipmi::Context::ptr ctx, uint8_t sensnum,
+                                      std::string& connection,
                                       std::string& path)
 {
     if (sensorTree.empty() && !getSensorSubtree(sensorTree))
@@ -129,22 +130,22 @@
         return IPMI_CC_RESPONSE_ERROR;
     }
 
-    if (sensorTree.size() < (sensnum + 1))
+    if (ctx == nullptr)
+    {
+        return IPMI_CC_RESPONSE_ERROR;
+    }
+
+    path = getPathFromSensorNumber((ctx->lun << 8) | sensnum);
+    if (path.empty())
     {
         return IPMI_CC_INVALID_FIELD_REQUEST;
     }
 
-    uint8_t sensorIndex = sensnum;
     for (const auto& sensor : sensorTree)
     {
-        if (sensorIndex-- == 0)
+        if (path == sensor.first)
         {
-            if (!sensor.second.size())
-            {
-                return IPMI_CC_RESPONSE_ERROR;
-            }
             connection = sensor.second.begin()->first;
-            path = sensor.first;
             break;
         }
     }