dbus-sdr: fix the vector size in sdrWriteTable and sdrStatsTable

- The original padEntries size is only 0-255 because the input
  index size is uint8. But if sensor number > 255, the size of
  padEntries will be different from the size of sensor map, so
  the result value when using getWritePermission will be incorrect.

TEST:
Before:
ipmitool raw -l 0 0x04 0x30 0x19 0xff 127 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Unable to send RAW command (channel=0x0 netfn=0x4 lun=0x0 cmd=0x30 rsp=0xce): Command response could not be provided
ipmitool raw -l 1 0x04 0x30 0x19 0xff 127 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Unable to send RAW command (channel=0x0 netfn=0x4 lun=0x1 cmd=0x30 rsp=0xce): Command response could not be provided

After:
ipmitool raw -l 0 0x04 0x30 0x19 0xff 127 0x00 0x00 0x00 0x00 0x00 0x00 0x00
ipmitool raw -l 1 0x04 0x30 0x19 0xff 127 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Unable to send RAW command (channel=0x0 netfn=0x4 lun=0x1 cmd=0x30 rsp=0xce): Command response could not be provided

Signed-off-by: Harvey.Wu <Harvey.Wu@quantatw.com>
Change-Id: Idf6f4f31a1a9d2dd3cc87ebe3a4dc4ca4b283f7c
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 4d35009..05f5edf 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -625,7 +625,8 @@
         }
 
         // Only allow external SetSensor if write permission granted
-        if (!details::sdrWriteTable.getWritePermission(sensorNumber))
+        if (!details::sdrWriteTable.getWritePermission((ctx->lun << 8) |
+                                                       sensorNumber))
         {
             return ipmi::responseResponseError();
         }
@@ -852,12 +853,14 @@
         }
 
         // Keep stats on the reading just obtained, even if it is "NaN"
-        if (details::sdrStatsTable.updateReading(sensnum, reading, byteValue))
+        if (details::sdrStatsTable.updateReading((ctx->lun << 8) | sensnum,
+                                                 reading, byteValue))
         {
             // This is the first reading, show the coefficients
             double step = (max - min) / 255.0;
             std::cerr << "IPMI sensor "
-                      << details::sdrStatsTable.getName(sensnum)
+                      << details::sdrStatsTable.getName((ctx->lun << 8) |
+                                                        sensnum)
                       << ": Range min=" << min << " max=" << max
                       << ", step=" << step
                       << ", Coefficients mValue=" << static_cast<int>(mValue)
@@ -1597,7 +1600,6 @@
                         const std::string& path,
                         get_sdr::SensorDataFullRecord& record)
 {
-    uint8_t sensornumber = static_cast<uint8_t>(sensorNum);
     constructSensorSdrHeaderKey(sensorNum, recordID, record);
 
     DbusInterfaceMap sensorMap;
@@ -1715,7 +1717,7 @@
                  sizeof(record.body.id_string));
 
     // Remember the sensor name, as determined for this sensor number
-    details::sdrStatsTable.updateName(sensornumber, name);
+    details::sdrStatsTable.updateName(sensorNum, name);
 
     bool sensorSettable = false;
     auto mutability =
@@ -1728,7 +1730,7 @@
     get_sdr::body::init_settable_state(sensorSettable, &record.body);
 
     // Grant write permission to sensors deemed externally settable
-    details::sdrWriteTable.setWritePermission(sensornumber, sensorSettable);
+    details::sdrWriteTable.setWritePermission(sensorNum, sensorSettable);
 
     IPMIThresholds thresholdData;
     try
@@ -1865,7 +1867,6 @@
                     const std::string& path,
                     get_sdr::SensorDataEventRecord& record)
 {
-    uint8_t sensornumber = static_cast<uint8_t>(sensorNum);
     constructEventSdrHeaderKey(sensorNum, recordID, record);
 
     DbusInterfaceMap sensorMap;
@@ -1901,7 +1902,7 @@
     std::memcpy(record.body.id_string, name.c_str(), nameSize);
 
     // Remember the sensor name, as determined for this sensor number
-    details::sdrStatsTable.updateName(sensornumber, name);
+    details::sdrStatsTable.updateName(sensorNum, name);
 
     return true;
 }