diff mbox series

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

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

Commit Message

Christophe Lombard April 29, 2022, 9:47 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 | 80 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

Comments

Frederic Barrat April 26, 2023, 1:24 p.m. UTC | #1
On 29/04/2022 11:47, Christophe Lombard wrote:
> 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 | 80 ++++++++++++++++++++++++++++++++++++++
>   1 file changed, 80 insertions(+)
> 
> diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
> index 5eb0c3f3..e44bb509 100644
> --- a/core/pldm/pldm-responder.c
> +++ b/core/pldm/pldm-responder.c
> @@ -568,6 +568,85 @@ 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);
> +		pldm_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 = malloc(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);
> +		pldm_cc_resp(req, req->hdrinf.pldm_type,
> +			     req->hdrinf.command, PLDM_ERROR);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	/* send PLDM message over MCTP */
> +	rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg));
> +	if (rc) {
> +		prlog(PR_ERR, "Failed to send GetStateSensorReadings response, rc = %d\n", rc);
> +		return OPAL_HARDWARE;
> +	}
> +
> +	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_rx_handle_request(struct pldm_rx_data *rx)
>   {
>   	const struct pldm_type *t;
> @@ -612,6 +691,7 @@ int pldm_mctp_responder_init(void)
>   	pldm_add_type(&pldm_platform_type);
>   	pldm_add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver);
>   	pldm_add_cmd(&pldm_platform_type, &pldm_platform_event_message);
> +	pldm_add_cmd(&pldm_platform_type, &pldm_platform_get_state_sensor_readings);



The code in the updated patch I'm reviewing has been modified and the 
above line is now missing. It is now included by mistake in the next patch.

   Fred


>   
>   	return OPAL_SUCCESS;
>   }
diff mbox series

Patch

diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
index 5eb0c3f3..e44bb509 100644
--- a/core/pldm/pldm-responder.c
+++ b/core/pldm/pldm-responder.c
@@ -568,6 +568,85 @@  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);
+		pldm_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 = malloc(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);
+		pldm_cc_resp(req, req->hdrinf.pldm_type,
+			     req->hdrinf.command, PLDM_ERROR);
+		return OPAL_PARAMETER;
+	}
+
+	/* send PLDM message over MCTP */
+	rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg));
+	if (rc) {
+		prlog(PR_ERR, "Failed to send GetStateSensorReadings response, rc = %d\n", rc);
+		return OPAL_HARDWARE;
+	}
+
+	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_rx_handle_request(struct pldm_rx_data *rx)
 {
 	const struct pldm_type *t;
@@ -612,6 +691,7 @@  int pldm_mctp_responder_init(void)
 	pldm_add_type(&pldm_platform_type);
 	pldm_add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver);
 	pldm_add_cmd(&pldm_platform_type, &pldm_platform_event_message);
+	pldm_add_cmd(&pldm_platform_type, &pldm_platform_get_state_sensor_readings);
 
 	return OPAL_SUCCESS;
 }