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