blob: 4bd2e03d45e53e3c89b48730b54c58730a86c6f7 [file] [log] [blame]
Patrick Venturec87de552020-05-20 20:25:39 -07001#pragma once
2
3#include "handler.hpp"
4
5#include <cstdint>
6#include <map>
7#include <nlohmann/json.hpp>
8#include <string>
9#include <tuple>
10#include <vector>
11
12namespace google
13{
14namespace ipmi
15{
16
William A. Kennington III96ad9062020-11-24 21:47:20 -080017constexpr char defaultConfigFile[] =
18 "/usr/share/ipmi-entity-association/entity_association_map.json";
Patrick Venturec87de552020-05-20 20:25:39 -070019
20class Handler : public HandlerInterface
21{
22 public:
23 explicit Handler(const std::string& entityConfigPath = defaultConfigFile) :
24 _configFile(entityConfigPath){};
25 ~Handler() = default;
26
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070027 std::tuple<std::uint8_t, std::string>
28 getEthDetails(std::string intf) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070029 std::int64_t getRxPackets(const std::string& name) const override;
30 VersionTuple getCpldVersion(unsigned int id) const override;
31 void psuResetDelay(std::uint32_t delay) const override;
Shounak Mitraac4a16f2021-02-02 11:11:44 -080032 void psuResetOnShutdown() const override;
Patrick Venturec87de552020-05-20 20:25:39 -070033 std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
Willy Tu3b1b4272021-03-02 17:58:10 -080034 uint32_t getFlashSize() override;
William A. Kennington III29f35bc2020-11-03 23:30:31 -080035 std::string getMachineName() override;
Patrick Venturec87de552020-05-20 20:25:39 -070036 void buildI2cPcieMapping() override;
37 size_t getI2cPcieMappingSize() const override;
linyuny8cfa4c42021-06-16 13:53:08 -070038 void hostPowerOffDelay(std::uint32_t delay) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070039 std::tuple<std::uint32_t, std::string>
40 getI2cEntry(unsigned int entry) const override;
41
42 private:
43 std::string _configFile;
44
45 bool _entityConfigParsed = false;
46
47 const std::map<uint8_t, std::string> _entityIdToName{
48 {0x03, "cpu"},
49 {0x04, "storage_device"},
50 {0x06, "system_management_module"},
51 {0x07, "system_board"},
52 {0x08, "memory_module"},
53 {0x0B, "add_in_card"},
54 {0x0E, "power_system_board"},
55 {0x10, "system_internal_expansion_board"},
56 {0x11, "other_system_board"},
57 {0x17, "system_chassis"},
58 {0x1D, "fan"},
59 {0x1E, "cooling_unit"},
60 {0x20, "memory_device"}};
61
62 nlohmann::json _entityConfig{};
63
64 std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
65};
66
Patrick Venturea3f9c2d2020-05-29 14:36:25 -070067/**
68 * Given a type, entity instance, and a configuration, return the name.
69 *
70 * @param[in] type - the entity type
71 * @param[in] instance - the entity instance
72 * @param[in] config - the json object holding the entity mapping
73 * @return the name of the entity from the map
74 */
75std::string readNameFromConfig(const std::string& type, uint8_t instance,
76 const nlohmann::json& config);
77
Patrick Venturec87de552020-05-20 20:25:39 -070078} // namespace ipmi
79} // namespace google