Make sensor/sdr list commands work on systems with > 255 sensors

The "ipmitool sdr elist" and "ipmitool sensor list" commands failed to
operate correctly on systems that contain more than 255 sensors. A
change made in the past assigned up to 255 sensors to LUN 0, 1, and
3. The code for iterating the SDR's did not get updated at the same
time. The SDR record number acted as the sensor number. This
incompatibility caused error response codes to be returned when sensor
number 255 (which is reserved) was accessed.

The change in this commit modifies the SDR access code to prevent
using the reserved sensor number. SDR records are still assigned in
order. The sensor number associated with the SDR are assigned to avoid
the reserved value, and in the same manner as code previously
submitted and merged.

Tested:
Installed the modified code on a SUT that enumerates more than 256
sensors.
Issued "ipmitool sensor list" and confirmed all sensors were
displayed. The "Get SDR 00ff command failed: Invalid data field in
request" error message was not displayed.
Issued "ipmitool sdr elist" and confirmed all sensors were
displayed. The "Get SDR 00ff command failed: Invalid data field in
request" error message was not displayed.
Confirmed the sensor number/LUN guard code was not activated.

Change-Id: I194a3116fdf255527a8c5036ee71b8b478c9b275
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/sensorcommands.cpp b/src/sensorcommands.cpp
index 8e17dc0..0cb4c04 100644
--- a/src/sensorcommands.cpp
+++ b/src/sensorcommands.cpp
@@ -1214,7 +1214,25 @@
 
     std::string connection;
     std::string path;
-    auto status = getSensorConnection(ctx, recordID, connection, path);
+    uint16_t sensNumFromRecID{recordID};
+    if ((recordID >= reservedSensorNumber) &&
+        (recordID < (2 * maxSensorsPerLUN)))
+    {
+        sensNumFromRecID = (recordID + 1) & maxSensorsPerLUN;
+        ctx->lun = 1;
+    }
+    else if ((recordID >= (2 * maxSensorsPerLUN)) &&
+             (recordID < maxIPMISensors))
+    {
+        sensNumFromRecID = (recordID + 2) & maxSensorsPerLUN;
+        ctx->lun = 3;
+    }
+    else if (recordID >= maxIPMISensors)
+    {
+        return GENERAL_ERROR;
+    }
+
+    auto status = getSensorConnection(ctx, sensNumFromRecID, connection, path);
     if (status)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
@@ -1230,7 +1248,7 @@
         return GENERAL_ERROR;
     }
     uint16_t sensorNum = getSensorNumberFromPath(path);
-    if (sensorNum == invalidSensorNumber)
+    if (sensorNum >= maxIPMISensors)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "getSensorDataRecord: invalidSensorNumber");
@@ -1239,6 +1257,12 @@
     uint8_t sensornumber = static_cast<uint8_t>(sensorNum);
     uint8_t lun = static_cast<uint8_t>(sensorNum >> 8);
 
+    if ((sensornumber != sensNumFromRecID) && (lun != ctx->lun))
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "getSensorDataRecord: sensor record mismatch");
+        return GENERAL_ERROR;
+    }
     get_sdr::SensorDataFullRecord record = {0};
 
     get_sdr::header::set_record_id(