Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 3 | #include "activation.hpp" |
Andrew Jeffery | 2abbce7 | 2023-10-18 10:17:35 +1030 | [diff] [blame] | 4 | #include "common/instance_id.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 5 | #include "common/types.hpp" |
| 6 | #include "device_updater.hpp" |
| 7 | #include "inventory_manager.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 8 | #include "requester/handler.hpp" |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 9 | #include "requester/mctp_endpoint_discovery.hpp" |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 10 | #include "update_manager.hpp" |
| 11 | |
| 12 | #include <unordered_map> |
| 13 | #include <vector> |
| 14 | |
| 15 | namespace pldm |
| 16 | { |
| 17 | |
| 18 | namespace fw_update |
| 19 | { |
| 20 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 21 | /** @class Manager |
| 22 | * |
| 23 | * This class handles all the aspects of the PLDM FW update specification for |
| 24 | * the MCTP devices |
| 25 | */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 26 | class Manager : public pldm::MctpDiscoveryHandlerIntf |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 27 | { |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 28 | 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 Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 36 | /** |
| 37 | * @brief Constructor for the PLDM Firmware Update Manager |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 38 | * |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 39 | * @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 Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 47 | */ |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 48 | explicit Manager(const pldm::utils::DBusHandler* dbusHandler, Event& event, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 49 | requester::Handler<requester::Request>& handler, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 50 | pldm::InstanceIdDb& instanceIdDb) : |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 51 | inventoryMgr(dbusHandler, handler, instanceIdDb, descriptorMap, |
| 52 | downstreamDescriptorMap, componentInfoMap, configurations), |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 53 | updateManager(event, handler, instanceIdDb, descriptorMap, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 54 | componentInfoMap) |
| 55 | {} |
| 56 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 57 | /** @brief Helper function to invoke registered handlers for |
| 58 | * the added MCTP endpoints |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 59 | * |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 60 | * @param[in] mctpInfos - information of discovered MCTP endpoints |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 61 | */ |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 62 | void handleMctpEndpoints(const MctpInfos& mctpInfos) override |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 63 | { |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 64 | inventoryMgr.discoverFDs(mctpInfos); |
| 65 | } |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 66 | |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 67 | /** @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 Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 77 | /** @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 Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 82 | void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) override |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 83 | { |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 84 | inventoryMgr.removeFDs(mctpInfos); |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 87 | /** @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 Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 93 | void updateMctpEndpointAvailability(const MctpInfo&, Availability) override |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 94 | { |
| 95 | return; |
| 96 | } |
| 97 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 98 | /** @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 Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame] | 113 | /** @brief Get Active EIDs. |
| 114 | * |
| 115 | * @param[in] addr - MCTP address of terminus |
| 116 | * @param[in] terminiNames - MCTP terminus name |
| 117 | */ |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 118 | std::optional<mctp_eid_t> getActiveEidByName(const std::string&) override |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame] | 119 | { |
| 120 | return std::nullopt; |
| 121 | } |
| 122 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 123 | private: |
| 124 | /** Descriptor information of all the discovered MCTP endpoints */ |
| 125 | DescriptorMap descriptorMap; |
| 126 | |
Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 127 | /** Downstream descriptor information of all the discovered MCTP endpoints |
| 128 | */ |
| 129 | DownstreamDescriptorMap downstreamDescriptorMap; |
| 130 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 131 | /** Component information of all the discovered MCTP endpoints */ |
| 132 | ComponentInfoMap componentInfoMap; |
| 133 | |
Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame^] | 134 | /** Configuration bindings from the Entity Manager */ |
| 135 | Configurations configurations; |
| 136 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 137 | /** @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 |