xref: /openbmc/pldm/fw-update/manager.hpp (revision 75e00422df3f9a4c9341ca8085706b6eaa6605b7)
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,
44                      downstreamDescriptorMap, componentInfoMap),
45         updateManager(event, handler, instanceIdDb, descriptorMap,
46                       componentInfoMap)
47     {}
48 
49     /** @brief Helper function to invoke registered handlers for
50      *         the added MCTP endpoints
51      *
52      *  @param[in] mctpInfos - information of discovered MCTP endpoints
53      */
handleMctpEndpoints(const MctpInfos & mctpInfos)54     void handleMctpEndpoints(const MctpInfos& mctpInfos)
55     {
56         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 
62         inventoryMgr.discoverFDs(eids);
63     }
64 
65     /** @brief Helper function to invoke registered handlers for
66      *         the removed MCTP endpoints
67      *
68      *  @param[in] mctpInfos - information of removed MCTP endpoints
69      */
handleRemovedMctpEndpoints(const MctpInfos &)70     void handleRemovedMctpEndpoints(const MctpInfos&)
71     {
72         return;
73     }
74 
75     /** @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      */
updateMctpEndpointAvailability(const MctpInfo &,Availability)81     void updateMctpEndpointAvailability(const MctpInfo&, Availability)
82     {
83         return;
84     }
85 
86     /** @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      */
handleRequest(mctp_eid_t eid,Command command,const pldm_msg * request,size_t reqMsgLen)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 
105     /** Downstream descriptor information of all the discovered MCTP endpoints
106      */
107     DownstreamDescriptorMap downstreamDescriptorMap;
108 
109     /** 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
122