fw_update: InventoryManager: Add Downstream Devices Support
In DSP0267_1.1.0, a Firmware Device can supports one or more
Downstream Devices to perform get firmware version or firmware
update. Add discovery of Downstream Devices, query the Downstream
Devices Descriptor if the Firmware Device support it.
The code is developed based on DSP0267_1.1.0 Section 10.3
QueryDownstreamDevices command format, Section 10.4
QueryDownstreamIdentifiers command format.
Tested: Add unit tests for the new command handlers.
Change-Id: Iad28b898b5a0799b2b145d38958bba78e9719f4e
Signed-off-by: Unive Tien <unive.tien.wiwynn@gmail.com>
diff --git a/fw-update/test/inventory_manager_test.cpp b/fw-update/test/inventory_manager_test.cpp
index 9d80be2..678d9bb 100644
--- a/fw-update/test/inventory_manager_test.cpp
+++ b/fw-update/test/inventory_manager_test.cpp
@@ -19,7 +19,7 @@
reqHandler(nullptr, event, instanceIdDb, false, seconds(1), 2,
milliseconds(100)),
inventoryManager(reqHandler, instanceIdDb, outDescriptorMap,
- outComponentInfoMap)
+ outDownstreamDescriptorMap, outComponentInfoMap)
{}
int fd = -1;
@@ -28,6 +28,7 @@
requester::Handler<requester::Request> reqHandler;
InventoryManager inventoryManager;
DescriptorMap outDescriptorMap{};
+ DownstreamDescriptorMap outDownstreamDescriptorMap{};
ComponentInfoMap outComponentInfoMap{};
};
@@ -100,6 +101,51 @@
EXPECT_EQ(outDescriptorMap.size(), 0);
}
+TEST_F(InventoryManagerTest, handleQueryDownstreamIdentifierResponse)
+{
+ constexpr uint8_t eid = 1;
+ constexpr uint8_t downstreamDeviceCount = 1;
+ constexpr uint32_t downstreamDeviceLen = 11;
+ constexpr size_t respPayloadLength =
+ PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN + downstreamDeviceLen;
+
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength>
+ queryDownstreamIdentifiersResp{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
+ 0x0B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
+ 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 0x15};
+ auto responseMsg = new (queryDownstreamIdentifiersResp.data()) pldm_msg;
+
+ inventoryManager.queryDownstreamIdentifiers(eid, responseMsg,
+ respPayloadLength);
+
+ DownstreamDevices downstreamDevices = {
+ {0,
+ {{PLDM_FWUP_IANA_ENTERPRISE_ID,
+ std::vector<uint8_t>{0x00, 0x00, 0xa0, 0x15}}}}};
+ DownstreamDescriptorMap refDownstreamDescriptorMap{
+ {eid, downstreamDevices}};
+
+ ASSERT_EQ(outDownstreamDescriptorMap.size(), downstreamDeviceCount);
+ ASSERT_EQ(outDownstreamDescriptorMap.size(),
+ refDownstreamDescriptorMap.size());
+ ASSERT_EQ(outDownstreamDescriptorMap, refDownstreamDescriptorMap);
+}
+
+TEST_F(InventoryManagerTest, handleQueryDownstreamIdentifierResponseErrorCC)
+{
+ constexpr size_t respPayloadLength = 1;
+ constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength>
+ queryDownstreamIdentifiersResp{0x00, 0x00, 0x00, 0x01};
+ const auto responseMsg =
+ new (const_cast<unsigned char*>(queryDownstreamIdentifiersResp.data()))
+ pldm_msg;
+ inventoryManager.queryDownstreamIdentifiers(1, responseMsg,
+ respPayloadLength);
+
+ ASSERT_EQ(outDownstreamDescriptorMap.size(), 0);
+}
+
TEST_F(InventoryManagerTest, getFirmwareParametersResponse)
{
// constexpr uint16_t compCount = 2;