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