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