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