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 | 23c868c | 2025-07-04 09:31:35 +0800 | [diff] [blame] | 77 | ipmi::Cc ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 78 | ipmi_request_t request, ipmi_response_t response, |
| 79 | ipmi_data_len_t data_len, ipmi_context_t context); |
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 | |
| 95 | struct GetSdrReq |
| 96 | { |
| 97 | uint8_t reservation_id_lsb; |
| 98 | uint8_t reservation_id_msb; |
| 99 | uint8_t record_id_lsb; |
| 100 | uint8_t record_id_msb; |
| 101 | uint8_t offset; |
| 102 | uint8_t bytes_to_read; |
| 103 | } __attribute__((packed)); |
| 104 | |
| 105 | namespace request |
| 106 | { |
| 107 | |
Emily Shaffer | e5c9d2f | 2019-06-25 14:26:45 -0700 | [diff] [blame] | 108 | inline uint16_t get_reservation_id(GetSdrReq* req) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 109 | { |
| 110 | return (req->reservation_id_lsb + (req->reservation_id_msb << 8)); |
| 111 | }; |
| 112 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 113 | inline uint16_t get_record_id(GetSdrReq* req) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 114 | { |
| 115 | return (req->record_id_lsb + (req->record_id_msb << 8)); |
| 116 | }; |
| 117 | |
| 118 | } // namespace request |
| 119 | |
| 120 | // Response |
| 121 | struct GetSdrResp |
| 122 | { |
| 123 | uint8_t next_record_id_lsb; |
| 124 | uint8_t next_record_id_msb; |
| 125 | uint8_t record_data[64]; |
| 126 | } __attribute__((packed)); |
| 127 | |
| 128 | namespace response |
| 129 | { |
| 130 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 131 | inline void set_next_record_id(uint16_t next, GetSdrResp* resp) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 132 | { |
| 133 | resp->next_record_id_lsb = next & 0xff; |
| 134 | resp->next_record_id_msb = (next >> 8) & 0xff; |
| 135 | }; |
| 136 | |
| 137 | } // namespace response |
| 138 | |
| 139 | // Record header |
| 140 | struct SensorDataRecordHeader |
| 141 | { |
| 142 | uint8_t record_id_lsb; |
| 143 | uint8_t record_id_msb; |
| 144 | uint8_t sdr_version; |
| 145 | uint8_t record_type; |
| 146 | uint8_t record_length; // Length not counting the header |
| 147 | } __attribute__((packed)); |
| 148 | |
| 149 | namespace header |
| 150 | { |
| 151 | |
| 152 | inline void set_record_id(int id, SensorDataRecordHeader* hdr) |
| 153 | { |
| 154 | hdr->record_id_lsb = (id & 0xFF); |
| 155 | hdr->record_id_msb = (id >> 8) & 0xFF; |
| 156 | }; |
| 157 | |
| 158 | } // namespace header |
| 159 | |
| 160 | enum SensorDataRecordType |
| 161 | { |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 162 | SENSOR_DATA_FULL_RECORD = 0x1, |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 163 | SENSOR_DATA_COMPACT_RECORD = 0x2, |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 164 | SENSOR_DATA_EVENT_RECORD = 0x3, |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 165 | SENSOR_DATA_ENTITY_RECORD = 0x8, |
Harvey Wu | a347627 | 2023-03-22 10:09:38 +0800 | [diff] [blame] | 166 | SENSOR_DATA_FRU_RECORD = 0x11, |
| 167 | SENSOR_DATA_MGMT_CTRL_LOCATOR = 0x12, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | // Record key |
| 171 | struct SensorDataRecordKey |
| 172 | { |
| 173 | uint8_t owner_id; |
| 174 | uint8_t owner_lun; |
| 175 | uint8_t sensor_number; |
| 176 | } __attribute__((packed)); |
| 177 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 178 | /** @struct SensorDataFruRecordKey |
| 179 | * |
| 180 | * FRU Device Locator Record(key) - SDR Type 11 |
| 181 | */ |
| 182 | struct SensorDataFruRecordKey |
| 183 | { |
| 184 | uint8_t deviceAddress; |
| 185 | uint8_t fruID; |
| 186 | uint8_t accessLun; |
| 187 | uint8_t channelNumber; |
| 188 | } __attribute__((packed)); |
| 189 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 190 | /** @struct SensorDataEntityRecordKey |
| 191 | * |
| 192 | * Entity Association Record(key) - SDR Type 8 |
| 193 | */ |
| 194 | struct SensorDataEntityRecordKey |
| 195 | { |
| 196 | uint8_t containerEntityId; |
| 197 | uint8_t containerEntityInstance; |
| 198 | uint8_t flags; |
| 199 | uint8_t entityId1; |
| 200 | uint8_t entityInstance1; |
| 201 | } __attribute__((packed)); |
| 202 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 203 | namespace key |
| 204 | { |
| 205 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 206 | static constexpr uint8_t listOrRangeBit = 7; |
| 207 | static constexpr uint8_t linkedBit = 6; |
| 208 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 209 | inline void set_owner_id_ipmb(SensorDataRecordKey* key) |
| 210 | { |
| 211 | key->owner_id &= ~0x01; |
| 212 | }; |
| 213 | |
| 214 | inline void set_owner_id_system_sw(SensorDataRecordKey* key) |
| 215 | { |
| 216 | key->owner_id |= 0x01; |
| 217 | }; |
| 218 | |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 219 | inline void set_owner_id_bmc(SensorDataRecordKey* key) |
| 220 | { |
| 221 | key->owner_id |= 0x20; |
| 222 | }; |
| 223 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 224 | inline void set_owner_id_address(uint8_t addr, SensorDataRecordKey* key) |
| 225 | { |
| 226 | key->owner_id &= 0x01; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 227 | key->owner_id |= addr << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | inline void set_owner_lun(uint8_t lun, SensorDataRecordKey* key) |
| 231 | { |
| 232 | key->owner_lun &= ~0x03; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 233 | key->owner_lun |= (lun & 0x03); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | inline void set_owner_lun_channel(uint8_t channel, SensorDataRecordKey* key) |
| 237 | { |
| 238 | key->owner_lun &= 0x0f; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 239 | key->owner_lun |= ((channel & 0xf) << 4); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 242 | inline void set_flags(bool isList, bool isLinked, |
| 243 | SensorDataEntityRecordKey* key) |
| 244 | { |
| 245 | key->flags = 0x00; |
| 246 | if (!isList) |
| 247 | key->flags |= 1 << listOrRangeBit; |
| 248 | |
| 249 | if (isLinked) |
| 250 | key->flags |= 1 << linkedBit; |
| 251 | }; |
| 252 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 253 | } // namespace key |
| 254 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 255 | /** @struct GetSensorThresholdsResponse |
| 256 | * |
| 257 | * Response structure for Get Sensor Thresholds command |
| 258 | */ |
| 259 | struct GetSensorThresholdsResponse |
| 260 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 261 | uint8_t validMask; //!< valid mask |
| 262 | uint8_t lowerNonCritical; //!< lower non-critical threshold |
| 263 | uint8_t lowerCritical; //!< lower critical threshold |
| 264 | uint8_t lowerNonRecoverable; //!< lower non-recoverable threshold |
| 265 | uint8_t upperNonCritical; //!< upper non-critical threshold |
| 266 | uint8_t upperCritical; //!< upper critical threshold |
| 267 | uint8_t upperNonRecoverable; //!< upper non-recoverable threshold |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 268 | } __attribute__((packed)); |
| 269 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 270 | // Body - full record |
| 271 | #define FULL_RECORD_ID_STR_MAX_LENGTH 16 |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 272 | |
| 273 | static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16; |
| 274 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 275 | struct SensorDataFullRecordBody |
| 276 | { |
| 277 | uint8_t entity_id; |
| 278 | uint8_t entity_instance; |
| 279 | uint8_t sensor_initialization; |
| 280 | uint8_t sensor_capabilities; // no macro support |
| 281 | uint8_t sensor_type; |
| 282 | uint8_t event_reading_type; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 283 | uint8_t supported_assertions[2]; // no macro support |
| 284 | uint8_t supported_deassertions[2]; // no macro support |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 285 | uint8_t discrete_reading_setting_mask[2]; // no macro support |
| 286 | uint8_t sensor_units_1; |
| 287 | uint8_t sensor_units_2_base; |
| 288 | uint8_t sensor_units_3_modifier; |
| 289 | uint8_t linearization; |
| 290 | uint8_t m_lsb; |
| 291 | uint8_t m_msb_and_tolerance; |
| 292 | uint8_t b_lsb; |
| 293 | uint8_t b_msb_and_accuracy_lsb; |
| 294 | uint8_t accuracy_and_sensor_direction; |
| 295 | uint8_t r_b_exponents; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 296 | uint8_t analog_characteristic_flags; // no macro support |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 297 | uint8_t nominal_reading; |
| 298 | uint8_t normal_max; |
| 299 | uint8_t normal_min; |
| 300 | uint8_t sensor_max; |
| 301 | uint8_t sensor_min; |
| 302 | uint8_t upper_nonrecoverable_threshold; |
| 303 | uint8_t upper_critical_threshold; |
| 304 | uint8_t upper_noncritical_threshold; |
| 305 | uint8_t lower_nonrecoverable_threshold; |
| 306 | uint8_t lower_critical_threshold; |
| 307 | uint8_t lower_noncritical_threshold; |
| 308 | uint8_t positive_threshold_hysteresis; |
| 309 | uint8_t negative_threshold_hysteresis; |
| 310 | uint16_t reserved; |
| 311 | uint8_t oem_reserved; |
| 312 | uint8_t id_string_info; |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 313 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 314 | } __attribute__((packed)); |
| 315 | |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 316 | /** @struct SensorDataCompactRecord |
| 317 | * |
| 318 | * Compact Sensor Record(body) - SDR Type 2 |
| 319 | */ |
| 320 | struct SensorDataCompactRecordBody |
| 321 | { |
| 322 | uint8_t entity_id; |
| 323 | uint8_t entity_instance; |
| 324 | uint8_t sensor_initialization; |
| 325 | uint8_t sensor_capabilities; // no macro support |
| 326 | uint8_t sensor_type; |
| 327 | uint8_t event_reading_type; |
| 328 | uint8_t supported_assertions[2]; // no macro support |
| 329 | uint8_t supported_deassertions[2]; // no macro support |
| 330 | uint8_t discrete_reading_setting_mask[2]; // no macro support |
| 331 | uint8_t sensor_units_1; |
| 332 | uint8_t sensor_units_2_base; |
| 333 | uint8_t sensor_units_3_modifier; |
| 334 | uint8_t record_sharing[2]; |
| 335 | uint8_t positive_threshold_hysteresis; |
| 336 | uint8_t negative_threshold_hysteresis; |
| 337 | uint8_t reserved[3]; |
| 338 | uint8_t oem_reserved; |
| 339 | uint8_t id_string_info; |
| 340 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
| 341 | } __attribute__((packed)); |
| 342 | |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 343 | /** @struct SensorDataEventRecord |
| 344 | * |
| 345 | * Event Only Sensor Record(body) - SDR Type 3 |
| 346 | */ |
| 347 | struct SensorDataEventRecordBody |
| 348 | { |
| 349 | uint8_t entity_id; |
| 350 | uint8_t entity_instance; |
| 351 | uint8_t sensor_type; |
| 352 | uint8_t event_reading_type; |
| 353 | uint8_t sensor_record_sharing_1; |
| 354 | uint8_t sensor_record_sharing_2; |
| 355 | uint8_t reserved; |
| 356 | uint8_t oem_reserved; |
| 357 | uint8_t id_string_info; |
| 358 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
| 359 | } __attribute__((packed)); |
| 360 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 361 | /** @struct SensorDataFruRecordBody |
| 362 | * |
| 363 | * FRU Device Locator Record(body) - SDR Type 11 |
| 364 | */ |
| 365 | struct SensorDataFruRecordBody |
| 366 | { |
| 367 | uint8_t reserved; |
| 368 | uint8_t deviceType; |
| 369 | uint8_t deviceTypeModifier; |
| 370 | uint8_t entityID; |
| 371 | uint8_t entityInstance; |
| 372 | uint8_t oem; |
| 373 | uint8_t deviceIDLen; |
| 374 | char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH]; |
| 375 | } __attribute__((packed)); |
| 376 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 377 | /** @struct SensorDataEntityRecordBody |
| 378 | * |
| 379 | * Entity Association Record(body) - SDR Type 8 |
| 380 | */ |
| 381 | struct SensorDataEntityRecordBody |
| 382 | { |
| 383 | uint8_t entityId2; |
| 384 | uint8_t entityInstance2; |
| 385 | uint8_t entityId3; |
| 386 | uint8_t entityInstance3; |
| 387 | uint8_t entityId4; |
| 388 | uint8_t entityInstance4; |
| 389 | } __attribute__((packed)); |
| 390 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 391 | namespace body |
| 392 | { |
| 393 | |
| 394 | inline void set_entity_instance_number(uint8_t n, |
| 395 | SensorDataFullRecordBody* body) |
| 396 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 397 | body->entity_instance &= 1 << 7; |
| 398 | body->entity_instance |= (n & ~(1 << 7)); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 399 | }; |
| 400 | inline void set_entity_physical_entity(SensorDataFullRecordBody* body) |
| 401 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 402 | body->entity_instance &= ~(1 << 7); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 403 | }; |
| 404 | inline void set_entity_logical_container(SensorDataFullRecordBody* body) |
| 405 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 406 | body->entity_instance |= 1 << 7; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 407 | }; |
| 408 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 409 | inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 410 | { |
| 411 | if (enabled) |
| 412 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 413 | body->sensor_initialization |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 414 | } |
| 415 | else |
| 416 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 417 | body->sensor_initialization &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 418 | }; |
| 419 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 420 | inline void event_generation_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 421 | { |
| 422 | if (enabled) |
| 423 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 424 | body->sensor_initialization |= 1 << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 425 | } |
| 426 | else |
| 427 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 428 | body->sensor_initialization &= ~(1 << 1); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 429 | } |
| 430 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 431 | inline void init_types_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 432 | { |
| 433 | if (enabled) |
| 434 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 435 | body->sensor_initialization |= 1 << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 436 | } |
| 437 | else |
| 438 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 439 | body->sensor_initialization &= ~(1 << 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 440 | } |
| 441 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 442 | inline void init_hyst_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 443 | { |
| 444 | if (enabled) |
| 445 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 446 | body->sensor_initialization |= 1 << 3; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 447 | } |
| 448 | else |
| 449 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 450 | body->sensor_initialization &= ~(1 << 3); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 451 | } |
| 452 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 453 | inline void init_thresh_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 454 | { |
| 455 | if (enabled) |
| 456 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 457 | body->sensor_initialization |= 1 << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 458 | } |
| 459 | else |
| 460 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 461 | body->sensor_initialization &= ~(1 << 4); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 462 | } |
| 463 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 464 | inline void init_events_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 465 | { |
| 466 | if (enabled) |
| 467 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 468 | body->sensor_initialization |= 1 << 5; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 469 | } |
| 470 | else |
| 471 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 472 | body->sensor_initialization &= ~(1 << 5); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 473 | } |
| 474 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 475 | inline void init_scanning_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 476 | { |
| 477 | if (enabled) |
| 478 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 479 | body->sensor_initialization |= 1 << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 480 | } |
| 481 | else |
| 482 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 483 | body->sensor_initialization &= ~(1 << 6); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 484 | } |
| 485 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 486 | inline void init_settable_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 487 | { |
| 488 | if (enabled) |
| 489 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 490 | body->sensor_initialization |= 1 << 7; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 491 | } |
| 492 | else |
| 493 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 494 | body->sensor_initialization &= ~(1 << 7); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 495 | } |
| 496 | }; |
| 497 | |
| 498 | inline void set_percentage(SensorDataFullRecordBody* body) |
| 499 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 500 | body->sensor_units_1 |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 501 | }; |
| 502 | inline void unset_percentage(SensorDataFullRecordBody* body) |
| 503 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 504 | body->sensor_units_1 &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 505 | }; |
| 506 | inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody* body) |
| 507 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 508 | body->sensor_units_1 &= ~(3 << 1); |
| 509 | body->sensor_units_1 |= (op & 0x3) << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 510 | }; |
| 511 | inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody* body) |
| 512 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 513 | body->sensor_units_1 &= ~(7 << 3); |
| 514 | body->sensor_units_1 |= (unit & 0x7) << 3; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 515 | }; |
| 516 | inline void set_analog_data_format(uint8_t format, |
| 517 | SensorDataFullRecordBody* body) |
| 518 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 519 | body->sensor_units_1 &= ~(3 << 6); |
| 520 | body->sensor_units_1 |= (format & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 521 | }; |
| 522 | |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 523 | inline void set_m(uint16_t m, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 524 | { |
| 525 | body->m_lsb = m & 0xff; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 526 | body->m_msb_and_tolerance &= ~(3 << 6); |
| 527 | body->m_msb_and_tolerance |= ((m & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 528 | }; |
| 529 | inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody* body) |
| 530 | { |
| 531 | body->m_msb_and_tolerance &= ~0x3f; |
| 532 | body->m_msb_and_tolerance |= tol & 0x3f; |
| 533 | }; |
| 534 | |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 535 | inline void set_b(uint16_t b, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 536 | { |
| 537 | body->b_lsb = b & 0xff; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 538 | body->b_msb_and_accuracy_lsb &= ~(3 << 6); |
| 539 | body->b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 540 | }; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 541 | inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 542 | { |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 543 | // bottom 6 bits |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 544 | body->b_msb_and_accuracy_lsb &= ~0x3f; |
| 545 | body->b_msb_and_accuracy_lsb |= acc & 0x3f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 546 | // top 4 bits |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 547 | body->accuracy_and_sensor_direction &= 0x0f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 548 | body->accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 549 | }; |
| 550 | inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 551 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 552 | body->accuracy_and_sensor_direction &= ~(3 << 2); |
| 553 | body->accuracy_and_sensor_direction |= (exp & 3) << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 554 | }; |
| 555 | inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody* body) |
| 556 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 557 | body->accuracy_and_sensor_direction &= ~(3 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 558 | body->accuracy_and_sensor_direction |= (dir & 3); |
| 559 | }; |
| 560 | |
| 561 | inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 562 | { |
| 563 | body->r_b_exponents &= 0xf0; |
| 564 | body->r_b_exponents |= exp & 0x0f; |
| 565 | }; |
| 566 | inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 567 | { |
| 568 | body->r_b_exponents &= 0x0f; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 569 | body->r_b_exponents |= (exp & 0x0f) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body) |
| 573 | { |
| 574 | body->id_string_info &= ~(0x1f); |
| 575 | body->id_string_info |= len & 0x1f; |
| 576 | }; |
Willy Tu | eae8859 | 2022-12-13 14:28:02 -0800 | [diff] [blame] | 577 | inline void set_id_strlen(uint8_t len, SensorDataEventRecordBody* body) |
| 578 | { |
| 579 | body->id_string_info &= ~(0x1f); |
| 580 | body->id_string_info |= len & 0x1f; |
| 581 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 582 | inline uint8_t get_id_strlen(SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 583 | { |
| 584 | return body->id_string_info & 0x1f; |
| 585 | }; |
| 586 | inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body) |
| 587 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 588 | body->id_string_info &= ~(3 << 6); |
| 589 | body->id_string_info |= (type & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 590 | }; |
Willy Tu | eae8859 | 2022-12-13 14:28:02 -0800 | [diff] [blame] | 591 | inline void set_id_type(uint8_t type, SensorDataEventRecordBody* body) |
| 592 | { |
| 593 | body->id_string_info &= ~(3 << 6); |
| 594 | body->id_string_info |= (type & 0x3) << 6; |
| 595 | }; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 596 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 597 | inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody* body) |
| 598 | { |
| 599 | body->deviceIDLen &= ~(LENGTH_MASK); |
| 600 | body->deviceIDLen |= len & LENGTH_MASK; |
| 601 | }; |
| 602 | |
| 603 | inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body) |
| 604 | { |
| 605 | return body->deviceIDLen & LENGTH_MASK; |
| 606 | }; |
| 607 | |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 608 | inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body) |
| 609 | { |
| 610 | body->discrete_reading_setting_mask[1] = mask & 0x3F; |
| 611 | } |
| 612 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 613 | } // namespace body |
| 614 | |
| 615 | // More types contained in section 43.17 Sensor Unit Type Codes, |
| 616 | // IPMI spec v2 rev 1.1 |
| 617 | enum SensorUnitTypeCodes |
| 618 | { |
| 619 | SENSOR_UNIT_UNSPECIFIED = 0, |
| 620 | SENSOR_UNIT_DEGREES_C = 1, |
| 621 | SENSOR_UNIT_VOLTS = 4, |
| 622 | SENSOR_UNIT_AMPERES = 5, |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 623 | SENSOR_UNIT_WATTS = 6, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 624 | SENSOR_UNIT_JOULES = 7, |
Kirill Pakhomov | 812e44c | 2018-10-22 16:25:35 +0300 | [diff] [blame] | 625 | SENSOR_UNIT_RPM = 18, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 626 | SENSOR_UNIT_METERS = 34, |
| 627 | SENSOR_UNIT_REVOLUTIONS = 41, |
| 628 | }; |
| 629 | |
| 630 | struct SensorDataFullRecord |
| 631 | { |
| 632 | SensorDataRecordHeader header; |
| 633 | SensorDataRecordKey key; |
| 634 | SensorDataFullRecordBody body; |
| 635 | } __attribute__((packed)); |
| 636 | |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 637 | /** @struct SensorDataComapactRecord |
| 638 | * |
| 639 | * Compact Sensor Record - SDR Type 2 |
| 640 | */ |
| 641 | struct SensorDataCompactRecord |
| 642 | { |
| 643 | SensorDataRecordHeader header; |
| 644 | SensorDataRecordKey key; |
| 645 | SensorDataCompactRecordBody body; |
| 646 | } __attribute__((packed)); |
| 647 | |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 648 | /** @struct SensorDataEventRecord |
| 649 | * |
| 650 | * Event Only Sensor Record - SDR Type 3 |
| 651 | */ |
| 652 | struct SensorDataEventRecord |
| 653 | { |
| 654 | SensorDataRecordHeader header; |
| 655 | SensorDataRecordKey key; |
| 656 | SensorDataEventRecordBody body; |
| 657 | } __attribute__((packed)); |
| 658 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 659 | /** @struct SensorDataFruRecord |
| 660 | * |
| 661 | * FRU Device Locator Record - SDR Type 11 |
| 662 | */ |
| 663 | struct SensorDataFruRecord |
| 664 | { |
| 665 | SensorDataRecordHeader header; |
| 666 | SensorDataFruRecordKey key; |
| 667 | SensorDataFruRecordBody body; |
| 668 | } __attribute__((packed)); |
| 669 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 670 | /** @struct SensorDataEntityRecord |
| 671 | * |
| 672 | * Entity Association Record - SDR Type 8 |
| 673 | */ |
| 674 | struct SensorDataEntityRecord |
| 675 | { |
| 676 | SensorDataRecordHeader header; |
| 677 | SensorDataEntityRecordKey key; |
| 678 | SensorDataEntityRecordBody body; |
| 679 | } __attribute__((packed)); |
| 680 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 681 | } // namespace get_sdr |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 682 | |
| 683 | namespace ipmi |
| 684 | { |
| 685 | |
| 686 | namespace sensor |
| 687 | { |
| 688 | |
| 689 | /** |
| 690 | * @brief Map offset to the corresponding bit in the assertion byte. |
| 691 | * |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 692 | * 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] | 693 | * byte and offsets 8-14 in the second byte. |
| 694 | * |
| 695 | * @param[in] offset - offset number. |
| 696 | * @param[in/out] resp - get sensor reading response. |
| 697 | */ |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 698 | inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 699 | { |
| 700 | if (offset > 7) |
| 701 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 702 | resp->discreteReadingSensorStates |= 1 << (offset - 8); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 703 | } |
| 704 | else |
| 705 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 706 | resp->thresholdLevelsStates |= 1 << offset; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 710 | /** |
| 711 | * @brief Set the reading field in the response. |
| 712 | * |
| 713 | * @param[in] offset - offset number. |
| 714 | * @param[in/out] resp - get sensor reading response. |
| 715 | */ |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 716 | inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 717 | { |
| 718 | resp->reading = value; |
| 719 | } |
| 720 | |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 721 | /** |
| 722 | * @brief Map the value to the assertion bytes. The assertion states are stored |
| 723 | * in 2 bytes. |
| 724 | * |
| 725 | * @param[in] value - value to mapped to the assertion byte. |
| 726 | * @param[in/out] resp - get sensor reading response. |
| 727 | */ |
| 728 | inline void setAssertionBytes(uint16_t value, |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 729 | ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 730 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 731 | resp->thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF); |
| 732 | resp->discreteReadingSensorStates = static_cast<uint8_t>(value >> 8); |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 733 | } |
| 734 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 735 | /** |
| 736 | * @brief Set the scanning enabled bit in the response. |
| 737 | * |
| 738 | * @param[in/out] resp - get sensor reading response. |
| 739 | */ |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 740 | inline void enableScanning(ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 741 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 742 | resp->readingOrStateUnavailable = false; |
| 743 | resp->scanningEnabled = true; |
| 744 | resp->allEventMessagesEnabled = false; |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 745 | } |
| 746 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 747 | } // namespace sensor |
| 748 | |
| 749 | } // namespace ipmi |