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 | |
| 36 | /** @brief Constructor |
| 37 | * |
| 38 | * @param[in] handler - PLDM request handler |
| 39 | */ |
| 40 | explicit Manager(Event& event, |
| 41 | requester::Handler<requester::Request>& handler, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 42 | pldm::InstanceIdDb& instanceIdDb) : |
| 43 | inventoryMgr(handler, instanceIdDb, descriptorMap, componentInfoMap), |
| 44 | updateManager(event, handler, instanceIdDb, descriptorMap, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 45 | componentInfoMap) |
| 46 | {} |
| 47 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 48 | /** @brief Helper function to invoke registered handlers for |
| 49 | * the added MCTP endpoints |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 50 | * |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 51 | * @param[in] mctpInfos - information of discovered MCTP endpoints |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 52 | */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 53 | void handleMctpEndpoints(const MctpInfos& mctpInfos) |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 54 | { |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 55 | 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 Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 61 | inventoryMgr.discoverFDs(eids); |
| 62 | } |
| 63 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 64 | /** @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 Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 74 | /** @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 |