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