Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #pragma once |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 2 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 5 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 6 | #include <ipmid/types.hpp> |
| 7 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 8 | #include <exception> |
| 9 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 10 | /** |
| 11 | * @enum device_type |
| 12 | * IPMI FRU device types |
| 13 | */ |
| 14 | enum device_type |
| 15 | { |
| 16 | IPMI_PHYSICAL_FRU = 0x00, |
| 17 | IPMI_LOGICAL_FRU = 0x80, |
| 18 | }; |
| 19 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 20 | // Discrete sensor types. |
| 21 | enum ipmi_sensor_types |
| 22 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 23 | IPMI_SENSOR_TEMP = 0x01, |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 24 | IPMI_SENSOR_VOLTAGE = 0x02, |
| 25 | IPMI_SENSOR_CURRENT = 0x03, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 26 | IPMI_SENSOR_FAN = 0x04, |
| 27 | IPMI_SENSOR_TPM = 0xCC, |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Brandon Kim | 9cf8562 | 2019-06-19 12:05:08 -0700 | [diff] [blame] | 30 | /** @brief Custom exception for reading sensors that are not funcitonal. |
| 31 | */ |
| 32 | struct SensorFunctionalError : public std::exception |
| 33 | { |
| 34 | const char* what() const noexcept |
| 35 | { |
| 36 | return "Sensor not functional"; |
| 37 | } |
| 38 | }; |
| 39 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 40 | #define MAX_DBUS_PATH 128 |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 41 | struct dbus_interface_t |
| 42 | { |
| 43 | uint8_t sensornumber; |
| 44 | uint8_t sensortype; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 45 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 46 | char bus[MAX_DBUS_PATH]; |
| 47 | char path[MAX_DBUS_PATH]; |
| 48 | char interface[MAX_DBUS_PATH]; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 49 | }; |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 50 | |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 51 | struct PlatformEventRequest |
| 52 | { |
| 53 | uint8_t eventMessageRevision; |
| 54 | uint8_t sensorType; |
| 55 | uint8_t sensorNumber; |
| 56 | uint8_t eventDirectionType; |
| 57 | uint8_t data[3]; |
| 58 | }; |
| 59 | |
George Liu | 6b47d5a | 2025-08-18 10:40:17 +0800 | [diff] [blame^] | 60 | static constexpr const char* ipmiSELObject = "xyz.openbmc_project.Logging.IPMI"; |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 61 | static constexpr const char* ipmiSELPath = "/xyz/openbmc_project/Logging/IPMI"; |
| 62 | static constexpr const char* ipmiSELAddInterface = |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 63 | "xyz.openbmc_project.Logging.IPMI"; |
Konstantin Aladyshev | b5160f5 | 2023-04-19 14:45:06 +0300 | [diff] [blame] | 64 | static const std::string ipmiSELAddMessage = "IPMI generated SEL Entry"; |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 65 | |
| 66 | static constexpr int selSystemEventSizeWith3Bytes = 8; |
| 67 | static constexpr int selSystemEventSizeWith2Bytes = 7; |
| 68 | static constexpr int selSystemEventSizeWith1Bytes = 6; |
| 69 | static constexpr int selIPMBEventSize = 7; |
| 70 | static constexpr uint8_t directionMask = 0x80; |
| 71 | static constexpr uint8_t byte3EnableMask = 0x30; |
| 72 | static constexpr uint8_t byte2EnableMask = 0xC0; |
| 73 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 74 | int set_sensor_dbus_state_s(uint8_t, const char*, const char*); |
| 75 | int set_sensor_dbus_state_y(uint8_t, const char*, const uint8_t); |
| 76 | int find_openbmc_path(uint8_t, dbus_interface_t*); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 77 | |
George Liu | c7a4da5 | 2025-08-19 16:20:31 +0800 | [diff] [blame] | 78 | ipmi::RspType<uint16_t, std::vector<uint8_t>> ipmiSensorGetSdr( |
| 79 | uint16_t, uint16_t, uint8_t, uint8_t); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 80 | |
jayaprakash Mutyala | d957823 | 2019-05-13 20:22:50 +0000 | [diff] [blame] | 81 | ipmi::RspType<uint16_t> ipmiSensorReserveSdr(); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 82 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 83 | static const uint16_t FRU_RECORD_ID_START = 256; |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 84 | static const uint16_t ENTITY_RECORD_ID_START = 512; |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 85 | static const uint8_t SDR_VERSION = 0x51; |
| 86 | static const uint16_t END_OF_RECORD = 0xFFFF; |
| 87 | static const uint8_t LENGTH_MASK = 0x1F; |
| 88 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 89 | /** |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 90 | * Get SDR |
| 91 | */ |
| 92 | namespace get_sdr |
| 93 | { |
| 94 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 95 | // Record header |
| 96 | struct SensorDataRecordHeader |
| 97 | { |
George Liu | c7a4da5 | 2025-08-19 16:20:31 +0800 | [diff] [blame] | 98 | uint16_t recordId; |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 99 | uint8_t sdrVersion; |
| 100 | uint8_t recordType; |
| 101 | uint8_t recordLength; // Length not counting the header |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 102 | } __attribute__((packed)); |
| 103 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 104 | enum SensorDataRecordType |
| 105 | { |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 106 | SENSOR_DATA_FULL_RECORD = 0x1, |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 107 | SENSOR_DATA_COMPACT_RECORD = 0x2, |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 108 | SENSOR_DATA_EVENT_RECORD = 0x3, |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 109 | SENSOR_DATA_ENTITY_RECORD = 0x8, |
Harvey Wu | a347627 | 2023-03-22 10:09:38 +0800 | [diff] [blame] | 110 | SENSOR_DATA_FRU_RECORD = 0x11, |
| 111 | SENSOR_DATA_MGMT_CTRL_LOCATOR = 0x12, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | // Record key |
| 115 | struct SensorDataRecordKey |
| 116 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 117 | uint8_t ownerId; |
| 118 | uint8_t ownerLun; |
| 119 | uint8_t sensorNumber; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 120 | } __attribute__((packed)); |
| 121 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 122 | /** @struct SensorDataFruRecordKey |
| 123 | * |
| 124 | * FRU Device Locator Record(key) - SDR Type 11 |
| 125 | */ |
| 126 | struct SensorDataFruRecordKey |
| 127 | { |
| 128 | uint8_t deviceAddress; |
| 129 | uint8_t fruID; |
| 130 | uint8_t accessLun; |
| 131 | uint8_t channelNumber; |
| 132 | } __attribute__((packed)); |
| 133 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 134 | /** @struct SensorDataEntityRecordKey |
| 135 | * |
| 136 | * Entity Association Record(key) - SDR Type 8 |
| 137 | */ |
| 138 | struct SensorDataEntityRecordKey |
| 139 | { |
| 140 | uint8_t containerEntityId; |
| 141 | uint8_t containerEntityInstance; |
| 142 | uint8_t flags; |
| 143 | uint8_t entityId1; |
| 144 | uint8_t entityInstance1; |
| 145 | } __attribute__((packed)); |
| 146 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 147 | namespace key |
| 148 | { |
| 149 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 150 | static constexpr uint8_t listOrRangeBit = 7; |
| 151 | static constexpr uint8_t linkedBit = 6; |
| 152 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 153 | inline void setOwnerIdIpmb(SensorDataRecordKey& key) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 154 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 155 | key.ownerId &= ~0x01; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 158 | inline void setOwnerIdSystemSw(SensorDataRecordKey& key) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 159 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 160 | key.ownerId |= 0x01; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 163 | inline void setOwnerIdBmc(SensorDataRecordKey& key) |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 164 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 165 | key.ownerId |= 0x20; |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 166 | }; |
| 167 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 168 | inline void setOwnerIdAddress(uint8_t addr, SensorDataRecordKey& key) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 169 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 170 | key.ownerId &= 0x01; |
| 171 | key.ownerId |= addr << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 174 | inline void setOwnerLun(uint8_t lun, SensorDataRecordKey& key) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 175 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 176 | key.ownerLun &= ~0x03; |
| 177 | key.ownerLun |= (lun & 0x03); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 180 | inline void setOwnerLunChannel(uint8_t channel, SensorDataRecordKey& key) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 181 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 182 | key.ownerLun &= 0x0f; |
| 183 | key.ownerLun |= ((channel & 0xf) << 4); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 186 | inline void setFlags(bool isList, bool isLinked, SensorDataEntityRecordKey& key) |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 187 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 188 | key.flags = 0x00; |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 189 | if (!isList) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 190 | { |
| 191 | key.flags |= 1 << listOrRangeBit; |
| 192 | } |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 193 | |
| 194 | if (isLinked) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 195 | { |
| 196 | key.flags |= 1 << linkedBit; |
| 197 | } |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 198 | }; |
| 199 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 200 | } // namespace key |
| 201 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 202 | /** @struct GetSensorThresholdsResponse |
| 203 | * |
| 204 | * Response structure for Get Sensor Thresholds command |
| 205 | */ |
| 206 | struct GetSensorThresholdsResponse |
| 207 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 208 | uint8_t validMask; //!< valid mask |
| 209 | uint8_t lowerNonCritical; //!< lower non-critical threshold |
| 210 | uint8_t lowerCritical; //!< lower critical threshold |
| 211 | uint8_t lowerNonRecoverable; //!< lower non-recoverable threshold |
| 212 | uint8_t upperNonCritical; //!< upper non-critical threshold |
| 213 | uint8_t upperCritical; //!< upper critical threshold |
| 214 | uint8_t upperNonRecoverable; //!< upper non-recoverable threshold |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 215 | } __attribute__((packed)); |
| 216 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 217 | // Body - full record |
| 218 | #define FULL_RECORD_ID_STR_MAX_LENGTH 16 |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 219 | |
| 220 | static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16; |
| 221 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 222 | struct SensorDataFullRecordBody |
| 223 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 224 | uint8_t entityId; |
| 225 | uint8_t entityInstance; |
| 226 | uint8_t sensorInitialization; |
| 227 | uint8_t sensorCapabilities; // no macro support |
| 228 | uint8_t sensorType; |
| 229 | uint8_t eventReadingType; |
| 230 | uint8_t supportedAssertions[2]; // no macro support |
| 231 | uint8_t supportedDeassertions[2]; // no macro support |
| 232 | uint8_t discreteReadingSettingMask[2]; // no macro support |
| 233 | uint8_t sensorUnits1; |
| 234 | uint8_t sensorUnits2Base; |
| 235 | uint8_t sensorUnits3Modifier; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 236 | uint8_t linearization; |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 237 | uint8_t mLsb; |
| 238 | uint8_t mMsbAndTolerance; |
| 239 | uint8_t bLsb; |
| 240 | uint8_t bMsbAndAccuracyLsb; |
| 241 | uint8_t accuracyAndSensorDirection; |
| 242 | uint8_t rbExponents; |
| 243 | uint8_t analogCharacteristicFlags; // no macro support |
| 244 | uint8_t nominalReading; |
| 245 | uint8_t normalMax; |
| 246 | uint8_t normalMin; |
| 247 | uint8_t sensorMax; |
| 248 | uint8_t sensorMin; |
| 249 | uint8_t upperNonrecoverableThreshold; |
| 250 | uint8_t upperCriticalThreshold; |
| 251 | uint8_t upperNoncriticalThreshold; |
| 252 | uint8_t lowerNonrecoverableThreshold; |
| 253 | uint8_t lowerCriticalThreshold; |
| 254 | uint8_t lowerNoncriticalThreshold; |
| 255 | uint8_t positiveThresholdHysteresis; |
| 256 | uint8_t negativeThresholdHysteresis; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 257 | uint16_t reserved; |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 258 | uint8_t oemReserved; |
| 259 | uint8_t idStringInfo; |
| 260 | char idString[FULL_RECORD_ID_STR_MAX_LENGTH]; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 261 | } __attribute__((packed)); |
| 262 | |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 263 | /** @struct SensorDataCompactRecord |
| 264 | * |
| 265 | * Compact Sensor Record(body) - SDR Type 2 |
| 266 | */ |
| 267 | struct SensorDataCompactRecordBody |
| 268 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 269 | uint8_t entityId; |
| 270 | uint8_t entityInstance; |
| 271 | uint8_t sensorInitialization; |
| 272 | uint8_t sensorCapabilities; // no macro support |
| 273 | uint8_t sensorType; |
| 274 | uint8_t eventReadingType; |
| 275 | uint8_t supportedAssertions[2]; // no macro support |
| 276 | uint8_t supportedDeassertions[2]; // no macro support |
| 277 | uint8_t discreteReadingSettingMask[2]; // no macro support |
| 278 | uint8_t sensorUnits1; |
| 279 | uint8_t sensorUnits2Base; |
| 280 | uint8_t sensorUnits3Modifier; |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 281 | uint8_t record_sharing[2]; |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 282 | uint8_t positiveThresholdHysteresis; |
| 283 | uint8_t negativeThresholdHysteresis; |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 284 | uint8_t reserved[3]; |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 285 | uint8_t oemReserved; |
| 286 | uint8_t idStringInfo; |
| 287 | char idString[FULL_RECORD_ID_STR_MAX_LENGTH]; |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 288 | } __attribute__((packed)); |
| 289 | |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 290 | /** @struct SensorDataEventRecord |
| 291 | * |
| 292 | * Event Only Sensor Record(body) - SDR Type 3 |
| 293 | */ |
| 294 | struct SensorDataEventRecordBody |
| 295 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 296 | uint8_t entityId; |
| 297 | uint8_t entityInstance; |
| 298 | uint8_t sensorType; |
| 299 | uint8_t eventReadingType; |
| 300 | uint8_t sensorRecordSharing1; |
| 301 | uint8_t sensorRecordSharing2; |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 302 | uint8_t reserved; |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 303 | uint8_t oemReserved; |
| 304 | uint8_t idStringInfo; |
| 305 | char idString[FULL_RECORD_ID_STR_MAX_LENGTH]; |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 306 | } __attribute__((packed)); |
| 307 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 308 | /** @struct SensorDataFruRecordBody |
| 309 | * |
| 310 | * FRU Device Locator Record(body) - SDR Type 11 |
| 311 | */ |
| 312 | struct SensorDataFruRecordBody |
| 313 | { |
| 314 | uint8_t reserved; |
| 315 | uint8_t deviceType; |
| 316 | uint8_t deviceTypeModifier; |
| 317 | uint8_t entityID; |
| 318 | uint8_t entityInstance; |
| 319 | uint8_t oem; |
| 320 | uint8_t deviceIDLen; |
| 321 | char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH]; |
| 322 | } __attribute__((packed)); |
| 323 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 324 | /** @struct SensorDataEntityRecordBody |
| 325 | * |
| 326 | * Entity Association Record(body) - SDR Type 8 |
| 327 | */ |
| 328 | struct SensorDataEntityRecordBody |
| 329 | { |
| 330 | uint8_t entityId2; |
| 331 | uint8_t entityInstance2; |
| 332 | uint8_t entityId3; |
| 333 | uint8_t entityInstance3; |
| 334 | uint8_t entityId4; |
| 335 | uint8_t entityInstance4; |
| 336 | } __attribute__((packed)); |
| 337 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 338 | namespace body |
| 339 | { |
| 340 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 341 | inline void setEntityInstanceNumber(uint8_t n, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 342 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 343 | body.entityInstance &= 1 << 7; |
| 344 | body.entityInstance |= (n & ~(1 << 7)); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 345 | }; |
| 346 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 347 | inline void setEntityPhysicalEntity(SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 348 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 349 | body.entityInstance &= ~(1 << 7); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 350 | }; |
| 351 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 352 | inline void setEntityLogicalContainer(SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 353 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 354 | body.entityInstance |= 1 << 7; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 355 | }; |
| 356 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 357 | inline void sensorScanningState(bool enabled, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 358 | { |
| 359 | if (enabled) |
| 360 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 361 | body.sensorInitialization |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 365 | body.sensorInitialization &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 366 | }; |
| 367 | }; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 368 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 369 | inline void eventGenerationState(bool enabled, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 370 | { |
| 371 | if (enabled) |
| 372 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 373 | body.sensorInitialization |= 1 << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 374 | } |
| 375 | else |
| 376 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 377 | body.sensorInitialization &= ~(1 << 1); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 378 | } |
| 379 | }; |
| 380 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 381 | inline void initTypesState(bool enabled, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 382 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 383 | if (enabled) |
| 384 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 385 | body.sensorInitialization |= 1 << 2; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 386 | } |
| 387 | else |
| 388 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 389 | body.sensorInitialization &= ~(1 << 2); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 390 | } |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 391 | }; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 392 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 393 | inline void initHystState(bool enabled, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 394 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 395 | if (enabled) |
| 396 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 397 | body.sensorInitialization |= 1 << 3; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 398 | } |
| 399 | else |
| 400 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 401 | body.sensorInitialization &= ~(1 << 3); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 402 | } |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 403 | }; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 404 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 405 | inline void initThreshState(bool enabled, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 406 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 407 | if (enabled) |
| 408 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 409 | body.sensorInitialization |= 1 << 4; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 410 | } |
| 411 | else |
| 412 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 413 | body.sensorInitialization &= ~(1 << 4); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 414 | } |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 415 | }; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 416 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 417 | inline void initEventsState(bool enabled, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 418 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 419 | if (enabled) |
| 420 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 421 | body.sensorInitialization |= 1 << 5; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 422 | } |
| 423 | else |
| 424 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 425 | body.sensorInitialization &= ~(1 << 5); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 426 | } |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 427 | }; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 428 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 429 | inline void initScanningState(bool enabled, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 430 | { |
| 431 | if (enabled) |
| 432 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 433 | body.sensorInitialization |= 1 << 6; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 434 | } |
| 435 | else |
| 436 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 437 | body.sensorInitialization &= ~(1 << 6); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 438 | } |
| 439 | }; |
| 440 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 441 | inline void initSettableState(bool enabled, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 442 | { |
| 443 | if (enabled) |
| 444 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 445 | body.sensorInitialization |= 1 << 7; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 446 | } |
| 447 | else |
| 448 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 449 | body.sensorInitialization &= ~(1 << 7); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 450 | } |
| 451 | }; |
| 452 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 453 | inline void setPercentage(SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 454 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 455 | body.sensorUnits1 |= 1 << 0; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 456 | }; |
| 457 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 458 | inline void unsetPercentage(SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 459 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 460 | body.sensorUnits1 &= ~(1 << 0); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 461 | }; |
| 462 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 463 | inline void setModifierOperation(uint8_t op, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 464 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 465 | body.sensorUnits1 &= ~(3 << 1); |
| 466 | body.sensorUnits1 |= (op & 0x3) << 1; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 467 | }; |
| 468 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 469 | inline void setRateUnit(uint8_t unit, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 470 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 471 | body.sensorUnits1 &= ~(7 << 3); |
| 472 | body.sensorUnits1 |= (unit & 0x7) << 3; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 473 | }; |
| 474 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 475 | inline void setAnalogDataFormat(uint8_t format, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 476 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 477 | body.sensorUnits1 &= ~(3 << 6); |
| 478 | body.sensorUnits1 |= (format & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 479 | }; |
| 480 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 481 | inline void setM(uint16_t m, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 482 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 483 | body.mLsb = m & 0xff; |
| 484 | body.mMsbAndTolerance &= ~(3 << 6); |
| 485 | body.mMsbAndTolerance |= ((m & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 486 | }; |
| 487 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 488 | inline void setTolerance(uint8_t tol, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 489 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 490 | body.mMsbAndTolerance &= ~0x3f; |
| 491 | body.mMsbAndTolerance |= tol & 0x3f; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 492 | }; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 493 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 494 | inline void setB(uint16_t b, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 495 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 496 | body.bLsb = b & 0xff; |
| 497 | body.bMsbAndAccuracyLsb &= ~(3 << 6); |
| 498 | body.bMsbAndAccuracyLsb |= ((b & (3 << 8)) >> 2); |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 499 | }; |
| 500 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 501 | inline void setAccuracy(uint16_t acc, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 502 | { |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 503 | // bottom 6 bits |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 504 | body.bMsbAndAccuracyLsb &= ~0x3f; |
| 505 | body.bMsbAndAccuracyLsb |= acc & 0x3f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 506 | // top 4 bits |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 507 | body.accuracyAndSensorDirection &= 0x0f; |
| 508 | body.accuracyAndSensorDirection |= ((acc >> 6) & 0xf) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 509 | }; |
| 510 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 511 | inline void setAccuracyExp(uint8_t exp, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 512 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 513 | body.accuracyAndSensorDirection &= ~(3 << 2); |
| 514 | body.accuracyAndSensorDirection |= (exp & 3) << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 515 | }; |
| 516 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 517 | inline void setSensorDir(uint8_t dir, SensorDataFullRecordBody& body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 518 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 519 | body.accuracyAndSensorDirection &= ~(3 << 0); |
| 520 | body.accuracyAndSensorDirection |= (dir & 3); |
Willy Tu | eae8859 | 2022-12-13 14:28:02 -0800 | [diff] [blame] | 521 | }; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 522 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 523 | inline void setBexp(uint8_t exp, SensorDataFullRecordBody& body) |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 524 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 525 | body.rbExponents &= 0xf0; |
| 526 | body.rbExponents |= exp & 0x0f; |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 527 | }; |
| 528 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 529 | inline void setRexp(uint8_t exp, SensorDataFullRecordBody& body) |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 530 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 531 | body.rbExponents &= 0x0f; |
| 532 | body.rbExponents |= (exp & 0x0f) << 4; |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 533 | }; |
| 534 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 535 | inline void setIdStrLen(uint8_t len, SensorDataFullRecordBody& body) |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 536 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 537 | body.idStringInfo &= ~(0x1f); |
| 538 | body.idStringInfo |= len & 0x1f; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 539 | }; |
| 540 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 541 | inline void setIdStrLen(uint8_t len, SensorDataEventRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 542 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 543 | body.idStringInfo &= ~(0x1f); |
| 544 | body.idStringInfo |= len & 0x1f; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 545 | }; |
| 546 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 547 | inline uint8_t getIdStrLen(const SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 548 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 549 | return body.idStringInfo & 0x1f; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 550 | }; |
| 551 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 552 | inline void setIdType(uint8_t type, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 553 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 554 | body.idStringInfo &= ~(3 << 6); |
| 555 | body.idStringInfo |= (type & 0x3) << 6; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 556 | }; |
| 557 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 558 | inline void setIdType(uint8_t type, SensorDataEventRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 559 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 560 | body.idStringInfo &= ~(3 << 6); |
| 561 | body.idStringInfo |= (type & 0x3) << 6; |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 562 | }; |
| 563 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 564 | inline void setDeviceIdStrLen(uint8_t len, SensorDataFruRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 565 | { |
| 566 | body.deviceIDLen &= ~(LENGTH_MASK); |
| 567 | body.deviceIDLen |= len & LENGTH_MASK; |
| 568 | }; |
| 569 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 570 | inline uint8_t getDeviceIdStrLen(const SensorDataFruRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 571 | { |
| 572 | return body.deviceIDLen & LENGTH_MASK; |
| 573 | }; |
| 574 | |
George Liu | f60be69 | 2025-08-19 11:28:42 +0800 | [diff] [blame] | 575 | inline void setReadableMask(uint8_t mask, SensorDataFullRecordBody& body) |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 576 | { |
George Liu | 42247d2 | 2025-08-19 10:24:47 +0800 | [diff] [blame] | 577 | body.discreteReadingSettingMask[1] = mask & 0x3F; |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 578 | } |
| 579 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 580 | } // namespace body |
| 581 | |
| 582 | // More types contained in section 43.17 Sensor Unit Type Codes, |
| 583 | // IPMI spec v2 rev 1.1 |
| 584 | enum SensorUnitTypeCodes |
| 585 | { |
| 586 | SENSOR_UNIT_UNSPECIFIED = 0, |
| 587 | SENSOR_UNIT_DEGREES_C = 1, |
| 588 | SENSOR_UNIT_VOLTS = 4, |
| 589 | SENSOR_UNIT_AMPERES = 5, |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 590 | SENSOR_UNIT_WATTS = 6, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 591 | SENSOR_UNIT_JOULES = 7, |
Kirill Pakhomov | 812e44c | 2018-10-22 16:25:35 +0300 | [diff] [blame] | 592 | SENSOR_UNIT_RPM = 18, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 593 | SENSOR_UNIT_METERS = 34, |
| 594 | SENSOR_UNIT_REVOLUTIONS = 41, |
| 595 | }; |
| 596 | |
| 597 | struct SensorDataFullRecord |
| 598 | { |
| 599 | SensorDataRecordHeader header; |
| 600 | SensorDataRecordKey key; |
| 601 | SensorDataFullRecordBody body; |
| 602 | } __attribute__((packed)); |
| 603 | |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 604 | /** @struct SensorDataComapactRecord |
| 605 | * |
| 606 | * Compact Sensor Record - SDR Type 2 |
| 607 | */ |
| 608 | struct SensorDataCompactRecord |
| 609 | { |
| 610 | SensorDataRecordHeader header; |
| 611 | SensorDataRecordKey key; |
| 612 | SensorDataCompactRecordBody body; |
| 613 | } __attribute__((packed)); |
| 614 | |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 615 | /** @struct SensorDataEventRecord |
| 616 | * |
| 617 | * Event Only Sensor Record - SDR Type 3 |
| 618 | */ |
| 619 | struct SensorDataEventRecord |
| 620 | { |
| 621 | SensorDataRecordHeader header; |
| 622 | SensorDataRecordKey key; |
| 623 | SensorDataEventRecordBody body; |
| 624 | } __attribute__((packed)); |
| 625 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 626 | /** @struct SensorDataFruRecord |
| 627 | * |
| 628 | * FRU Device Locator Record - SDR Type 11 |
| 629 | */ |
| 630 | struct SensorDataFruRecord |
| 631 | { |
| 632 | SensorDataRecordHeader header; |
| 633 | SensorDataFruRecordKey key; |
| 634 | SensorDataFruRecordBody body; |
| 635 | } __attribute__((packed)); |
| 636 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 637 | /** @struct SensorDataEntityRecord |
| 638 | * |
| 639 | * Entity Association Record - SDR Type 8 |
| 640 | */ |
| 641 | struct SensorDataEntityRecord |
| 642 | { |
| 643 | SensorDataRecordHeader header; |
| 644 | SensorDataEntityRecordKey key; |
| 645 | SensorDataEntityRecordBody body; |
| 646 | } __attribute__((packed)); |
| 647 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 648 | } // namespace get_sdr |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 649 | |
| 650 | namespace ipmi |
| 651 | { |
| 652 | |
| 653 | namespace sensor |
| 654 | { |
| 655 | |
| 656 | /** |
| 657 | * @brief Map offset to the corresponding bit in the assertion byte. |
| 658 | * |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 659 | * The discrete sensors support up to 14 states. 0-7 offsets are stored in one |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 660 | * byte and offsets 8-14 in the second byte. |
| 661 | * |
| 662 | * @param[in] offset - offset number. |
| 663 | * @param[in/out] resp - get sensor reading response. |
| 664 | */ |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 665 | inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse& resp) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 666 | { |
| 667 | if (offset > 7) |
| 668 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 669 | resp.discreteReadingSensorStates |= 1 << (offset - 8); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 670 | } |
| 671 | else |
| 672 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 673 | resp.thresholdLevelsStates |= 1 << offset; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 677 | /** |
| 678 | * @brief Set the reading field in the response. |
| 679 | * |
| 680 | * @param[in] offset - offset number. |
| 681 | * @param[in/out] resp - get sensor reading response. |
| 682 | */ |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 683 | inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse& resp) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 684 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 685 | resp.reading = value; |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 686 | } |
| 687 | |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 688 | /** |
| 689 | * @brief Map the value to the assertion bytes. The assertion states are stored |
| 690 | * in 2 bytes. |
| 691 | * |
| 692 | * @param[in] value - value to mapped to the assertion byte. |
| 693 | * @param[in/out] resp - get sensor reading response. |
| 694 | */ |
| 695 | inline void setAssertionBytes(uint16_t value, |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 696 | ipmi::sensor::GetSensorResponse& resp) |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 697 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 698 | resp.thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF); |
| 699 | resp.discreteReadingSensorStates = static_cast<uint8_t>(value >> 8); |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 700 | } |
| 701 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 702 | /** |
| 703 | * @brief Set the scanning enabled bit in the response. |
| 704 | * |
| 705 | * @param[in/out] resp - get sensor reading response. |
| 706 | */ |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 707 | inline void enableScanning(ipmi::sensor::GetSensorResponse& resp) |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 708 | { |
George Liu | e6b2be5 | 2025-08-19 13:57:43 +0800 | [diff] [blame] | 709 | resp.readingOrStateUnavailable = false; |
| 710 | resp.scanningEnabled = true; |
| 711 | resp.allEventMessagesEnabled = false; |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 712 | } |
| 713 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 714 | } // namespace sensor |
| 715 | |
| 716 | } // namespace ipmi |