fix sdr count when number > 255

- After PR-60906, it will count the fru data and type 12 sensors.
  But when SDR count > 255, there are some problems.

- If the lun of cmd isn't 0, the start position of recordID need to be
  updated.
- Using if condition to add type 12 sensors. Because if sensor number
  + fru device is 254, it will overflow after adding 2 type 12 sensors.
- The type of sdrCount is uint8, which means the maximum value is 255,
  so it needs to break while loop if the count reaches 255.

refs:
https://gerrit.openbmc.org/c/openbmc/phosphor-host-ipmid/+/60906

TEST:
root@bmc:~# ipmitool sdr elist | wc -l
281 => 0x119
root@bmc:~# ipmitool sdr elist all | wc -l
295 => 0x127

Before:
root@bmc:~# ipmitool raw -l 0 0x04 0x20 0x00
 ff 83 c8 56 a2 63
root@bmc:~# ipmitool raw -l 0 0x04 0x20 0x01 ERROR
 27 83 c8 56 a2 63
=> count overflow
root@bmc:~# ipmitool raw -l 1 0x04 0x20 0x00
 1a 83 c8 56 a2 63
root@bmc:~# ipmitool raw -l 1 0x04 0x20 0x01 ERROR
 1c 83 c8 56 a2 63
=> doesn't count the fru data

After:
root@bmc:~# ipmitool raw -l 0 0x04 0x20 0x00
 ff 83 3e 2c a3 63
root@bmc:~# ipmitool raw -l 0 0x04 0x20 0x01
 ff 83 3e 2c a3 63
root@bmc:~# ipmitool raw -l 1 0x04 0x20 0x00
 1a 83 3e 2c a3 63
root@bmc:~# ipmitool raw -l 1 0x04 0x20 0x01
 28 83 3e 2c a3 63

If count < 255,
root@bmc:~# ipmitool sdr elist | wc -l
151
root@bmc:~# ipmitool sdr elist all | wc -l
165
root@bmc:~# ipmitool raw -l 0 0x04 0x20 0x00
 97 81 f0 2b a2 63
root@bmc:~# ipmitool raw -l 0 0x04 0x20 0x01
 a5 81 f0 2b a2 63

Signed-off-by: Harvey Wu <Harvey.Wu@quantatw.com>
Change-Id: Ic4645c82d85e154bea5dc7fdd6b54d1331e58c36
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index c57a1a2..ad81fd8 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -2190,6 +2190,15 @@
     {
         auto& ipmiDecoratorPaths = getIpmiDecoratorPaths(ctx);
 
+        if (ctx->lun == 1)
+        {
+            recordID += maxSensorsPerLUN;
+        }
+        else if (ctx->lun == 3)
+        {
+            recordID += maxSensorsPerLUN * 2;
+        }
+
         // Count the number of Type 1 SDR entries assigned to the LUN
         while (!getSensorDataRecord(
             ctx, ipmiDecoratorPaths.value_or(std::unordered_set<std::string>()),
@@ -2223,12 +2232,19 @@
                     sdrCount++;
                 }
             }
-            else if (hdr->record_type == get_sdr::SENSOR_DATA_FRU_RECORD)
+            else if (hdr->record_type == get_sdr::SENSOR_DATA_FRU_RECORD ||
+                     hdr->record_type == get_sdr::SENSOR_DATA_MGMT_CTRL_LOCATOR)
             {
                 sdrCount++;
             }
+
+            // Because response count data is 1 byte, so sdrCount need to avoid
+            // overflow.
+            if (sdrCount == maxSensorsPerLUN)
+            {
+                break;
+            }
         }
-        sdrCount += ipmi::storage::type12Count;
     }
     else if (count.value_or(0) == getSensorCount)
     {