libpldm: Implement encode/decode for GetStateSensorReadings
The spec of GetStateSensorReadings command refers to DSP0248_1.2.0: 20.2
Change-Id: I8b2222196d1b960697b73d83911937c4164b09af
Signed-off-by: Jolie Ku <jolie_ku@wistron.com>
diff --git a/libpldm/platform.h b/libpldm/platform.h
index 0cce1b4..0371d1c 100644
--- a/libpldm/platform.h
+++ b/libpldm/platform.h
@@ -12,8 +12,10 @@
/* Maximum size for request */
#define PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES 19
+#define PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES 4
/* Response lengths are inclusive of completion code */
#define PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES 1
+#define PLDM_GET_STATE_SENSOR_READINGS_RESP_BYTES 34
#define PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES 1
#define PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES 4
@@ -35,7 +37,33 @@
enum effecter_state { PLDM_INVALID_VALUE = 0xFF };
+enum sensor_operational_state {
+ ENABLED = 0x00,
+ DISABLED = 0x01,
+ UNAVAILABLE = 0x02,
+ STATUSUNKNOWN = 0x03,
+ FAILED = 0x04,
+ INITIALIZING = 0x05,
+ SHUTTINGDOWN = 0x06,
+ INTEST = 0x07
+};
+
+enum present_state {
+ UNKNOWN = 0x0,
+ NORMAL = 0x01,
+ WARNING = 0x02,
+ CRITICAL = 0x03,
+ FATAL = 0x04,
+ LOWERWARNING = 0x05,
+ LOWERCRITICAL = 0x06,
+ LOWERFATAL = 0x07,
+ UPPERWARNING = 0x08,
+ UPPERCRITICAL = 0x09,
+ UPPERFATAL = 0x0a
+};
+
enum pldm_platform_commands {
+ PLDM_GET_STATE_SENSOR_READINGS = 0x21,
PLDM_SET_NUMERIC_EFFECTER_VALUE = 0x31,
PLDM_SET_STATE_EFFECTER_STATES = 0x39,
PLDM_GET_PDR = 0x51,
@@ -127,6 +155,20 @@
uint8_t effecter_state; //!< Expected state of the effecter
} __attribute__((packed)) set_effecter_state_field;
+/** @struct get_sensor_readings_field
+ *
+ * Structure representing a stateField in GetStateSensorReadings command */
+
+typedef struct state_field_for_get_state_sensor_readings {
+ uint8_t sensor_op_state; //!< The state of the sensor itself
+ uint8_t present_state; //!< Return a state value
+ uint8_t previous_state; //!< The state that the presentState was entered
+ //! from. This must be different from the
+ //! present state
+ uint8_t event_state; //!< Return a state value from a PLDM State Set
+ //! that is associated with the sensor
+} __attribute__((packed)) get_sensor_state_field;
+
/** @struct PLDM_SetStateEffecterStates_Request
*
* Structure representing PLDM set state effecter states request.
@@ -174,6 +216,26 @@
uint8_t effecter_value[1];
} __attribute__((packed));
+/** @struct pldm_get_state_sensor_readings_req
+ *
+ * Structure representing PLDM get state sensor readings request.
+ */
+struct pldm_get_state_sensor_readings_req {
+ uint16_t sensor_id;
+ bitfield8_t sensor_rearm;
+ uint8_t reserved;
+} __attribute__((packed));
+
+/** @struct pldm_get_state_sensor_readings_resp
+ *
+ * Structure representing PLDM get state sensor readings response.
+ */
+struct pldm_get_state_sensor_readings_resp {
+ uint8_t completion_code;
+ uint8_t comp_sensor_count;
+ get_sensor_state_field field[1];
+} __attribute__((packed));
+
/* Responder */
/* SetNumericEffecterValue */
@@ -299,6 +361,48 @@
uint8_t *transfer_op_flag, uint16_t *request_cnt,
uint16_t *record_chg_num);
+/* GetStateSensorReadings */
+
+/** @brief Decode GetStateSensorReadings request data
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of request message payload
+ * @param[out] sensor_id - used to identify and access the simple or composite
+ * sensor
+ * @param[out] sensor_rearm - Each bit location in this field corresponds to a
+ * particular sensor within the state sensor, where bit [0] corresponds
+ * to the first state sensor (sensor offset 0) and bit [7] corresponds
+ * to the eighth sensor (sensor offset 7), sequentially.
+ * @param[out] reserved - value: 0x00
+ * @return pldm_completion_codes
+ */
+
+int decode_get_state_sensor_readings_req(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint16_t *sensor_id,
+ bitfield8_t *sensor_rearm,
+ uint8_t *reserved);
+
+/** @brief Encode GetStateSensorReadings response data
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - PLDM completion code
+ * @param[out] comp_sensor_count - The number of individual sets of sensor
+ * information that this command accesses
+ * @param[out] field - Each stateField is an instance of a stateField structure
+ * that is used to return the present operational state setting and the
+ * present state and event state for a particular set of sensor
+ * information contained within the state sensor
+ * @param[out] msg - Message will be written to this
+ * @return pldm_completion_codes
+ */
+
+int encode_get_state_sensor_readings_resp(uint8_t instance_id,
+ uint8_t completion_code,
+ uint8_t comp_sensor_count,
+ get_sensor_state_field *field,
+ struct pldm_msg *msg);
+
/* Requester */
/* GetPDR */
@@ -433,6 +537,48 @@
size_t payload_length,
uint8_t *completion_code);
+/** @brief Create a PLDM request message for GetStateSensorReadings
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] sensor_id - used to identify and access the simple or composite
+ * sensor
+ * @param[in] sensorRearm - Each bit location in this field corresponds to a
+ * particular sensor within the state sensor, where bit [0] corresponds
+ * to the first state sensor (sensor offset 0) and bit [7] corresponds
+ * to the eighth sensor (sensor offset 7), sequentially
+ * @param[in] reserved - value: 0x00
+ * @param[out] msg - Message will be written to this
+ * @return pldm_completion_codes
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+
+int encode_get_state_sensor_readings_req(uint8_t instance_id,
+ uint16_t sensor_id,
+ bitfield8_t sensor_rearm,
+ uint8_t reserved,
+ struct pldm_msg *msg);
+
+/** @brief Decode GetStateSensorReadings response data
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - PLDM completion code
+ * @param[in,out] comp_sensor_count - The number of individual sets of sensor
+ * information that this command accesses
+ * @param[out] field - Each stateField is an instance of a stateField structure
+ * that is used to return the present operational state setting and the
+ * present state and event state for a particular set of sensor
+ * information contained within the state sensor
+ * @return pldm_completion_codes
+ */
+
+int decode_get_state_sensor_readings_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint8_t *comp_sensor_count,
+ get_sensor_state_field *field);
+
#ifdef __cplusplus
}
#endif