xref: /openbmc/pldm/fw-update/manager.hpp (revision 44524a5f)
1 #pragma once
2 
3 #include "activation.hpp"
4 #include "common/instance_id.hpp"
5 #include "common/types.hpp"
6 #include "device_updater.hpp"
7 #include "inventory_manager.hpp"
8 #include "requester/handler.hpp"
9 #include "requester/mctp_endpoint_discovery.hpp"
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 
21 /** @class Manager
22  *
23  * This class handles all the aspects of the PLDM FW update specification for
24  * the MCTP devices
25  */
26 class Manager : public pldm::MctpDiscoveryHandlerIntf
27 {
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      */
Manager(Event & event,requester::Handler<requester::Request> & handler,pldm::InstanceIdDb & instanceIdDb)40     explicit Manager(Event& event,
41                      requester::Handler<requester::Request>& handler,
42                      pldm::InstanceIdDb& instanceIdDb) :
43         inventoryMgr(handler, instanceIdDb, descriptorMap, componentInfoMap),
44         updateManager(event, handler, instanceIdDb, descriptorMap,
45                       componentInfoMap)
46     {}
47 
48     /** @brief Helper function to invoke registered handlers for
49      *         the added MCTP endpoints
50      *
51      *  @param[in] mctpInfos - information of discovered MCTP endpoints
52      */
handleMctpEndpoints(const MctpInfos & mctpInfos)53     void handleMctpEndpoints(const MctpInfos& mctpInfos)
54     {
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 
61         inventoryMgr.discoverFDs(eids);
62     }
63 
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      */
handleRemovedMctpEndpoints(const MctpInfos &)69     void handleRemovedMctpEndpoints(const MctpInfos&)
70     {
71         return;
72     }
73 
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      */
handleRequest(mctp_eid_t eid,Command command,const pldm_msg * request,size_t reqMsgLen)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
106