xref: /openbmc/pldm/fw-update/manager.hpp (revision 21f128d8)
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 "update_manager.hpp"
10 
11 #include <unordered_map>
12 #include <vector>
13 
14 namespace pldm
15 {
16 
17 namespace fw_update
18 {
19 
20 /** @class Manager
21  *
22  * This class handles all the aspects of the PLDM FW update specification for
23  * the MCTP devices
24  */
25 class Manager
26 {
27   public:
28     Manager() = delete;
29     Manager(const Manager&) = delete;
30     Manager(Manager&&) = delete;
31     Manager& operator=(const Manager&) = delete;
32     Manager& operator=(Manager&&) = delete;
33     ~Manager() = default;
34 
35     /** @brief Constructor
36      *
37      *  @param[in] handler - PLDM request handler
38      */
39     explicit Manager(Event& event,
40                      requester::Handler<requester::Request>& handler,
41                      pldm::InstanceIdDb& instanceIdDb) :
42         inventoryMgr(handler, instanceIdDb, descriptorMap, componentInfoMap),
43         updateManager(event, handler, instanceIdDb, descriptorMap,
44                       componentInfoMap)
45     {}
46 
47     /** @brief Discover MCTP endpoints that support the PLDM firmware update
48      *         specification
49      *
50      *  @param[in] eids - Array of MCTP endpoints
51      *
52      *  @return return PLDM_SUCCESS on success and PLDM_ERROR otherwise
53      */
54     void handleMCTPEndpoints(const std::vector<mctp_eid_t>& eids)
55     {
56         inventoryMgr.discoverFDs(eids);
57     }
58 
59     /** @brief Handle PLDM request for the commands in the FW update
60      *         specification
61      *
62      *  @param[in] eid - Remote MCTP Endpoint ID
63      *  @param[in] command - PLDM command code
64      *  @param[in] request - PLDM request message
65      *  @param[in] requestLen - PLDM request message length
66      *  @return PLDM response message
67      */
68     Response handleRequest(mctp_eid_t eid, Command command,
69                            const pldm_msg* request, size_t reqMsgLen)
70     {
71         return updateManager.handleRequest(eid, command, request, reqMsgLen);
72     }
73 
74   private:
75     /** Descriptor information of all the discovered MCTP endpoints */
76     DescriptorMap descriptorMap;
77 
78     /** Component information of all the discovered MCTP endpoints */
79     ComponentInfoMap componentInfoMap;
80 
81     /** @brief PLDM firmware inventory manager */
82     InventoryManager inventoryMgr;
83 
84     /** @brief PLDM firmware update manager */
85     UpdateManager updateManager;
86 };
87 
88 } // namespace fw_update
89 
90 } // namespace pldm
91