diff mbox series

[V3,04/15] core/pldm: Decode the GetStateSensorReadings request

Message ID 20220913102724.65563-5-clombard@linux.vnet.ibm.com
State Superseded
Headers show
Series Complete PLDM responder and enable PLDM support | expand

Commit Message

Christophe Lombard Sept. 13, 2022, 10:27 a.m. UTC
The GetStateSensorReadings command can return readings for multiple state
sensors (a PLDM State Sensor that returns more than one set of state
information is called a composite state sensor).

The Event Receiver acknowledges receiving the PLDM Event Message in the
response to this command.

Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
---
 core/pldm/pldm-responder.c | 83 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
diff mbox series

Patch

diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
index a1a19220..0224ea75 100644
--- a/core/pldm/pldm-responder.c
+++ b/core/pldm/pldm-responder.c
@@ -577,6 +577,89 @@  static struct pldm_cmd pldm_platform_event_message = {
 	.handler = platform_event_message,
 };
 
+struct get_state_sensor_readings_req {
+	uint16_t sensor_id;
+	bitfield8_t sensor_rearm;
+	uint8_t reserved;
+};
+
+/*
+ * GetStateSensorReadings (0x21)
+ * The GetStateSensorReadings command can return readings for multiple
+ * state sensors (a PLDM State Sensor that returns more than one set of
+ * state information is called a composite state sensor).
+ */
+static int platform_get_state_sensor_readings(const struct pldm_rx_data *req)
+{
+	struct get_state_sensor_readings_req readings_req;
+	size_t response_length;
+	char *response_msg;
+	int rc;
+
+	get_sensor_state_field sensor_state = {
+		.sensor_op_state = PLDM_SENSOR_UNKNOWN,
+		.present_state = 0,
+		.previous_state = 0,
+		.event_state = 0
+	};
+
+	/* decode GetStateSensorReadings request data */
+	rc = decode_get_state_sensor_readings_req(
+				req->msg,
+				PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES,
+				&readings_req.sensor_id,
+				&readings_req.sensor_rearm,
+				&readings_req.reserved);
+	if (rc) {
+		prlog(PR_ERR, "Failed to decode GetStateSensorReadings request, rc = %d\n", rc);
+		cc_resp(req, req->hdrinf.pldm_type,
+			req->hdrinf.command, PLDM_ERROR);
+		return OPAL_INTERNAL_ERROR;
+	}
+
+	prlog(PR_DEBUG, "%s - sensor_id: %d, sensor_rearm: %x\n",
+			__func__, readings_req.sensor_id,
+			readings_req.sensor_rearm.byte);
+
+	/* send state sensor reading response */
+	response_length = sizeof(struct pldm_msg_hdr) +
+			  sizeof(struct pldm_get_state_sensor_readings_resp) +
+			  (sizeof(get_sensor_state_field) * 1);
+	response_msg = zalloc(response_length);
+
+	rc = encode_get_state_sensor_readings_resp(
+					req->hdrinf.instance,
+					PLDM_SUCCESS,
+					1, /* sensor count of 1 */
+					&sensor_state,
+					(struct pldm_msg *)response_msg);
+	if (rc != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Encode GetStateSensorReadings response Error, rc: %d\n", rc);
+		cc_resp(req, req->hdrinf.pldm_type,
+			req->hdrinf.command, PLDM_ERROR);
+		free(response_msg);
+		return OPAL_PARAMETER;
+	}
+
+	/* send PLDM message over MCTP */
+	rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg));
+	if (rc) {
+		prlog(PR_ERR, "Failed to send GetStateSensorReadings response, rc = %d\n", rc);
+		free(response_msg);
+		return OPAL_HARDWARE;
+	}
+
+	free(response_msg);
+
+	return OPAL_SUCCESS;
+}
+
+static struct pldm_cmd pldm_platform_get_state_sensor_readings = {
+	.name = "PLDM_GET_STATE_SENSOR_READINGS",
+	.pldm_cmd_id = PLDM_GET_STATE_SENSOR_READINGS,
+	.handler = platform_get_state_sensor_readings,
+};
+
 int pldm_responder_handle_request(struct pldm_rx_data *rx)
 {
 	const struct pldm_type *type;