1 /*
2 // Copyright (c) 2017 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 #pragma once
18 #include <dbus-sdr/sdrutils.hpp>
19 
20 #include <cstdint>
21 
22 #pragma pack(push, 1)
23 
24 struct SensorThresholdResp
25 {
26     uint8_t readable;
27     uint8_t lowernc;
28     uint8_t lowercritical;
29     uint8_t lowernonrecoverable;
30     uint8_t uppernc;
31     uint8_t uppercritical;
32     uint8_t uppernonrecoverable;
33 };
34 
35 #pragma pack(pop)
36 
37 enum class IPMIThresholdRespBits
38 {
39     lowerNonCritical,
40     lowerCritical,
41     lowerNonRecoverable,
42     upperNonCritical,
43     upperCritical,
44     upperNonRecoverable
45 };
46 
47 enum class IPMISensorReadingByte2 : uint8_t
48 {
49     eventMessagesEnable = (1 << 7),
50     sensorScanningEnable = (1 << 6),
51     readingStateUnavailable = (1 << 5),
52 };
53 
54 enum class IPMISensorReadingByte3 : uint8_t
55 {
56     upperNonRecoverable = (1 << 5),
57     upperCritical = (1 << 4),
58     upperNonCritical = (1 << 3),
59     lowerNonRecoverable = (1 << 2),
60     lowerCritical = (1 << 1),
61     lowerNonCritical = (1 << 0),
62 };
63 
64 enum class IPMISensorEventEnableByte2 : uint8_t
65 {
66     eventMessagesEnable = (1 << 7),
67     sensorScanningEnable = (1 << 6),
68 };
69 
70 enum class IPMISensorEventEnableThresholds : uint8_t
71 {
72     nonRecoverableThreshold = (1 << 6),
73     criticalThreshold = (1 << 5),
74     nonCriticalThreshold = (1 << 4),
75     upperNonRecoverableGoingHigh = (1 << 3),
76     upperNonRecoverableGoingLow = (1 << 2),
77     upperCriticalGoingHigh = (1 << 1),
78     upperCriticalGoingLow = (1 << 0),
79     upperNonCriticalGoingHigh = (1 << 7),
80     upperNonCriticalGoingLow = (1 << 6),
81     lowerNonRecoverableGoingHigh = (1 << 5),
82     lowerNonRecoverableGoingLow = (1 << 4),
83     lowerCriticalGoingHigh = (1 << 3),
84     lowerCriticalGoingLow = (1 << 2),
85     lowerNonCriticalGoingHigh = (1 << 1),
86     lowerNonCriticalGoingLow = (1 << 0),
87 };
88 
89 enum class IPMIGetSensorEventEnableThresholds : uint8_t
90 {
91     lowerNonCriticalGoingLow = 0,
92     lowerNonCriticalGoingHigh = 1,
93     lowerCriticalGoingLow = 2,
94     lowerCriticalGoingHigh = 3,
95     lowerNonRecoverableGoingLow = 4,
96     lowerNonRecoverableGoingHigh = 5,
97     upperNonCriticalGoingLow = 6,
98     upperNonCriticalGoingHigh = 7,
99     upperCriticalGoingLow = 8,
100     upperCriticalGoingHigh = 9,
101     upperNonRecoverableGoingLow = 10,
102     upperNonRecoverableGoingHigh = 11,
103 };
104 
105 namespace ipmi
106 {
107 
108 uint16_t getNumberOfSensors();
109 
110 SensorSubTree& getSensorTree();
111 
112 ipmi_ret_t getSensorConnection(ipmi::Context::ptr ctx, uint8_t sensnum,
113                                std::string& connection, std::string& path,
114                                std::vector<std::string>* interfaces = nullptr);
115 
116 struct IPMIThresholds
117 {
118     std::optional<uint8_t> warningLow;
119     std::optional<uint8_t> warningHigh;
120     std::optional<uint8_t> criticalLow;
121     std::optional<uint8_t> criticalHigh;
122 };
123 
124 namespace sensor
125 {
126 /**
127  * @brief Retrieve the number of sensors that are not included in the list of
128  * sensors published via D-Bus
129  *
130  * @param[in]: ctx: the pointer to the D-Bus context
131  * @return: The number of additional sensors separate from those published
132  * dynamically on D-Bus
133  */
134 size_t getOtherSensorsCount(ipmi::Context::ptr ctx);
135 
136 /**
137  * @brief Retrieve the record data for the sensors not published via D-Bus
138  *
139  * @param[in]: ctx: the pointer to the D-Bus context
140  * @param[in]: recordID: the integer index for the sensor to retrieve
141  * @param[out]: SDR data for the indexed sensor
142  * @return: 0: success
143  *          negative number: error condition
144  */
145 int getOtherSensorsDataRecord(ipmi::Context::ptr ctx, uint16_t recordID,
146                               std::vector<uint8_t>& recordData);
147 } // namespace sensor
148 
149 namespace dcmi
150 {
151 
152 struct sensorInfo
153 {
154     std::string objectPath;
155     uint8_t type;
156     uint16_t recordId;
157     uint8_t entityId;
158     uint8_t entityInstance;
159 };
160 
161 } // namespace dcmi
162 
163 } // namespace ipmi
164