blob: 673b5138e0c2ffa95b0f783fcff8d612408781d1 [file] [log] [blame]
Tom Joseph75356c12021-06-20 03:52:40 -07001#pragma once
2
Andrew Jeffery2abbce72023-10-18 10:17:35 +10303#include "common/instance_id.hpp"
Tom Joseph75356c12021-06-20 03:52:40 -07004#include "common/types.hpp"
Unive Tien7ad45b42025-08-18 06:04:53 +00005#include "firmware_inventory_manager.hpp"
Tom Joseph75356c12021-06-20 03:52:40 -07006#include "requester/handler.hpp"
7
Tom Joseph75356c12021-06-20 03:52:40 -07008namespace pldm
9{
10
11namespace fw_update
12{
13
14/** @class InventoryManager
15 *
16 * InventoryManager class manages the software inventory of firmware devices
17 * managed by the BMC. It discovers the firmware identifiers and the component
18 * details of the FD. Firmware identifiers, component details and update
19 * capabilities of FD are populated by the InventoryManager and is used for the
20 * firmware update of the FDs.
21 */
22class InventoryManager
23{
24 public:
25 InventoryManager() = delete;
26 InventoryManager(const InventoryManager&) = delete;
27 InventoryManager(InventoryManager&&) = delete;
28 InventoryManager& operator=(const InventoryManager&) = delete;
29 InventoryManager& operator=(InventoryManager&&) = delete;
30 ~InventoryManager() = default;
31
32 /** @brief Constructor
33 *
34 * @param[in] handler - PLDM request handler
Andrew Jefferya330b2f2023-05-04 14:55:37 +093035 * @param[in] instanceIdDb - Managing instance ID for PLDM requests
Manojkiran Eda2576aec2024-06-17 12:05:17 +053036 * @param[out] descriptorMap - Populate the firmware identifiers for the
Tom Joseph75356c12021-06-20 03:52:40 -070037 * FDs managed by the BMC.
Unive Tien8b169dc2024-11-25 09:34:39 +080038 * @param[out] downstreamDescriptorMap - Populate the downstream
39 * identifiers for the FDs managed
40 * by the BMC.
Tom Joseph75356c12021-06-20 03:52:40 -070041 * @param[out] componentInfoMap - Populate the component info for the FDs
42 * managed by the BMC.
43 */
44 explicit InventoryManager(
Unive Tien7ad45b42025-08-18 06:04:53 +000045 const pldm::utils::DBusHandler* dbusHandler,
Tom Joseph75356c12021-06-20 03:52:40 -070046 pldm::requester::Handler<pldm::requester::Request>& handler,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093047 InstanceIdDb& instanceIdDb, DescriptorMap& descriptorMap,
Unive Tien8b169dc2024-11-25 09:34:39 +080048 DownstreamDescriptorMap& downstreamDescriptorMap,
Unive Tien7ad45b42025-08-18 06:04:53 +000049 ComponentInfoMap& componentInfoMap,
50 const Configurations& configurations) :
Patrick Williams16c2a0a2024-08-16 15:20:59 -040051 handler(handler), instanceIdDb(instanceIdDb),
Unive Tien8b169dc2024-11-25 09:34:39 +080052 descriptorMap(descriptorMap),
53 downstreamDescriptorMap(downstreamDescriptorMap),
Unive Tien7ad45b42025-08-18 06:04:53 +000054 componentInfoMap(componentInfoMap), configurations(configurations),
55 firmwareInventoryManager(dbusHandler, configurations)
Tom Joseph75356c12021-06-20 03:52:40 -070056 {}
57
58 /** @brief Discover the firmware identifiers and component details of FDs
59 *
60 * Inventory commands QueryDeviceIdentifiers and GetFirmwareParmeters
61 * commands are sent to every FD and the response is used to populate
62 * the firmware identifiers and component details of the FDs.
63 *
Unive Tien7ad45b42025-08-18 06:04:53 +000064 * @param[in] mctpInfos - List of MCTP endpoint information
Tom Joseph75356c12021-06-20 03:52:40 -070065 */
Unive Tien7ad45b42025-08-18 06:04:53 +000066 void discoverFDs(const MctpInfos& mctpInfos);
67
68 /** @brief Remove the firmware identifiers and component details of FDs
69 *
70 * This function removes the firmware identifiers, component details and
71 * downstream device identifiers of the FDs managed by the BMC.
72 *
73 * @param[in] mctpInfos - List of MCTP endpoint information
74 */
75 void removeFDs(const MctpInfos& mctpInfos);
Tom Joseph75356c12021-06-20 03:52:40 -070076
77 /** @brief Handler for QueryDeviceIdentifiers command response
78 *
79 * The response of the QueryDeviceIdentifiers is processed and firmware
80 * identifiers of the FD is updated. GetFirmwareParameters command request
81 * is sent to the FD.
82 *
83 * @param[in] eid - Remote MCTP endpoint
84 * @param[in] response - PLDM response message
85 * @param[in] respMsgLen - Response message length
86 */
87 void queryDeviceIdentifiers(mctp_eid_t eid, const pldm_msg* response,
88 size_t respMsgLen);
89
Unive Tien8b169dc2024-11-25 09:34:39 +080090 /** @brief Handler for QueryDownstreamDevices command response
91 *
92 * @param[in] eid - Remote MCTP endpoint
93 * @param[in] response - PLDM response message
94 * @param[in] respMsgLen - Response message length
95 */
96 void queryDownstreamDevices(mctp_eid_t eid, const pldm_msg* response,
97 size_t respMsgLen);
98
99 /** @brief Handler for QueryDownstreamIdentifiers command response
100 *
101 * @param[in] eid - Remote MCTP endpoint
102 * @param[in] response - PLDM response message
103 * @param[in] respMsgLen - Response message length
104 */
105 void queryDownstreamIdentifiers(mctp_eid_t eid, const pldm_msg* response,
106 size_t respMsgLen);
107
108 /** @brief Handler for GetDownstreamFirmwareParameters command response
109 *
110 * @param[in] eid - Remote MCTP endpoint
111 * @param[in] response - PLDM response message
112 * @param[in] respMsgLen - Response message length
113 */
114 void getDownstreamFirmwareParameters(
115 mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen);
116
Tom Joseph75356c12021-06-20 03:52:40 -0700117 /** @brief Handler for GetFirmwareParameters command response
118 *
119 * Handling the response of GetFirmwareParameters command and create
120 * software version D-Bus objects.
121 *
122 * @param[in] eid - Remote MCTP endpoint
123 * @param[in] response - PLDM response message
124 * @param[in] respMsgLen - Response message length
125 */
126 void getFirmwareParameters(mctp_eid_t eid, const pldm_msg* response,
127 size_t respMsgLen);
128
129 private:
Unive Tien8b169dc2024-11-25 09:34:39 +0800130 /**
131 * @brief Sends QueryDeviceIdentifiers request
132 *
133 * @param[in] eid - Remote MCTP endpoint
134 */
135 void sendQueryDeviceIdentifiersRequest(mctp_eid_t eid);
136
137 /**
138 * @brief Sends QueryDownstreamDevices request
139 *
140 * @param[in] eid - Remote MCTP endpoint
141 */
142 void sendQueryDownstreamDevicesRequest(mctp_eid_t eid);
143
144 /**
145 * @brief Sends QueryDownstreamIdentifiers request
146 *
147 * The request format is defined at Table 16 – QueryDownstreamIdentifiers
148 * command format in DSP0267_1.1.0
149 *
150 * @param[in] eid - Remote MCTP endpoint
151 * @param[in] dataTransferHandle - Data transfer handle
152 * @param[in] transferOperationFlag - Transfer operation flag
153 */
154 void sendQueryDownstreamIdentifiersRequest(
155 mctp_eid_t eid, uint32_t dataTransferHandle,
156 enum transfer_op_flag transferOperationFlag);
157
158 /**
159 * @brief Sends QueryDownstreamFirmwareParameters request
160 *
161 * @param[in] eid - Remote MCTP endpoint
162 * @param[in] dataTransferHandle - Data transfer handle
163 * @param[in] transferOperationFlag - Transfer operation flag
164 */
165 void sendGetDownstreamFirmwareParametersRequest(
166 mctp_eid_t eid, uint32_t dataTransferHandle,
167 const enum transfer_op_flag transferOperationFlag);
168
Unive Tien7ad45b42025-08-18 06:04:53 +0000169 /**
170 * @brief obtain Firmware Device Name from either configurations or
171 * descriptors, if none of them is available, a default name is
172 * generated.
173 *
174 * @param[in] eid - Remote MCTP endpoint
175 * @param[in] descriptors - Descriptors of the firmware device
176 */
177 void obtainFirmwareDeviceName(pldm::eid eid,
178 const Descriptors& descriptors);
179
Tom Joseph75356c12021-06-20 03:52:40 -0700180 /** @brief Send GetFirmwareParameters command request
181 *
182 * @param[in] eid - Remote MCTP endpoint
183 */
184 void sendGetFirmwareParametersRequest(mctp_eid_t eid);
185
186 /** @brief PLDM request handler */
187 pldm::requester::Handler<pldm::requester::Request>& handler;
188
Andrew Jefferya330b2f2023-05-04 14:55:37 +0930189 /** @brief Instance ID database for managing instance ID*/
190 InstanceIdDb& instanceIdDb;
Tom Joseph75356c12021-06-20 03:52:40 -0700191
192 /** @brief Device identifiers of the managed FDs */
193 DescriptorMap& descriptorMap;
194
Unive Tien7ad45b42025-08-18 06:04:53 +0000195 /** @brief Firmware Device names of the managed FDs */
196 std::map<eid, SoftwareName> firmwareDeviceNameMap;
197
Unive Tien8b169dc2024-11-25 09:34:39 +0800198 /** @brief Downstream Device identifiers of the managed FDs */
199 DownstreamDescriptorMap& downstreamDescriptorMap;
200
Tom Joseph75356c12021-06-20 03:52:40 -0700201 /** @brief Component information needed for the update of the managed FDs */
202 ComponentInfoMap& componentInfoMap;
Unive Tien7ad45b42025-08-18 06:04:53 +0000203
204 /** @brief Configuration bindings from Entity Manager */
205 const Configurations& configurations;
206
207 /** @brief Dbus Inventory Item Manager */
208 FirmwareInventoryManager firmwareInventoryManager;
Tom Joseph75356c12021-06-20 03:52:40 -0700209};
210
Unive Tien7ad45b42025-08-18 06:04:53 +0000211/**
212 * @brief Obtain the device name from the configurations
213 *
214 * @param[in] configurations - Configurations from Entity Manager
215 * @param[in] eid - Remote MCTP endpoint
216 *
217 * @return SoftwareName - The Device name, std::nullopt if not found
218 */
219std::optional<SoftwareName> obtainDeviceNameFromConfigurations(
220 const Configurations& configurations, pldm::eid eid);
221
222/**
223 * @brief Obtain the device name from the descriptors
224 *
225 * @param[in] descriptors - Descriptors of the device
226 *
227 * @return SoftwareName - The Device name, std::nullopt if not found
228 */
229std::optional<SoftwareName> obtainDeviceNameFromDescriptors(
230 const Descriptors& descriptors);
231
Tom Joseph75356c12021-06-20 03:52:40 -0700232} // namespace fw_update
233
234} // namespace pldm