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 "sdrutils.hpp"
19
20 #include <ipmid/api.hpp>
21
22 #include <cstdint>
23
24 #pragma pack(push, 1)
25
26 struct SensorThresholdResp
27 {
28 uint8_t readable;
29 uint8_t lowernc;
30 uint8_t lowercritical;
31 uint8_t lowernonrecoverable;
32 uint8_t uppernc;
33 uint8_t uppercritical;
34 uint8_t uppernonrecoverable;
35 };
36
37 #pragma pack(pop)
38
39 enum class IPMIThresholdRespBits
40 {
41 lowerNonCritical,
42 lowerCritical,
43 lowerNonRecoverable,
44 upperNonCritical,
45 upperCritical,
46 upperNonRecoverable
47 };
48
49 enum class IPMISensorReadingByte2 : uint8_t
50 {
51 eventMessagesEnable = (1 << 7),
52 sensorScanningEnable = (1 << 6),
53 readingStateUnavailable = (1 << 5),
54 };
55
56 enum class IPMISensorReadingByte3 : uint8_t
57 {
58 upperNonRecoverable = (1 << 5),
59 upperCritical = (1 << 4),
60 upperNonCritical = (1 << 3),
61 lowerNonRecoverable = (1 << 2),
62 lowerCritical = (1 << 1),
63 lowerNonCritical = (1 << 0),
64 };
65
66 enum class IPMISensorEventEnableByte2 : uint8_t
67 {
68 eventMessagesEnable = (1 << 7),
69 sensorScanningEnable = (1 << 6),
70 };
71
72 enum class IPMISensorEventEnableThresholds : uint8_t
73 {
74 nonRecoverableThreshold = (1 << 6),
75 criticalThreshold = (1 << 5),
76 nonCriticalThreshold = (1 << 4),
77 upperNonRecoverableGoingHigh = (1 << 3),
78 upperNonRecoverableGoingLow = (1 << 2),
79 upperCriticalGoingHigh = (1 << 1),
80 upperCriticalGoingLow = (1 << 0),
81 upperNonCriticalGoingHigh = (1 << 7),
82 upperNonCriticalGoingLow = (1 << 6),
83 lowerNonRecoverableGoingHigh = (1 << 5),
84 lowerNonRecoverableGoingLow = (1 << 4),
85 lowerCriticalGoingHigh = (1 << 3),
86 lowerCriticalGoingLow = (1 << 2),
87 lowerNonCriticalGoingHigh = (1 << 1),
88 lowerNonCriticalGoingLow = (1 << 0),
89 };
90
91 enum class IPMIGetSensorEventEnableThresholds : uint8_t
92 {
93 lowerNonCriticalGoingLow = 0,
94 lowerNonCriticalGoingHigh = 1,
95 lowerCriticalGoingLow = 2,
96 lowerCriticalGoingHigh = 3,
97 lowerNonRecoverableGoingLow = 4,
98 lowerNonRecoverableGoingHigh = 5,
99 upperNonCriticalGoingLow = 6,
100 upperNonCriticalGoingHigh = 7,
101 upperCriticalGoingLow = 8,
102 upperCriticalGoingHigh = 9,
103 upperNonRecoverableGoingLow = 10,
104 upperNonRecoverableGoingHigh = 11,
105 };
106
107 enum class IPMINetfnSensorCmds : ipmi_cmd_t
108 {
109 ipmiCmdGetDeviceSDRInfo = 0x20,
110 ipmiCmdGetDeviceSDR = 0x21,
111 ipmiCmdReserveDeviceSDRRepo = 0x22,
112 ipmiCmdSetSensorThreshold = 0x26,
113 ipmiCmdGetSensorThreshold = 0x27,
114 ipmiCmdGetSensorEventEnable = 0x29,
115 ipmiCmdGetSensorEventStatus = 0x2B,
116 ipmiCmdGetSensorReading = 0x2D,
117 ipmiCmdGetSensorType = 0x2F,
118 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
119 };
120
121 namespace ipmi
122 {
123 extern SensorSubTree sensorTree;
getSensorConnection(ipmi::Context::ptr ctx,uint8_t sensnum,std::string & connection,std::string & path)124 static ipmi_ret_t getSensorConnection(ipmi::Context::ptr ctx, uint8_t sensnum,
125 std::string& connection,
126 std::string& path)
127 {
128 if (!getSensorSubtree(sensorTree) && sensorTree.empty())
129 {
130 return IPMI_CC_RESPONSE_ERROR;
131 }
132
133 if (ctx == nullptr)
134 {
135 return IPMI_CC_RESPONSE_ERROR;
136 }
137
138 path = getPathFromSensorNumber((ctx->lun << 8) | sensnum);
139 if (path.empty())
140 {
141 return IPMI_CC_INVALID_FIELD_REQUEST;
142 }
143
144 for (const auto& sensor : sensorTree)
145 {
146 if (path == sensor.first)
147 {
148 connection = sensor.second.begin()->first;
149 break;
150 }
151 }
152
153 return 0;
154 }
155
156 struct IPMIThresholds
157 {
158 std::optional<uint8_t> warningLow;
159 std::optional<uint8_t> warningHigh;
160 std::optional<uint8_t> criticalLow;
161 std::optional<uint8_t> criticalHigh;
162 };
163
164 } // namespace ipmi
165