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 enum class IPMINetfnSensorCmds : ipmi_cmd_t 106 { 107 ipmiCmdGetDeviceSDRInfo = 0x20, 108 ipmiCmdGetDeviceSDR = 0x21, 109 ipmiCmdReserveDeviceSDRRepo = 0x22, 110 ipmiCmdSetSensorThreshold = 0x26, 111 ipmiCmdGetSensorThreshold = 0x27, 112 ipmiCmdGetSensorEventEnable = 0x29, 113 ipmiCmdGetSensorEventStatus = 0x2B, 114 ipmiCmdGetSensorReading = 0x2D, 115 ipmiCmdGetSensorType = 0x2F, 116 ipmiCmdSetSensorReadingAndEventStatus = 0x30, 117 }; 118 119 namespace ipmi 120 { 121 122 uint16_t getNumberOfSensors(); 123 124 SensorSubTree& getSensorTree(); 125 126 ipmi_ret_t getSensorConnection(ipmi::Context::ptr ctx, uint8_t sensnum, 127 std::string& connection, std::string& path, 128 std::vector<std::string>* interfaces = nullptr); 129 130 struct IPMIThresholds 131 { 132 std::optional<uint8_t> warningLow; 133 std::optional<uint8_t> warningHigh; 134 std::optional<uint8_t> criticalLow; 135 std::optional<uint8_t> criticalHigh; 136 }; 137 138 namespace sensor 139 { 140 /** 141 * @brief Retrieve the number of sensors that are not included in the list of 142 * sensors published via D-Bus 143 * 144 * @param[in]: ctx: the pointer to the D-Bus context 145 * @return: The number of additional sensors separate from those published 146 * dynamically on D-Bus 147 */ 148 size_t getOtherSensorsCount(ipmi::Context::ptr ctx); 149 150 /** 151 * @brief Retrieve the record data for the sensors not published via D-Bus 152 * 153 * @param[in]: ctx: the pointer to the D-Bus context 154 * @param[in]: recordID: the integer index for the sensor to retrieve 155 * @param[out]: SDR data for the indexed sensor 156 * @return: 0: success 157 * negative number: error condition 158 */ 159 int getOtherSensorsDataRecord(ipmi::Context::ptr ctx, uint16_t recordID, 160 std::vector<uint8_t>& recordData); 161 } // namespace sensor 162 163 namespace dcmi 164 { 165 166 struct sensorInfo 167 { 168 std::string objectPath; 169 uint8_t type; 170 uint16_t recordId; 171 uint8_t entityId; 172 uint8_t entityInstance; 173 }; 174 175 } // namespace dcmi 176 177 } // namespace ipmi 178