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