dbus-sdr: implement SDR Record Type 8
- implement SDR Record Type 8 sensor like ipmi_entity_get_sdr function
in sensorhandler.cpp, and will locate at the last of SDR list
TEST:
~# ipmitool sdr elist all -vvv
...
...
...
SDR record ID : 0x00d9
SDR record type : 0x08
SDR record next : 0x00da
SDR record bytes: 11
Getting 11 bytes from SDR at offset 5
SDR record ID : 0x00d9
SDR record ID : 0x00da
SDR record type : 0x08
SDR record next : 0xffff
SDR record bytes: 11
Getting 11 bytes from SDR at offset 5
SDR record ID : 0x00da
~# ipmitool raw 0x04 0x21 0x00 0x00 0xd9 0x00 0x00 0xff
da 00 d9 00 51 08 0b 1e 00 80 0b 03 0b 07 1d 00
1d 01
~# ipmitool raw 0x04 0x21 0x00 0x00 0xda 0x00 0x00 0xff
ff ff da 00 51 08 0b 1e 01 80 0b 08 0b 0b 1d 02
1d 03
Signed-off-by: Harvey Wu <Harvey.Wu@quantatw.com>
Change-Id: I4998532402158f299dcb34c29734b23b5f8dc719
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 4e971b3..81bdf23 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -19,6 +19,7 @@
#include "dbus-sdr/sdrutils.hpp"
#include "dbus-sdr/sensorutils.hpp"
#include "dbus-sdr/storagecommands.hpp"
+#include "entity_map_json.hpp"
#include <algorithm>
#include <array>
@@ -1925,8 +1926,13 @@
return GENERAL_ERROR;
}
- size_t lastRecord =
- getNumberOfSensors() + fruCount + ipmi::storage::type12Count - 1;
+ const auto& entityRecords =
+ ipmi::sensor::EntityInfoMapContainer::getContainer()
+ ->getIpmiEntityRecords();
+ size_t entityCount = entityRecords.size();
+
+ size_t lastRecord = getNumberOfSensors() + fruCount +
+ ipmi::storage::type12Count + entityCount - 1;
if (recordID == lastRecordIndex)
{
recordID = lastRecord;
@@ -1940,12 +1946,24 @@
if (recordID >= getNumberOfSensors())
{
- size_t fruIndex = recordID - getNumberOfSensors();
+ size_t sdrIndex = recordID - getNumberOfSensors();
- if (fruIndex >= fruCount)
+ if (sdrIndex >= fruCount + ipmi::storage::type12Count)
+ {
+ // handle type 8 entity map records
+ ipmi::sensor::EntityInfoMap::const_iterator entity =
+ entityRecords.find(static_cast<uint8_t>(
+ sdrIndex - fruCount - ipmi::storage::type12Count));
+ if (entity == entityRecords.end())
+ {
+ return IPMI_CC_SENSOR_INVALID;
+ }
+ recordData = ipmi::storage::getType8SDRs(entity, recordID);
+ }
+ else if (sdrIndex >= fruCount)
{
// handle type 12 hardcoded records
- size_t type12Index = fruIndex - fruCount;
+ size_t type12Index = sdrIndex - fruCount;
if (type12Index >= ipmi::storage::type12Count)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
@@ -1958,7 +1976,7 @@
{
// handle fru records
get_sdr::SensorDataFruRecord data;
- ret = ipmi::storage::getFruSdrs(ctx, fruIndex, data);
+ ret = ipmi::storage::getFruSdrs(ctx, sdrIndex, data);
if (ret != IPMI_CC_OK)
{
return GENERAL_ERROR;
@@ -2315,9 +2333,14 @@
return ipmi::response(ret);
}
+ const auto& entityRecords =
+ ipmi::sensor::EntityInfoMapContainer::getContainer()
+ ->getIpmiEntityRecords();
+ int entityCount = entityRecords.size();
+
auto& sensorTree = getSensorTree();
- size_t lastRecord =
- getNumberOfSensors() + fruCount + ipmi::storage::type12Count - 1;
+ size_t lastRecord = getNumberOfSensors() + fruCount +
+ ipmi::storage::type12Count + entityCount - 1;
uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF;
if (!getSensorSubtree(sensorTree) && sensorTree.empty())
diff --git a/dbus-sdr/storagecommands.cpp b/dbus-sdr/storagecommands.cpp
index 33be2dd..b76aa5e 100644
--- a/dbus-sdr/storagecommands.cpp
+++ b/dbus-sdr/storagecommands.cpp
@@ -1178,6 +1178,41 @@
return ipmi::responseInvalidCommand();
}
+std::vector<uint8_t>
+ getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity,
+ uint16_t recordId)
+{
+ std::vector<uint8_t> resp;
+ get_sdr::SensorDataEntityRecord data{};
+
+ /* Header */
+ get_sdr::header::set_record_id(recordId, &(data.header));
+ // Based on IPMI Spec v2.0 rev 1.1
+ data.header.sdr_version = SDR_VERSION;
+ data.header.record_type = 0x08;
+ data.header.record_length = sizeof(data.key) + sizeof(data.body);
+
+ /* Key */
+ data.key.containerEntityId = entity->second.containerEntityId;
+ data.key.containerEntityInstance = entity->second.containerEntityInstance;
+ get_sdr::key::set_flags(entity->second.isList, entity->second.isLinked,
+ &(data.key));
+ data.key.entityId1 = entity->second.containedEntities[0].first;
+ data.key.entityInstance1 = entity->second.containedEntities[0].second;
+
+ /* Body */
+ data.body.entityId2 = entity->second.containedEntities[1].first;
+ data.body.entityInstance2 = entity->second.containedEntities[1].second;
+ data.body.entityId3 = entity->second.containedEntities[2].first;
+ data.body.entityInstance3 = entity->second.containedEntities[2].second;
+ data.body.entityId4 = entity->second.containedEntities[3].first;
+ data.body.entityInstance4 = entity->second.containedEntities[3].second;
+
+ resp.insert(resp.end(), (uint8_t*)&data, ((uint8_t*)&data) + sizeof(data));
+
+ return resp;
+}
+
std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId)
{
std::vector<uint8_t> resp;
diff --git a/include/dbus-sdr/storagecommands.hpp b/include/dbus-sdr/storagecommands.hpp
index d0fa110..79feb56 100644
--- a/include/dbus-sdr/storagecommands.hpp
+++ b/include/dbus-sdr/storagecommands.hpp
@@ -107,6 +107,9 @@
ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count);
+std::vector<uint8_t>
+ getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity,
+ uint16_t recordId);
std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId);
std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId);
} // namespace storage