blob: 46a32853fad64ada3ed44116668380b897cf1e26 [file] [log] [blame]
Tom Josephfb3bc062021-08-17 07:48:11 -07001#pragma once
2
Tom Josephfb3bc062021-08-17 07:48:11 -07003#include "activation.hpp"
4#include "common/types.hpp"
5#include "device_updater.hpp"
6#include "inventory_manager.hpp"
Andrew Jefferya330b2f2023-05-04 14:55:37 +09307#include "pldmd/instance_id.hpp"
Tom Josephfb3bc062021-08-17 07:48:11 -07008#include "requester/handler.hpp"
9#include "update_manager.hpp"
10
George Liuc453e162022-12-21 17:16:23 +080011#include <libpldm/pldm.h>
12
Tom Josephfb3bc062021-08-17 07:48:11 -070013#include <unordered_map>
14#include <vector>
15
16namespace pldm
17{
18
19namespace fw_update
20{
21
Tom Josephfb3bc062021-08-17 07:48:11 -070022/** @class Manager
23 *
24 * This class handles all the aspects of the PLDM FW update specification for
25 * the MCTP devices
26 */
27class Manager
28{
Tom Josephfb3bc062021-08-17 07:48:11 -070029 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,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093043 pldm::InstanceIdDb& instanceIdDb) :
44 inventoryMgr(handler, instanceIdDb, descriptorMap, componentInfoMap),
45 updateManager(event, handler, instanceIdDb, descriptorMap,
Tom Josephfb3bc062021-08-17 07:48:11 -070046 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