| #pragma once |
| |
| #include <stdint.h> |
| |
| #include <sdbusplus/message/types.hpp> |
| #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
| #include <xyz/openbmc_project/Inventory/Item/NetworkAdapter/server.hpp> |
| #include <xyz/openbmc_project/Inventory/Item/Port/server.hpp> |
| |
| #include <sdbusplus/timer.hpp> |
| |
| #include <bitset> |
| #include <format> |
| #include <map> |
| #include <set> |
| #include <string> |
| #include <unordered_map> |
| #include <variant> |
| #include <vector> |
| |
| |
| namespace pldm |
| { |
| |
| using eid = uint8_t; |
| using Request = std::vector<uint8_t>; |
| using Response = std::vector<uint8_t>; |
| using Command = uint8_t; |
| |
| using NetworkAdapterInterface = sdbusplus::server::object_t< |
| sdbusplus::xyz::openbmc_project::Inventory::Item::server::NetworkAdapter>; |
| |
| using PortInterface = sdbusplus::server::object_t< |
| sdbusplus::xyz::openbmc_project::Inventory::Item::server::Port>; |
| |
| using AssociationDefinitionsInterface = sdbusplus::server::object_t< |
| sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
| |
| struct PLDMEntity |
| { |
| uint16_t entityType; |
| uint16_t instNum; |
| uint16_t containerId; |
| std::string toString() const |
| { |
| return std::format("(Type:{}, Inst:{}, Container:{})", entityType, |
| instNum, containerId); |
| } |
| bool operator==(const PLDMEntity& other) const |
| { |
| return (entityType == other.entityType && instNum == other.instNum && |
| containerId == other.containerId); |
| } |
| }; |
| |
| struct PLDMEntityHasher |
| { |
| std::size_t operator()(const PLDMEntity& k) const |
| { |
| std::size_t res = 17; |
| res = res * 31 + std::hash<uint16_t>()(k.entityType); |
| res = res * 31 + std::hash<uint16_t>()(k.instNum); |
| res = res * 31 + std::hash<uint16_t>()(k.containerId); |
| return res; |
| } |
| }; |
| |
| class InventoryBase |
| { |
| protected: |
| PLDMEntity entity; |
| std::string name; |
| std::string inventoryPath; |
| std::string parentInventoryPath; |
| |
| public: |
| InventoryBase(const PLDMEntity& entity, const std::string& name, |
| const std::string& inventoryPath, |
| const std::string& parentInventoryPath) : |
| entity(entity), name(name), inventoryPath(inventoryPath), |
| parentInventoryPath(parentInventoryPath) |
| {} |
| |
| std::string getInventoryPath() const |
| { |
| return inventoryPath; |
| } |
| |
| // Make InventoryBase class polymoprphic by adding a virtual |
| // destructor |
| virtual ~InventoryBase() {} |
| |
| virtual void setHealthState([[maybe_unused]] const std::string& health) {} |
| inline static const std::string HealthStateOK = "OK"; |
| inline static const std::string HealthStateWarning = "Warning"; |
| inline static const std::string HealthStateCritical = "Critical"; |
| inline static const std::string Unknown = "Unknown"; |
| }; |
| |
| class NicInventory : public InventoryBase |
| { |
| public: |
| NicInventory(sdbusplus::bus::bus& bus, const PLDMEntity& entity, |
| const std::string& name, const std::string& inventoryPath, |
| const std::string& parentInventoryPath) : |
| InventoryBase(entity, name, inventoryPath, parentInventoryPath) |
| { |
| nicInterface = std::make_shared<NetworkAdapterInterface>( |
| bus, inventoryPath.c_str()); |
| nicInterface->statusHealth(Unknown); |
| |
| association = std::make_shared<AssociationDefinitionsInterface>( |
| bus, inventoryPath.c_str()); |
| association->associations( |
| {{"chassis", "network_adapter", parentInventoryPath}}); |
| } |
| |
| void setHealthState(const std::string& health) |
| { |
| if (nicInterface) |
| { |
| nicInterface->statusHealth(health); |
| } |
| } |
| |
| private: |
| std::shared_ptr<NetworkAdapterInterface> nicInterface; |
| std::shared_ptr<AssociationDefinitionsInterface> association; |
| }; |
| |
| class PortInventory : public InventoryBase |
| { |
| public: |
| PortInventory(sdbusplus::bus::bus& bus, const PLDMEntity& entity, |
| const std::string& name, const std::string& inventoryPath, |
| const std::string& parentInventoryPath) : |
| InventoryBase(entity, name, inventoryPath, parentInventoryPath) |
| { |
| portInterface = std::make_shared<PortInterface>(bus, |
| inventoryPath.c_str()); |
| // Set default values |
| portInterface->linkState(LinkStateDisabled); |
| portInterface->linkStatus(Unknown); |
| portInterface->currentSpeedGbps(0); |
| |
| association = std::make_shared<AssociationDefinitionsInterface>( |
| bus, inventoryPath.c_str()); |
| association->associations( |
| {{"adapter", "all_ports", parentInventoryPath}}); |
| } |
| |
| void setSpeedGbps(double gbps) |
| { |
| if (portInterface) |
| { |
| portInterface->currentSpeedGbps(gbps); |
| } |
| } |
| |
| void setLinkState(const std::string& linkState) |
| { |
| if (portInterface) |
| { |
| portInterface->linkState(linkState); |
| } |
| } |
| |
| void setLinkStatus(const std::string& linkStatus) |
| { |
| if (portInterface) |
| { |
| portInterface->linkStatus(linkStatus); |
| } |
| } |
| |
| public: |
| inline static const std::string LinkStateDisabled = "Disabled"; |
| inline static const std::string LinkStateEnabled = "Enabled"; |
| inline static const std::string LinkStatusLinkDown = "LinkDown"; |
| inline static const std::string LinkStatusLinkUp = "LinkUp"; |
| inline static const std::string LinkStatusNoLink = "NoLink"; |
| |
| private: |
| std::shared_ptr<PortInterface> portInterface; |
| std::shared_ptr<AssociationDefinitionsInterface> association; |
| }; |
| |
| namespace dbus |
| { |
| |
| using ObjectPath = std::string; |
| using Service = std::string; |
| using Interface = std::string; |
| using Interfaces = std::vector<std::string>; |
| using Property = std::string; |
| using PropertyType = std::string; |
| using Value = |
| std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, |
| uint64_t, double, std::string, std::vector<uint8_t>>; |
| |
| using PropertyMap = std::map<Property, Value>; |
| using InterfaceMap = std::map<Interface, PropertyMap>; |
| using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>; |
| |
| } // namespace dbus |
| |
| namespace fw_update |
| { |
| |
| // Descriptor definition |
| using DescriptorType = uint16_t; |
| using DescriptorData = std::vector<uint8_t>; |
| using VendorDefinedDescriptorTitle = std::string; |
| using VendorDefinedDescriptorData = std::vector<uint8_t>; |
| using VendorDefinedDescriptorInfo = |
| std::tuple<VendorDefinedDescriptorTitle, VendorDefinedDescriptorData>; |
| using Descriptors = |
| std::map<DescriptorType, |
| std::variant<DescriptorData, VendorDefinedDescriptorInfo>>; |
| |
| using DescriptorMap = std::unordered_map<eid, Descriptors>; |
| |
| // Component information |
| using CompClassification = uint16_t; |
| using CompIdentifier = uint16_t; |
| using CompKey = std::pair<CompClassification, CompIdentifier>; |
| using CompClassificationIndex = uint8_t; |
| using ComponentInfo = std::map<CompKey, CompClassificationIndex>; |
| using ComponentInfoMap = std::unordered_map<eid, ComponentInfo>; |
| |
| // PackageHeaderInformation |
| using PackageHeaderSize = size_t; |
| using PackageVersion = std::string; |
| using ComponentBitmapBitLength = uint16_t; |
| using PackageHeaderChecksum = uint32_t; |
| |
| // FirmwareDeviceIDRecords |
| using DeviceIDRecordCount = uint8_t; |
| using DeviceUpdateOptionFlags = std::bitset<32>; |
| using ApplicableComponents = std::vector<size_t>; |
| using ComponentImageSetVersion = std::string; |
| using FirmwareDevicePackageData = std::vector<uint8_t>; |
| using FirmwareDeviceIDRecord = |
| std::tuple<DeviceUpdateOptionFlags, ApplicableComponents, |
| ComponentImageSetVersion, Descriptors, |
| FirmwareDevicePackageData>; |
| using FirmwareDeviceIDRecords = std::vector<FirmwareDeviceIDRecord>; |
| |
| // ComponentImageInformation |
| using ComponentImageCount = uint16_t; |
| using CompComparisonStamp = uint32_t; |
| using CompOptions = std::bitset<16>; |
| using ReqCompActivationMethod = std::bitset<16>; |
| using CompLocationOffset = uint32_t; |
| using CompSize = uint32_t; |
| using CompVersion = std::string; |
| using ComponentImageInfo = |
| std::tuple<CompClassification, CompIdentifier, CompComparisonStamp, |
| CompOptions, ReqCompActivationMethod, CompLocationOffset, |
| CompSize, CompVersion>; |
| using ComponentImageInfos = std::vector<ComponentImageInfo>; |
| |
| enum class ComponentImageInfoPos : size_t |
| { |
| CompClassificationPos = 0, |
| CompIdentifierPos = 1, |
| CompComparisonStampPos = 2, |
| CompOptionsPos = 3, |
| ReqCompActivationMethodPos = 4, |
| CompLocationOffsetPos = 5, |
| CompSizePos = 6, |
| CompVersionPos = 7, |
| }; |
| |
| } // namespace fw_update |
| |
| namespace pdr |
| { |
| |
| using EID = uint8_t; |
| using TerminusHandle = uint16_t; |
| using TerminusID = uint8_t; |
| using SensorID = uint16_t; |
| using EntityType = uint16_t; |
| using EntityInstance = uint16_t; |
| using ContainerID = uint16_t; |
| using StateSetId = uint16_t; |
| using CompositeCount = uint8_t; |
| using SensorOffset = uint8_t; |
| using EventState = uint8_t; |
| using TerminusValidity = uint8_t; |
| |
| //!< Subset of the State Set that is supported by a effecter/sensor |
| using PossibleStates = std::set<uint8_t>; |
| //!< Subset of the State Set that is supported by each effecter/sensor in a |
| //!< composite efffecter/sensor |
| using CompositeSensorStates = std::vector<PossibleStates>; |
| using EntityInfo = std::tuple<ContainerID, EntityType, EntityInstance>; |
| using SensorInfo = std::tuple<EntityInfo, CompositeSensorStates>; |
| |
| } // namespace pdr |
| |
| } // namespace pldm |