libpldm: Implement encode/decode for GetSensorReading
The spec of GetSensorReading command refers to DSP0248_1.2.0:18.2
Change-Id: I3749efe77db6ff4f87f72a4c59d716522a4aba39
Signed-off-by: Jolie Ku <jolie_ku@wistron.com>
Signed-off-by: George Liu <liuxiwei@inspur.com>
diff --git a/libpldm/platform.h b/libpldm/platform.h
index b3b8eac..3fc8ab3 100644
--- a/libpldm/platform.h
+++ b/libpldm/platform.h
@@ -15,6 +15,7 @@
#define PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES 19
#define PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES 4
#define PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES 2
+#define PLDM_GET_SENSOR_READING_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
@@ -26,6 +27,7 @@
/* Minimum response length */
#define PLDM_GET_PDR_MIN_RESP_BYTES 12
#define PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES 5
+#define PLDM_GET_SENSOR_READING_MIN_RESP_BYTES 8
/* Minimum length for PLDM PlatformEventMessage request */
#define PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES 3
@@ -84,6 +86,14 @@
UPPERFATAL = 0x0a
};
+enum pldm_sensor_event_message_enable {
+ PLDM_NO_EVENT_GENERATION,
+ PLDM_EVENTS_DISABLED,
+ PLDM_EVENTS_ENABLED,
+ PLDM_OP_EVENTS_ONLY_ENABLED,
+ PLDM_STATE_EVENTS_ONLY_ENABLED
+};
+
enum pldm_effecter_oper_state {
EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING,
EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING,
@@ -97,6 +107,7 @@
};
enum pldm_platform_commands {
+ PLDM_GET_SENSOR_READING = 0x11,
PLDM_GET_STATE_SENSOR_READINGS = 0x21,
PLDM_SET_NUMERIC_EFFECTER_VALUE = 0x31,
PLDM_GET_NUMERIC_EFFECTER_VALUE = 0x32,
@@ -464,6 +475,30 @@
uint8_t pending_and_present_values[1];
} __attribute__((packed));
+/** @struct pldm_get_sensor_reading_req
+ *
+ * Structure representing PLDM get sensor reading request
+ */
+struct pldm_get_sensor_reading_req {
+ uint16_t sensor_id;
+ bool8_t rearm_event_state;
+} __attribute__((packed));
+
+/** @struct pldm_get_sensor_reading_resp
+ *
+ * Structure representing PLDM get sensor reading response
+ */
+struct pldm_get_sensor_reading_resp {
+ uint8_t completion_code;
+ uint8_t sensor_data_size;
+ uint8_t sensor_operational_state;
+ uint8_t sensor_event_message_enable;
+ uint8_t present_state;
+ uint8_t previous_state;
+ uint8_t event_state;
+ uint8_t present_reading[1];
+} __attribute__((packed));
+
/* Responder */
/* SetNumericEffecterValue */
@@ -669,6 +704,51 @@
uint8_t effecter_oper_state, uint8_t *pending_value, uint8_t *present_value,
struct pldm_msg *msg, size_t payload_length);
+/* GetSensorReading */
+
+/** @brief Decode GetSensorReading request data
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of request message payload
+ * @param[out] sensor_id - A handle that is used to identify and access
+ * the sensor
+ * @param[out] rearm_event_state - true = manually re-arm EventState after
+ * responding to this request, false = no manual re-arm
+ * @return pldm_completion_codes
+ */
+
+int decode_get_sensor_reading_req(const struct pldm_msg *msg,
+ size_t payload_length, uint16_t *sensor_id,
+ bool8_t *rearm_event_state);
+
+/** @brief Encode GetSensorReading response data
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - PLDM completion code
+ * @param[out] sensor_data_size - The bit width and format of reading and
+ * threshold values
+ * @param[out] sensor_operational_state - The state of the sensor itself
+ * @param[out] sensor_event_message_enable - value: { noEventGeneration,
+ * eventsDisabled, eventsEnabled, opEventsOnlyEnabled,
+ * stateEventsOnlyEnabled }
+ * @param[out] present_state - The most recently assessed state value monitored
+ * by the sensor
+ * @param[out] previous_state - The state that the presentState was entered
+ * from
+ * @param[out] event_state - Indicates which threshold crossing assertion
+ * events have been detected
+ * @param[out] present_reading - The present value indicated by the sensor
+ * @param[out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ * @return pldm_completion_codes
+ */
+
+int encode_get_sensor_reading_resp(
+ uint8_t instance_id, uint8_t completion_code, uint8_t sensor_data_size,
+ uint8_t sensor_operational_state, uint8_t sensor_event_message_enable,
+ uint8_t present_state, uint8_t previous_state, uint8_t event_state,
+ uint8_t *present_reading, struct pldm_msg *msg, size_t payload_length);
+
/* Requester */
/* GetPDR */
@@ -1062,6 +1142,51 @@
uint8_t *event_data_operation, uint8_t *number_of_change_entries,
size_t *change_entry_data_offset);
+/* GetSensorReading */
+
+/** @brief Encode GetSensorReading request data
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] sensor_id - A handle that is used to identify and access the
+ * sensor
+ * @param[in] rearm_event_state - true = manually re-arm EventState after
+ * responding to this request, false = no manual re-arm
+ * @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_sensor_reading_req(uint8_t instance_id, uint16_t sensor_id,
+ bool8_t rearm_event_state,
+ struct pldm_msg *msg);
+
+/** @brief Decode GetSensorReading response data
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - PLDM completion code
+ * @param[out] sensor_data_size - The bit width and format of reading and
+ * threshold values
+ * @param[out] sensor_operational_state - The state of the sensor itself
+ * @param[out] sensor_event_message_enable - value: { noEventGeneration,
+ * eventsDisabled, eventsEnabled, opEventsOnlyEnabled,
+ * stateEventsOnlyEnabled }
+ * @param[out] present_state - The most recently assessed state value monitored
+ * by the sensor
+ * @param[out] previous_state - The state that the presentState was entered
+ * from
+ * @param[out] event_state - Indicates which threshold crossing assertion
+ * events have been detected
+ * @param[out] present_reading - The present value indicated by the sensor
+ * @return pldm_completion_codes
+ */
+
+int decode_get_sensor_reading_resp(
+ const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
+ uint8_t *sensor_data_size, uint8_t *sensor_operational_state,
+ uint8_t *sensor_event_message_enable, uint8_t *present_state,
+ uint8_t *previous_state, uint8_t *event_state, uint8_t *present_reading);
+
#ifdef __cplusplus
}
#endif