1c87de558SPatrick Venture #pragma once 2c87de558SPatrick Venture 3c87de558SPatrick Venture #include "handler.hpp" 4c87de558SPatrick Venture 5c87de558SPatrick Venture #include <cstdint> 6c87de558SPatrick Venture #include <map> 7c87de558SPatrick Venture #include <nlohmann/json.hpp> 8c87de558SPatrick Venture #include <string> 9c87de558SPatrick Venture #include <tuple> 10c87de558SPatrick Venture #include <vector> 11c87de558SPatrick Venture 12c87de558SPatrick Venture namespace google 13c87de558SPatrick Venture { 14c87de558SPatrick Venture namespace ipmi 15c87de558SPatrick Venture { 16c87de558SPatrick Venture 17*96ad9069SWilliam A. Kennington III constexpr char defaultConfigFile[] = 18*96ad9069SWilliam A. Kennington III "/usr/share/ipmi-entity-association/entity_association_map.json"; 19c87de558SPatrick Venture 20c87de558SPatrick Venture class Handler : public HandlerInterface 21c87de558SPatrick Venture { 22c87de558SPatrick Venture public: 23c87de558SPatrick Venture explicit Handler(const std::string& entityConfigPath = defaultConfigFile) : 24c87de558SPatrick Venture _configFile(entityConfigPath){}; 25c87de558SPatrick Venture ~Handler() = default; 26c87de558SPatrick Venture 27c87de558SPatrick Venture std::tuple<std::uint8_t, std::string> getEthDetails() const override; 28c87de558SPatrick Venture std::int64_t getRxPackets(const std::string& name) const override; 29c87de558SPatrick Venture VersionTuple getCpldVersion(unsigned int id) const override; 30c87de558SPatrick Venture void psuResetDelay(std::uint32_t delay) const override; 31c87de558SPatrick Venture std::string getEntityName(std::uint8_t id, std::uint8_t instance) override; 3229f35bceSWilliam A. Kennington III std::string getMachineName() override; 33c87de558SPatrick Venture void buildI2cPcieMapping() override; 34c87de558SPatrick Venture size_t getI2cPcieMappingSize() const override; 35c87de558SPatrick Venture std::tuple<std::uint32_t, std::string> 36c87de558SPatrick Venture getI2cEntry(unsigned int entry) const override; 37c87de558SPatrick Venture 38c87de558SPatrick Venture private: 39c87de558SPatrick Venture std::string _configFile; 40c87de558SPatrick Venture 41c87de558SPatrick Venture bool _entityConfigParsed = false; 42c87de558SPatrick Venture 43c87de558SPatrick Venture const std::map<uint8_t, std::string> _entityIdToName{ 44c87de558SPatrick Venture {0x03, "cpu"}, 45c87de558SPatrick Venture {0x04, "storage_device"}, 46c87de558SPatrick Venture {0x06, "system_management_module"}, 47c87de558SPatrick Venture {0x07, "system_board"}, 48c87de558SPatrick Venture {0x08, "memory_module"}, 49c87de558SPatrick Venture {0x0B, "add_in_card"}, 50c87de558SPatrick Venture {0x0E, "power_system_board"}, 51c87de558SPatrick Venture {0x10, "system_internal_expansion_board"}, 52c87de558SPatrick Venture {0x11, "other_system_board"}, 53c87de558SPatrick Venture {0x17, "system_chassis"}, 54c87de558SPatrick Venture {0x1D, "fan"}, 55c87de558SPatrick Venture {0x1E, "cooling_unit"}, 56c87de558SPatrick Venture {0x20, "memory_device"}}; 57c87de558SPatrick Venture 58c87de558SPatrick Venture nlohmann::json _entityConfig{}; 59c87de558SPatrick Venture 60c87de558SPatrick Venture std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map; 61c87de558SPatrick Venture }; 62c87de558SPatrick Venture 63a3f9c2d3SPatrick Venture /** 64a3f9c2d3SPatrick Venture * Given a type, entity instance, and a configuration, return the name. 65a3f9c2d3SPatrick Venture * 66a3f9c2d3SPatrick Venture * @param[in] type - the entity type 67a3f9c2d3SPatrick Venture * @param[in] instance - the entity instance 68a3f9c2d3SPatrick Venture * @param[in] config - the json object holding the entity mapping 69a3f9c2d3SPatrick Venture * @return the name of the entity from the map 70a3f9c2d3SPatrick Venture */ 71a3f9c2d3SPatrick Venture std::string readNameFromConfig(const std::string& type, uint8_t instance, 72a3f9c2d3SPatrick Venture const nlohmann::json& config); 73a3f9c2d3SPatrick Venture 74c87de558SPatrick Venture } // namespace ipmi 75c87de558SPatrick Venture } // namespace google 76