blob: 2e75f6ced9e8678264fbdd7d98bc477e6a0872df [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
Unive Tien7ad45b42025-08-18 06:04:53 +000036 /**
37 * @brief Constructor for the PLDM Firmware Update Manager
Tom Josephfb3bc062021-08-17 07:48:11 -070038 *
Unive Tien7ad45b42025-08-18 06:04:53 +000039 * @param[in] dbusHandler - Pointer to the D-Bus handler used for querying
40 * inventory and board paths
41 * @param[in] event - Reference to the io_context event object for
42 * asynchronous operations
43 * @param[in] handler - Reference to the PLDM request handler for processing
44 * PLDM requests
45 * @param[in] instanceIdDb - Reference to the InstanceId database for
46 * managing PLDM instance IDs
Tom Josephfb3bc062021-08-17 07:48:11 -070047 */
Unive Tien7ad45b42025-08-18 06:04:53 +000048 explicit Manager(const pldm::utils::DBusHandler* dbusHandler, Event& event,
Tom Josephfb3bc062021-08-17 07:48:11 -070049 requester::Handler<requester::Request>& handler,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093050 pldm::InstanceIdDb& instanceIdDb) :
Unive Tien7ad45b42025-08-18 06:04:53 +000051 inventoryMgr(dbusHandler, handler, instanceIdDb, descriptorMap,
52 downstreamDescriptorMap, componentInfoMap, configurations),
Andrew Jefferya330b2f2023-05-04 14:55:37 +093053 updateManager(event, handler, instanceIdDb, descriptorMap,
Tom Josephfb3bc062021-08-17 07:48:11 -070054 componentInfoMap)
55 {}
56
Gilbert Chen44524a52022-02-14 12:12:25 +000057 /** @brief Helper function to invoke registered handlers for
58 * the added MCTP endpoints
Tom Josephfb3bc062021-08-17 07:48:11 -070059 *
Gilbert Chen44524a52022-02-14 12:12:25 +000060 * @param[in] mctpInfos - information of discovered MCTP endpoints
Tom Josephfb3bc062021-08-17 07:48:11 -070061 */
Unive Tien7ad45b42025-08-18 06:04:53 +000062 void handleMctpEndpoints(const MctpInfos& mctpInfos) override
Tom Josephfb3bc062021-08-17 07:48:11 -070063 {
Unive Tien7ad45b42025-08-18 06:04:53 +000064 inventoryMgr.discoverFDs(mctpInfos);
65 }
Gilbert Chen44524a52022-02-14 12:12:25 +000066
Unive Tien7ad45b42025-08-18 06:04:53 +000067 /** @brief Helper function to invoke registered handlers for
68 * the updated EM configurations
69 *
70 * @param[in] configurations - updated EM configurations
71 */
72 void handleConfigurations(const Configurations& configurations) override
73 {
74 this->configurations = configurations;
Tom Josephfb3bc062021-08-17 07:48:11 -070075 }
76
Gilbert Chen44524a52022-02-14 12:12:25 +000077 /** @brief Helper function to invoke registered handlers for
78 * the removed MCTP endpoints
79 *
80 * @param[in] mctpInfos - information of removed MCTP endpoints
81 */
Unive Tien7ad45b42025-08-18 06:04:53 +000082 void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) override
Gilbert Chen44524a52022-02-14 12:12:25 +000083 {
Unive Tien7ad45b42025-08-18 06:04:53 +000084 inventoryMgr.removeFDs(mctpInfos);
Gilbert Chen44524a52022-02-14 12:12:25 +000085 }
86
Chau Ly75e00422024-03-19 12:33:08 +000087 /** @brief Helper function to invoke registered handlers for
88 * updating the availability status of the MCTP endpoint
89 *
90 * @param[in] mctpInfo - information of the target endpoint
91 * @param[in] availability - new availability status
92 */
Unive Tien7ad45b42025-08-18 06:04:53 +000093 void updateMctpEndpointAvailability(const MctpInfo&, Availability) override
Chau Ly75e00422024-03-19 12:33:08 +000094 {
95 return;
96 }
97
Tom Josephfb3bc062021-08-17 07:48:11 -070098 /** @brief Handle PLDM request for the commands in the FW update
99 * specification
100 *
101 * @param[in] eid - Remote MCTP Endpoint ID
102 * @param[in] command - PLDM command code
103 * @param[in] request - PLDM request message
104 * @param[in] requestLen - PLDM request message length
105 * @return PLDM response message
106 */
107 Response handleRequest(mctp_eid_t eid, Command command,
108 const pldm_msg* request, size_t reqMsgLen)
109 {
110 return updateManager.handleRequest(eid, command, request, reqMsgLen);
111 }
112
Thu Nguyen38e12aa2025-01-21 22:47:56 +0000113 /** @brief Get Active EIDs.
114 *
115 * @param[in] addr - MCTP address of terminus
116 * @param[in] terminiNames - MCTP terminus name
117 */
Unive Tien7ad45b42025-08-18 06:04:53 +0000118 std::optional<mctp_eid_t> getActiveEidByName(const std::string&) override
Thu Nguyen38e12aa2025-01-21 22:47:56 +0000119 {
120 return std::nullopt;
121 }
122
Tom Josephfb3bc062021-08-17 07:48:11 -0700123 private:
124 /** Descriptor information of all the discovered MCTP endpoints */
125 DescriptorMap descriptorMap;
126
Unive Tien8b169dc2024-11-25 09:34:39 +0800127 /** Downstream descriptor information of all the discovered MCTP endpoints
128 */
129 DownstreamDescriptorMap downstreamDescriptorMap;
130
Tom Josephfb3bc062021-08-17 07:48:11 -0700131 /** Component information of all the discovered MCTP endpoints */
132 ComponentInfoMap componentInfoMap;
133
Unive Tien7ad45b42025-08-18 06:04:53 +0000134 /** Configuration bindings from the Entity Manager */
135 Configurations configurations;
136
Tom Josephfb3bc062021-08-17 07:48:11 -0700137 /** @brief PLDM firmware inventory manager */
138 InventoryManager inventoryMgr;
139
140 /** @brief PLDM firmware update manager */
141 UpdateManager updateManager;
142};
143
144} // namespace fw_update
145
146} // namespace pldm