blob: e100a5273569049c603760a3e073ac6181703e20 [file] [log] [blame]
Tom Joseph75356c12021-06-20 03:52:40 -07001#pragma once
2
Unive Tienee2bd8a2025-10-30 08:11:06 +00003#include "aggregate_update_manager.hpp"
Andrew Jeffery2abbce72023-10-18 10:17:35 +10304#include "common/instance_id.hpp"
Tom Joseph75356c12021-06-20 03:52:40 -07005#include "common/types.hpp"
Unive Tien7ad45b42025-08-18 06:04:53 +00006#include "firmware_inventory_manager.hpp"
Tom Joseph75356c12021-06-20 03:52:40 -07007#include "requester/handler.hpp"
8
Tom Joseph75356c12021-06-20 03:52:40 -07009namespace pldm
10{
11
12namespace fw_update
13{
14
15/** @class InventoryManager
16 *
17 * InventoryManager class manages the software inventory of firmware devices
18 * managed by the BMC. It discovers the firmware identifiers and the component
19 * details of the FD. Firmware identifiers, component details and update
20 * capabilities of FD are populated by the InventoryManager and is used for the
21 * firmware update of the FDs.
22 */
23class InventoryManager
24{
25 public:
26 InventoryManager() = delete;
27 InventoryManager(const InventoryManager&) = delete;
28 InventoryManager(InventoryManager&&) = delete;
29 InventoryManager& operator=(const InventoryManager&) = delete;
30 InventoryManager& operator=(InventoryManager&&) = delete;
31 ~InventoryManager() = default;
32
33 /** @brief Constructor
34 *
35 * @param[in] handler - PLDM request handler
Andrew Jefferya330b2f2023-05-04 14:55:37 +093036 * @param[in] instanceIdDb - Managing instance ID for PLDM requests
Manojkiran Eda2576aec2024-06-17 12:05:17 +053037 * @param[out] descriptorMap - Populate the firmware identifiers for the
Tom Joseph75356c12021-06-20 03:52:40 -070038 * FDs managed by the BMC.
Unive Tien8b169dc2024-11-25 09:34:39 +080039 * @param[out] downstreamDescriptorMap - Populate the downstream
40 * identifiers for the FDs managed
41 * by the BMC.
Tom Joseph75356c12021-06-20 03:52:40 -070042 * @param[out] componentInfoMap - Populate the component info for the FDs
43 * managed by the BMC.
44 */
45 explicit InventoryManager(
Unive Tien7ad45b42025-08-18 06:04:53 +000046 const pldm::utils::DBusHandler* dbusHandler,
Tom Joseph75356c12021-06-20 03:52:40 -070047 pldm::requester::Handler<pldm::requester::Request>& handler,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093048 InstanceIdDb& instanceIdDb, DescriptorMap& descriptorMap,
Unive Tien8b169dc2024-11-25 09:34:39 +080049 DownstreamDescriptorMap& downstreamDescriptorMap,
Unive Tien7ad45b42025-08-18 06:04:53 +000050 ComponentInfoMap& componentInfoMap,
Unive Tienee2bd8a2025-10-30 08:11:06 +000051 const Configurations& configurations,
52 AggregateUpdateManager& updateManager) :
Patrick Williams16c2a0a2024-08-16 15:20:59 -040053 handler(handler), instanceIdDb(instanceIdDb),
Unive Tien8b169dc2024-11-25 09:34:39 +080054 descriptorMap(descriptorMap),
55 downstreamDescriptorMap(downstreamDescriptorMap),
Unive Tien7ad45b42025-08-18 06:04:53 +000056 componentInfoMap(componentInfoMap), configurations(configurations),
Unive Tienee2bd8a2025-10-30 08:11:06 +000057 firmwareInventoryManager(dbusHandler, configurations, updateManager)
Tom Joseph75356c12021-06-20 03:52:40 -070058 {}
59
60 /** @brief Discover the firmware identifiers and component details of FDs
61 *
62 * Inventory commands QueryDeviceIdentifiers and GetFirmwareParmeters
63 * commands are sent to every FD and the response is used to populate
64 * the firmware identifiers and component details of the FDs.
65 *
Unive Tien7ad45b42025-08-18 06:04:53 +000066 * @param[in] mctpInfos - List of MCTP endpoint information
Tom Joseph75356c12021-06-20 03:52:40 -070067 */
Unive Tien7ad45b42025-08-18 06:04:53 +000068 void discoverFDs(const MctpInfos& mctpInfos);
69
70 /** @brief Remove the firmware identifiers and component details of FDs
71 *
72 * This function removes the firmware identifiers, component details and
73 * downstream device identifiers of the FDs managed by the BMC.
74 *
75 * @param[in] mctpInfos - List of MCTP endpoint information
76 */
77 void removeFDs(const MctpInfos& mctpInfos);
Tom Joseph75356c12021-06-20 03:52:40 -070078
79 /** @brief Handler for QueryDeviceIdentifiers command response
80 *
81 * The response of the QueryDeviceIdentifiers is processed and firmware
82 * identifiers of the FD is updated. GetFirmwareParameters command request
83 * is sent to the FD.
84 *
85 * @param[in] eid - Remote MCTP endpoint
86 * @param[in] response - PLDM response message
87 * @param[in] respMsgLen - Response message length
88 */
89 void queryDeviceIdentifiers(mctp_eid_t eid, const pldm_msg* response,
90 size_t respMsgLen);
91
Unive Tien8b169dc2024-11-25 09:34:39 +080092 /** @brief Handler for QueryDownstreamDevices command response
93 *
94 * @param[in] eid - Remote MCTP endpoint
95 * @param[in] response - PLDM response message
96 * @param[in] respMsgLen - Response message length
97 */
98 void queryDownstreamDevices(mctp_eid_t eid, const pldm_msg* response,
99 size_t respMsgLen);
100
101 /** @brief Handler for QueryDownstreamIdentifiers command response
102 *
103 * @param[in] eid - Remote MCTP endpoint
104 * @param[in] response - PLDM response message
105 * @param[in] respMsgLen - Response message length
106 */
107 void queryDownstreamIdentifiers(mctp_eid_t eid, const pldm_msg* response,
108 size_t respMsgLen);
109
110 /** @brief Handler for GetDownstreamFirmwareParameters command response
111 *
112 * @param[in] eid - Remote MCTP endpoint
113 * @param[in] response - PLDM response message
114 * @param[in] respMsgLen - Response message length
115 */
116 void getDownstreamFirmwareParameters(
117 mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen);
118
Tom Joseph75356c12021-06-20 03:52:40 -0700119 /** @brief Handler for GetFirmwareParameters command response
120 *
121 * Handling the response of GetFirmwareParameters command and create
122 * software version D-Bus objects.
123 *
124 * @param[in] eid - Remote MCTP endpoint
125 * @param[in] response - PLDM response message
126 * @param[in] respMsgLen - Response message length
127 */
128 void getFirmwareParameters(mctp_eid_t eid, const pldm_msg* response,
129 size_t respMsgLen);
130
131 private:
Unive Tien8b169dc2024-11-25 09:34:39 +0800132 /**
133 * @brief Sends QueryDeviceIdentifiers request
134 *
135 * @param[in] eid - Remote MCTP endpoint
136 */
137 void sendQueryDeviceIdentifiersRequest(mctp_eid_t eid);
138
139 /**
140 * @brief Sends QueryDownstreamDevices request
141 *
142 * @param[in] eid - Remote MCTP endpoint
143 */
144 void sendQueryDownstreamDevicesRequest(mctp_eid_t eid);
145
146 /**
147 * @brief Sends QueryDownstreamIdentifiers request
148 *
149 * The request format is defined at Table 16 – QueryDownstreamIdentifiers
150 * command format in DSP0267_1.1.0
151 *
152 * @param[in] eid - Remote MCTP endpoint
153 * @param[in] dataTransferHandle - Data transfer handle
154 * @param[in] transferOperationFlag - Transfer operation flag
155 */
156 void sendQueryDownstreamIdentifiersRequest(
157 mctp_eid_t eid, uint32_t dataTransferHandle,
158 enum transfer_op_flag transferOperationFlag);
159
160 /**
161 * @brief Sends QueryDownstreamFirmwareParameters request
162 *
163 * @param[in] eid - Remote MCTP endpoint
164 * @param[in] dataTransferHandle - Data transfer handle
165 * @param[in] transferOperationFlag - Transfer operation flag
166 */
167 void sendGetDownstreamFirmwareParametersRequest(
168 mctp_eid_t eid, uint32_t dataTransferHandle,
169 const enum transfer_op_flag transferOperationFlag);
170
Unive Tien7ad45b42025-08-18 06:04:53 +0000171 /**
172 * @brief obtain Firmware Device Name from either configurations or
173 * descriptors, if none of them is available, a default name is
174 * generated.
175 *
176 * @param[in] eid - Remote MCTP endpoint
177 * @param[in] descriptors - Descriptors of the firmware device
178 */
179 void obtainFirmwareDeviceName(pldm::eid eid,
180 const Descriptors& descriptors);
181
Tom Joseph75356c12021-06-20 03:52:40 -0700182 /** @brief Send GetFirmwareParameters command request
183 *
184 * @param[in] eid - Remote MCTP endpoint
185 */
186 void sendGetFirmwareParametersRequest(mctp_eid_t eid);
187
188 /** @brief PLDM request handler */
189 pldm::requester::Handler<pldm::requester::Request>& handler;
190
Andrew Jefferya330b2f2023-05-04 14:55:37 +0930191 /** @brief Instance ID database for managing instance ID*/
192 InstanceIdDb& instanceIdDb;
Tom Joseph75356c12021-06-20 03:52:40 -0700193
194 /** @brief Device identifiers of the managed FDs */
195 DescriptorMap& descriptorMap;
196
Unive Tien7ad45b42025-08-18 06:04:53 +0000197 /** @brief Firmware Device names of the managed FDs */
198 std::map<eid, SoftwareName> firmwareDeviceNameMap;
199
Unive Tien8b169dc2024-11-25 09:34:39 +0800200 /** @brief Downstream Device identifiers of the managed FDs */
201 DownstreamDescriptorMap& downstreamDescriptorMap;
202
Tom Joseph75356c12021-06-20 03:52:40 -0700203 /** @brief Component information needed for the update of the managed FDs */
204 ComponentInfoMap& componentInfoMap;
Unive Tien7ad45b42025-08-18 06:04:53 +0000205
206 /** @brief Configuration bindings from Entity Manager */
207 const Configurations& configurations;
208
209 /** @brief Dbus Inventory Item Manager */
210 FirmwareInventoryManager firmwareInventoryManager;
Tom Joseph75356c12021-06-20 03:52:40 -0700211};
212
Unive Tien7ad45b42025-08-18 06:04:53 +0000213/**
214 * @brief Obtain the device name from the configurations
215 *
216 * @param[in] configurations - Configurations from Entity Manager
217 * @param[in] eid - Remote MCTP endpoint
218 *
219 * @return SoftwareName - The Device name, std::nullopt if not found
220 */
221std::optional<SoftwareName> obtainDeviceNameFromConfigurations(
222 const Configurations& configurations, pldm::eid eid);
223
224/**
225 * @brief Obtain the device name from the descriptors
226 *
227 * @param[in] descriptors - Descriptors of the device
228 *
229 * @return SoftwareName - The Device name, std::nullopt if not found
230 */
231std::optional<SoftwareName> obtainDeviceNameFromDescriptors(
232 const Descriptors& descriptors);
233
Tom Joseph75356c12021-06-20 03:52:40 -0700234} // namespace fw_update
235
236} // namespace pldm