blob: 649bf20a40d3a54f84db5c752e2fe3843b12ea51 [file] [edit]
#pragma once
#include "config.h"
#include "activation.hpp"
#include "common/instance_id.hpp"
#include "common/types.hpp"
#include "device_updater.hpp"
#include "inventory_manager.hpp"
#include "requester/handler.hpp"
#include "requester/mctp_endpoint_discovery.hpp"
#include "update_manager.hpp"
#include <unordered_map>
#include <vector>
namespace pldm
{
namespace fw_update
{
constexpr uint8_t FW_UPDATE_DISCOVERY_RETRIES = 2;
/** @class Manager
*
* This class handles all the aspects of the PLDM FW update specification for
* the MCTP devices
*/
class Manager : public pldm::MctpDiscoveryHandlerIntf
{
public:
Manager() = delete;
Manager(const Manager&) = delete;
Manager(Manager&&) = delete;
Manager& operator=(const Manager&) = delete;
Manager& operator=(Manager&&) = delete;
~Manager() = default;
/** @brief Constructor
*
* @param[in] handler - PLDM request handler
*/
explicit Manager(Event& event,
requester::Handler<requester::Request>& handler,
pldm::InstanceIdDb& instanceIdDb) :
handler(handler),
inventoryMgr(handler, instanceIdDb, descriptorMap, componentInfoMap),
updateManager(event, handler, instanceIdDb, descriptorMap,
componentInfoMap)
{}
/** @brief Helper function to invoke registered handlers for
* the added MCTP endpoints
*
* @param[in] mctpInfos - information of discovered MCTP endpoints
*/
void handleMctpEndpoints(const TerminusInfos& mctpInfos) override
{
std::vector<mctp_eid_t> eids;
for (const auto& [tid, mctpInfo] : mctpInfos)
{
auto eid = std::get<pldm::eid>(mctpInfo);
auto network = std::get<NetworkId>(mctpInfo);
if (auto* transport = handler.getTransport())
{
transport->mapTid(tid, network, eid);
}
eids.push_back(eid);
}
inventoryMgr.discoverFDs(eids, FW_UPDATE_DISCOVERY_RETRIES);
}
/** @brief Helper function to invoke registered handlers for
* the removed MCTP endpoints
*
* @param[in] mctpInfos - information of removed MCTP endpoints
*/
void handleRemovedMctpEndpoints(const TerminusInfos& mctpInfos) override
{
for (const auto& [tid, mctpInfo] : mctpInfos)
{
if (auto* transport = handler.getTransport())
{
transport->unmapTid(tid);
}
}
}
/** @brief Helper function to invoke registered handlers for
* updating the availability status of the MCTP endpoint
*
* @param[in] mctpInfo - information of the target endpoint
* @param[in] availability - new availability status
*/
void updateMctpEndpointAvailability(const MctpInfo&, Availability) override
{
return;
}
/** @brief Get Active EIDs.
*
* @param[in] addr - MCTP address of terminus
* @param[in] terminiNames - MCTP terminus name
*/
std::optional<mctp_eid_t> getActiveEidByName(const std::string&) override
{
return std::nullopt;
}
std::optional<pldm_tid_t> allocateOrGetTid(
const MctpInfo& /*mctpInfo*/) override
{
// FW update doesn't manage TIDs
return std::nullopt;
}
PldmTransport* getTransport() override
{
return handler.getTransport();
}
/** @brief Handle PLDM request for the commands in the FW update
* specification
*
* @param[in] eid - Remote MCTP Endpoint ID
* @param[in] command - PLDM command code
* @param[in] request - PLDM request message
* @param[in] requestLen - PLDM request message length
* @return PLDM response message
*/
Response handleRequest(mctp_eid_t eid, Command command,
const pldm_msg* request, size_t reqMsgLen)
{
return updateManager.handleRequest(eid, command, request, reqMsgLen);
}
private:
/** @brief Reference to the PLDM request handler */
requester::Handler<requester::Request>& handler;
/** Descriptor information of all the discovered MCTP endpoints */
DescriptorMap descriptorMap;
/** Component information of all the discovered MCTP endpoints */
ComponentInfoMap componentInfoMap;
/** @brief PLDM firmware inventory manager */
InventoryManager inventoryMgr;
/** @brief PLDM firmware update manager */
UpdateManager updateManager;
};
} // namespace fw_update
} // namespace pldm