blob: 14ac450a53eb4fa05d73dcbbd6a9c81a2fb6633e [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) :
Unive Tien8b169dc2024-11-25 09:34:39 +080043 inventoryMgr(handler, instanceIdDb, descriptorMap,
44 downstreamDescriptorMap, componentInfoMap),
Andrew Jefferya330b2f2023-05-04 14:55:37 +093045 updateManager(event, handler, instanceIdDb, descriptorMap,
Tom Josephfb3bc062021-08-17 07:48:11 -070046 componentInfoMap)
47 {}
48
Gilbert Chen44524a52022-02-14 12:12:25 +000049 /** @brief Helper function to invoke registered handlers for
50 * the added MCTP endpoints
Tom Josephfb3bc062021-08-17 07:48:11 -070051 *
Gilbert Chen44524a52022-02-14 12:12:25 +000052 * @param[in] mctpInfos - information of discovered MCTP endpoints
Tom Josephfb3bc062021-08-17 07:48:11 -070053 */
Gilbert Chen44524a52022-02-14 12:12:25 +000054 void handleMctpEndpoints(const MctpInfos& mctpInfos)
Tom Josephfb3bc062021-08-17 07:48:11 -070055 {
Gilbert Chen44524a52022-02-14 12:12:25 +000056 std::vector<mctp_eid_t> eids;
57 for (const auto& mctpInfo : mctpInfos)
58 {
59 eids.emplace_back(std::get<mctp_eid_t>(mctpInfo));
60 }
61
Tom Josephfb3bc062021-08-17 07:48:11 -070062 inventoryMgr.discoverFDs(eids);
63 }
64
Gilbert Chen44524a52022-02-14 12:12:25 +000065 /** @brief Helper function to invoke registered handlers for
66 * the removed MCTP endpoints
67 *
68 * @param[in] mctpInfos - information of removed MCTP endpoints
69 */
70 void handleRemovedMctpEndpoints(const MctpInfos&)
71 {
72 return;
73 }
74
Chau Ly75e00422024-03-19 12:33:08 +000075 /** @brief Helper function to invoke registered handlers for
76 * updating the availability status of the MCTP endpoint
77 *
78 * @param[in] mctpInfo - information of the target endpoint
79 * @param[in] availability - new availability status
80 */
81 void updateMctpEndpointAvailability(const MctpInfo&, Availability)
82 {
83 return;
84 }
85
Tom Josephfb3bc062021-08-17 07:48:11 -070086 /** @brief Handle PLDM request for the commands in the FW update
87 * specification
88 *
89 * @param[in] eid - Remote MCTP Endpoint ID
90 * @param[in] command - PLDM command code
91 * @param[in] request - PLDM request message
92 * @param[in] requestLen - PLDM request message length
93 * @return PLDM response message
94 */
95 Response handleRequest(mctp_eid_t eid, Command command,
96 const pldm_msg* request, size_t reqMsgLen)
97 {
98 return updateManager.handleRequest(eid, command, request, reqMsgLen);
99 }
100
101 private:
102 /** Descriptor information of all the discovered MCTP endpoints */
103 DescriptorMap descriptorMap;
104
Unive Tien8b169dc2024-11-25 09:34:39 +0800105 /** Downstream descriptor information of all the discovered MCTP endpoints
106 */
107 DownstreamDescriptorMap downstreamDescriptorMap;
108
Tom Josephfb3bc062021-08-17 07:48:11 -0700109 /** Component information of all the discovered MCTP endpoints */
110 ComponentInfoMap componentInfoMap;
111
112 /** @brief PLDM firmware inventory manager */
113 InventoryManager inventoryMgr;
114
115 /** @brief PLDM firmware update manager */
116 UpdateManager updateManager;
117};
118
119} // namespace fw_update
120
121} // namespace pldm