blob: bc983afa99d29f78993cb3770560b7d878c15bf1 [file] [log] [blame]
Willy Tude54f482021-01-26 15:59:09 -08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#include <boost/algorithm/string.hpp>
18#include <boost/bimap.hpp>
19#include <boost/container/flat_map.hpp>
20#include <cstdio>
21#include <cstring>
22#include <exception>
23#include <filesystem>
24#include <ipmid/api.hpp>
25#include <ipmid/types.hpp>
26#include <map>
27#include <phosphor-logging/log.hpp>
28#include <sdbusplus/bus/match.hpp>
29#include <string>
30#include <vector>
31
32#pragma once
33
34static constexpr bool debug = false;
35
36struct CmpStrVersion
37{
38 bool operator()(std::string a, std::string b) const
39 {
40 return strverscmp(a.c_str(), b.c_str()) < 0;
41 }
42};
43
44using SensorSubTree = boost::container::flat_map<
45 std::string,
46 boost::container::flat_map<std::string, std::vector<std::string>>,
47 CmpStrVersion>;
48
49using SensorNumMap = boost::bimap<int, std::string>;
50
51static constexpr uint16_t maxSensorsPerLUN = 255;
52static constexpr uint16_t maxIPMISensors = (maxSensorsPerLUN * 3);
53static constexpr uint16_t lun1Sensor0 = 0x100;
54static constexpr uint16_t lun3Sensor0 = 0x300;
55static constexpr uint16_t invalidSensorNumber = 0xFFFF;
56static constexpr uint8_t reservedSensorNumber = 0xFF;
57
58namespace details
59{
Kuiying Wanga8b5b262021-02-06 23:38:22 +080060uint16_t getSensorSubtree(std::shared_ptr<SensorSubTree>& subtree);
Willy Tude54f482021-01-26 15:59:09 -080061
62bool getSensorNumMap(std::shared_ptr<SensorNumMap>& sensorNumMap);
63} // namespace details
64
65bool getSensorSubtree(SensorSubTree& subtree);
66
67struct CmpStr
68{
69 bool operator()(const char* a, const char* b) const
70 {
71 return std::strcmp(a, b) < 0;
72 }
73};
74
75enum class SensorTypeCodes : uint8_t
76{
77 reserved = 0x0,
78 temperature = 0x1,
79 voltage = 0x2,
80 current = 0x3,
81 fan = 0x4,
82 other = 0xB,
83};
84
85const static boost::container::flat_map<const char*, SensorTypeCodes, CmpStr>
86 sensorTypes{{{"temperature", SensorTypeCodes::temperature},
87 {"voltage", SensorTypeCodes::voltage},
88 {"current", SensorTypeCodes::current},
89 {"fan_tach", SensorTypeCodes::fan},
90 {"fan_pwm", SensorTypeCodes::fan},
91 {"power", SensorTypeCodes::other}}};
92
93std::string getSensorTypeStringFromPath(const std::string& path);
94
95uint8_t getSensorTypeFromPath(const std::string& path);
96
97uint16_t getSensorNumberFromPath(const std::string& path);
98
99uint8_t getSensorEventTypeFromPath(const std::string& path);
100
101std::string getPathFromSensorNumber(uint16_t sensorNum);
102
103namespace ipmi
104{
105std::map<std::string, std::vector<std::string>>
106 getObjectInterfaces(const char* path);
107
108std::map<std::string, Value> getEntityManagerProperties(const char* path,
109 const char* interface);
110
111const std::string* getSensorConfigurationInterface(
112 const std::map<std::string, std::vector<std::string>>&
113 sensorInterfacesResponse);
114
115void updateIpmiFromAssociation(const std::string& path,
116 const DbusInterfaceMap& sensorMap,
117 uint8_t& entityId, uint8_t& entityInstance);
118} // namespace ipmi