blob: be45eb7cdd8bb9ba0ba9527501b9da1f2b4129a8 [file] [log] [blame]
Tom Josephfb3bc062021-08-17 07:48:11 -07001#pragma once
2
Tom Josephfb3bc062021-08-17 07:48:11 -07003#include "activation.hpp"
Andrew Jeffery2abbce72023-10-18 10:17:35 +10304#include "common/instance_id.hpp"
Tom Josephfb3bc062021-08-17 07:48:11 -07005#include "common/types.hpp"
6#include "device_updater.hpp"
7#include "inventory_manager.hpp"
Tom Josephfb3bc062021-08-17 07:48:11 -07008#include "requester/handler.hpp"
Gilbert Chen44524a52022-02-14 12:12:25 +00009#include "requester/mctp_endpoint_discovery.hpp"
Tom Josephfb3bc062021-08-17 07:48:11 -070010#include "update_manager.hpp"
11
12#include <unordered_map>
13#include <vector>
14
15namespace pldm
16{
17
18namespace fw_update
19{
20
Tom Josephfb3bc062021-08-17 07:48:11 -070021/** @class Manager
22 *
23 * This class handles all the aspects of the PLDM FW update specification for
24 * the MCTP devices
25 */
Gilbert Chen44524a52022-02-14 12:12:25 +000026class Manager : public pldm::MctpDiscoveryHandlerIntf
Tom Josephfb3bc062021-08-17 07:48:11 -070027{
Tom Josephfb3bc062021-08-17 07:48:11 -070028 public:
29 Manager() = delete;
30 Manager(const Manager&) = delete;
31 Manager(Manager&&) = delete;
32 Manager& operator=(const Manager&) = delete;
33 Manager& operator=(Manager&&) = delete;
34 ~Manager() = default;
35
36 /** @brief Constructor
37 *
38 * @param[in] handler - PLDM request handler
39 */
40 explicit Manager(Event& event,
41 requester::Handler<requester::Request>& handler,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093042 pldm::InstanceIdDb& instanceIdDb) :
43 inventoryMgr(handler, instanceIdDb, descriptorMap, componentInfoMap),
44 updateManager(event, handler, instanceIdDb, descriptorMap,
Tom Josephfb3bc062021-08-17 07:48:11 -070045 componentInfoMap)
46 {}
47
Gilbert Chen44524a52022-02-14 12:12:25 +000048 /** @brief Helper function to invoke registered handlers for
49 * the added MCTP endpoints
Tom Josephfb3bc062021-08-17 07:48:11 -070050 *
Gilbert Chen44524a52022-02-14 12:12:25 +000051 * @param[in] mctpInfos - information of discovered MCTP endpoints
Tom Josephfb3bc062021-08-17 07:48:11 -070052 */
Gilbert Chen44524a52022-02-14 12:12:25 +000053 void handleMctpEndpoints(const MctpInfos& mctpInfos)
Tom Josephfb3bc062021-08-17 07:48:11 -070054 {
Gilbert Chen44524a52022-02-14 12:12:25 +000055 std::vector<mctp_eid_t> eids;
56 for (const auto& mctpInfo : mctpInfos)
57 {
58 eids.emplace_back(std::get<mctp_eid_t>(mctpInfo));
59 }
60
Tom Josephfb3bc062021-08-17 07:48:11 -070061 inventoryMgr.discoverFDs(eids);
62 }
63
Gilbert Chen44524a52022-02-14 12:12:25 +000064 /** @brief Helper function to invoke registered handlers for
65 * the removed MCTP endpoints
66 *
67 * @param[in] mctpInfos - information of removed MCTP endpoints
68 */
69 void handleRemovedMctpEndpoints(const MctpInfos&)
70 {
71 return;
72 }
73
Tom Josephfb3bc062021-08-17 07:48:11 -070074 /** @brief Handle PLDM request for the commands in the FW update
75 * specification
76 *
77 * @param[in] eid - Remote MCTP Endpoint ID
78 * @param[in] command - PLDM command code
79 * @param[in] request - PLDM request message
80 * @param[in] requestLen - PLDM request message length
81 * @return PLDM response message
82 */
83 Response handleRequest(mctp_eid_t eid, Command command,
84 const pldm_msg* request, size_t reqMsgLen)
85 {
86 return updateManager.handleRequest(eid, command, request, reqMsgLen);
87 }
88
89 private:
90 /** Descriptor information of all the discovered MCTP endpoints */
91 DescriptorMap descriptorMap;
92
93 /** Component information of all the discovered MCTP endpoints */
94 ComponentInfoMap componentInfoMap;
95
96 /** @brief PLDM firmware inventory manager */
97 InventoryManager inventoryMgr;
98
99 /** @brief PLDM firmware update manager */
100 UpdateManager updateManager;
101};
102
103} // namespace fw_update
104
105} // namespace pldm