blob: 88a901b859c42cddca3165ad537279dce0a7d58b [file] [log] [blame]
Willy Tua2056e92021-10-10 13:36:16 -07001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Patrick Venturec87de552020-05-20 20:25:39 -070015#pragma once
16
17#include "handler.hpp"
18
19#include <cstdint>
20#include <map>
21#include <nlohmann/json.hpp>
22#include <string>
23#include <tuple>
24#include <vector>
25
26namespace google
27{
28namespace ipmi
29{
30
William A. Kennington III96ad9062020-11-24 21:47:20 -080031constexpr char defaultConfigFile[] =
32 "/usr/share/ipmi-entity-association/entity_association_map.json";
Patrick Venturec87de552020-05-20 20:25:39 -070033
34class Handler : public HandlerInterface
35{
36 public:
37 explicit Handler(const std::string& entityConfigPath = defaultConfigFile) :
38 _configFile(entityConfigPath){};
39 ~Handler() = default;
40
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070041 std::tuple<std::uint8_t, std::string>
42 getEthDetails(std::string intf) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070043 std::int64_t getRxPackets(const std::string& name) const override;
44 VersionTuple getCpldVersion(unsigned int id) const override;
45 void psuResetDelay(std::uint32_t delay) const override;
Shounak Mitraac4a16f2021-02-02 11:11:44 -080046 void psuResetOnShutdown() const override;
Patrick Venturec87de552020-05-20 20:25:39 -070047 std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
Willy Tu3b1b4272021-03-02 17:58:10 -080048 uint32_t getFlashSize() override;
William A. Kennington III29f35bc2020-11-03 23:30:31 -080049 std::string getMachineName() override;
Patrick Venturec87de552020-05-20 20:25:39 -070050 void buildI2cPcieMapping() override;
51 size_t getI2cPcieMappingSize() const override;
linyuny8cfa4c42021-06-16 13:53:08 -070052 void hostPowerOffDelay(std::uint32_t delay) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070053 std::tuple<std::uint32_t, std::string>
54 getI2cEntry(unsigned int entry) const override;
55
56 private:
57 std::string _configFile;
58
59 bool _entityConfigParsed = false;
60
61 const std::map<uint8_t, std::string> _entityIdToName{
62 {0x03, "cpu"},
63 {0x04, "storage_device"},
64 {0x06, "system_management_module"},
65 {0x07, "system_board"},
66 {0x08, "memory_module"},
67 {0x0B, "add_in_card"},
68 {0x0E, "power_system_board"},
69 {0x10, "system_internal_expansion_board"},
70 {0x11, "other_system_board"},
71 {0x17, "system_chassis"},
72 {0x1D, "fan"},
73 {0x1E, "cooling_unit"},
74 {0x20, "memory_device"}};
75
76 nlohmann::json _entityConfig{};
77
78 std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
79};
80
Patrick Venturea3f9c2d2020-05-29 14:36:25 -070081/**
82 * Given a type, entity instance, and a configuration, return the name.
83 *
84 * @param[in] type - the entity type
85 * @param[in] instance - the entity instance
86 * @param[in] config - the json object holding the entity mapping
87 * @return the name of the entity from the map
88 */
89std::string readNameFromConfig(const std::string& type, uint8_t instance,
90 const nlohmann::json& config);
91
Patrick Venturec87de552020-05-20 20:25:39 -070092} // namespace ipmi
93} // namespace google