| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| Unive Tien | ee2bd8a | 2025-10-30 08:11:06 +0000 | [diff] [blame^] | 3 | #include "aggregate_update_manager.hpp" |
| Andrew Jeffery | 2abbce7 | 2023-10-18 10:17:35 +1030 | [diff] [blame] | 4 | #include "common/instance_id.hpp" |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 5 | #include "common/types.hpp" |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 6 | #include "firmware_inventory_manager.hpp" |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 7 | #include "requester/handler.hpp" |
| 8 | |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 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 |
| Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 36 | * @param[in] instanceIdDb - Managing instance ID for PLDM requests |
| Manojkiran Eda | 2576aec | 2024-06-17 12:05:17 +0530 | [diff] [blame] | 37 | * @param[out] descriptorMap - Populate the firmware identifiers for the |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 38 | * FDs managed by the BMC. |
| Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 39 | * @param[out] downstreamDescriptorMap - Populate the downstream |
| 40 | * identifiers for the FDs managed |
| 41 | * by the BMC. |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 42 | * @param[out] componentInfoMap - Populate the component info for the FDs |
| 43 | * managed by the BMC. |
| 44 | */ |
| 45 | explicit InventoryManager( |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 46 | const pldm::utils::DBusHandler* dbusHandler, |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 47 | pldm::requester::Handler<pldm::requester::Request>& handler, |
| Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 48 | InstanceIdDb& instanceIdDb, DescriptorMap& descriptorMap, |
| Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 49 | DownstreamDescriptorMap& downstreamDescriptorMap, |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 50 | ComponentInfoMap& componentInfoMap, |
| Unive Tien | ee2bd8a | 2025-10-30 08:11:06 +0000 | [diff] [blame^] | 51 | const Configurations& configurations, |
| 52 | AggregateUpdateManager& updateManager) : |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 53 | handler(handler), instanceIdDb(instanceIdDb), |
| Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 54 | descriptorMap(descriptorMap), |
| 55 | downstreamDescriptorMap(downstreamDescriptorMap), |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 56 | componentInfoMap(componentInfoMap), configurations(configurations), |
| Unive Tien | ee2bd8a | 2025-10-30 08:11:06 +0000 | [diff] [blame^] | 57 | firmwareInventoryManager(dbusHandler, configurations, updateManager) |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 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 | * |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 66 | * @param[in] mctpInfos - List of MCTP endpoint information |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 67 | */ |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 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); |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 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 | |
| Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 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 | |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 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: |
| Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 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 | |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 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 | |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 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 | |
| Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 191 | /** @brief Instance ID database for managing instance ID*/ |
| 192 | InstanceIdDb& instanceIdDb; |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 193 | |
| 194 | /** @brief Device identifiers of the managed FDs */ |
| 195 | DescriptorMap& descriptorMap; |
| 196 | |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 197 | /** @brief Firmware Device names of the managed FDs */ |
| 198 | std::map<eid, SoftwareName> firmwareDeviceNameMap; |
| 199 | |
| Unive Tien | 8b169dc | 2024-11-25 09:34:39 +0800 | [diff] [blame] | 200 | /** @brief Downstream Device identifiers of the managed FDs */ |
| 201 | DownstreamDescriptorMap& downstreamDescriptorMap; |
| 202 | |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 203 | /** @brief Component information needed for the update of the managed FDs */ |
| 204 | ComponentInfoMap& componentInfoMap; |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 205 | |
| 206 | /** @brief Configuration bindings from Entity Manager */ |
| 207 | const Configurations& configurations; |
| 208 | |
| 209 | /** @brief Dbus Inventory Item Manager */ |
| 210 | FirmwareInventoryManager firmwareInventoryManager; |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 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 | |
| Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 234 | } // namespace fw_update |
| 235 | |
| 236 | } // namespace pldm |