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