xref: /openbmc/pldm/fw-update/inventory_manager.hpp (revision ee2bd8ad3979dac8c41afa643e0eb24b31e70683)
1 #pragma once
2 
3 #include "aggregate_update_manager.hpp"
4 #include "common/instance_id.hpp"
5 #include "common/types.hpp"
6 #include "firmware_inventory_manager.hpp"
7 #include "requester/handler.hpp"
8 
9 namespace pldm
10 {
11 
12 namespace 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  */
23 class 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
36      *  @param[in] instanceIdDb - Managing instance ID for PLDM requests
37      *  @param[out] descriptorMap - Populate the firmware identifiers for the
38      *                              FDs managed by the BMC.
39      *  @param[out] downstreamDescriptorMap - Populate the downstream
40      *                                        identifiers for the FDs managed
41      *                                        by the BMC.
42      *  @param[out] componentInfoMap - Populate the component info for the FDs
43      *                                 managed by the BMC.
44      */
InventoryManager(const pldm::utils::DBusHandler * dbusHandler,pldm::requester::Handler<pldm::requester::Request> & handler,InstanceIdDb & instanceIdDb,DescriptorMap & descriptorMap,DownstreamDescriptorMap & downstreamDescriptorMap,ComponentInfoMap & componentInfoMap,const Configurations & configurations,AggregateUpdateManager & updateManager)45     explicit InventoryManager(
46         const pldm::utils::DBusHandler* dbusHandler,
47         pldm::requester::Handler<pldm::requester::Request>& handler,
48         InstanceIdDb& instanceIdDb, DescriptorMap& descriptorMap,
49         DownstreamDescriptorMap& downstreamDescriptorMap,
50         ComponentInfoMap& componentInfoMap,
51         const Configurations& configurations,
52         AggregateUpdateManager& updateManager) :
53         handler(handler), instanceIdDb(instanceIdDb),
54         descriptorMap(descriptorMap),
55         downstreamDescriptorMap(downstreamDescriptorMap),
56         componentInfoMap(componentInfoMap), configurations(configurations),
57         firmwareInventoryManager(dbusHandler, configurations, updateManager)
58     {}
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      *
66      *  @param[in] mctpInfos - List of MCTP endpoint information
67      */
68     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);
78 
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 
92     /** @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 
119     /** @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:
132     /**
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 
171     /**
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 
182     /** @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 
191     /** @brief Instance ID database for managing instance ID*/
192     InstanceIdDb& instanceIdDb;
193 
194     /** @brief Device identifiers of the managed FDs */
195     DescriptorMap& descriptorMap;
196 
197     /** @brief Firmware Device names of the managed FDs */
198     std::map<eid, SoftwareName> firmwareDeviceNameMap;
199 
200     /** @brief Downstream Device identifiers of the managed FDs */
201     DownstreamDescriptorMap& downstreamDescriptorMap;
202 
203     /** @brief Component information needed for the update of the managed FDs */
204     ComponentInfoMap& componentInfoMap;
205 
206     /** @brief Configuration bindings from Entity Manager */
207     const Configurations& configurations;
208 
209     /** @brief Dbus Inventory Item Manager */
210     FirmwareInventoryManager firmwareInventoryManager;
211 };
212 
213 /**
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  */
221 std::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  */
231 std::optional<SoftwareName> obtainDeviceNameFromDescriptors(
232     const Descriptors& descriptors);
233 
234 } // namespace fw_update
235 
236 } // namespace pldm
237