dsp: platform: Add sensor enable responder
Add responder definitions and decode routines for
SetStateSensorEnables and SetNumericSensorEnable
Change-Id: Ic93da95f6b3cda4a99951943ebba1b1e20b95d79
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 693727e..297a033 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -2504,6 +2504,101 @@
}
LIBPLDM_ABI_TESTING
+int decode_set_numeric_sensor_enable_req(
+ const struct pldm_msg *msg, size_t payload_length,
+ struct pldm_set_numeric_sensor_enable_req *req)
+{
+ PLDM_MSGBUF_DEFINE_P(buf);
+ uint8_t event_enable = 0;
+ uint8_t op_state = 0;
+ int rc;
+
+ if (msg == NULL || req == NULL) {
+ return -EINVAL;
+ }
+
+ rc = pldm_msgbuf_init_errno(buf, 0, msg->payload, payload_length);
+ if (rc) {
+ return rc;
+ }
+
+ pldm_msgbuf_extract(buf, req->sensor_id);
+ pldm_msgbuf_extract(buf, op_state);
+ pldm_msgbuf_extract(buf, event_enable);
+
+ rc = pldm_msgbuf_complete_consumed(buf);
+ if (rc) {
+ return rc;
+ }
+
+ if (op_state > PLDM_SET_SENSOR_UNAVAILABLE) {
+ return -EPROTO;
+ }
+
+ if (event_enable > PLDM_STATE_EVENTS_ONLY_ENABLED) {
+ return -EPROTO;
+ }
+
+ req->op_state = op_state;
+ req->event_enable = event_enable;
+
+ return 0;
+}
+
+LIBPLDM_ABI_TESTING
+int decode_set_state_sensor_enables_req(
+ const struct pldm_msg *msg, size_t payload_length,
+ struct pldm_set_state_sensor_enables_req *req)
+{
+ PLDM_MSGBUF_DEFINE_P(buf);
+ int rc;
+
+ if (msg == NULL || req == NULL) {
+ return -EINVAL;
+ }
+
+ rc = pldm_msgbuf_init_errno(buf, 3, msg->payload, payload_length);
+ if (rc) {
+ return rc;
+ }
+
+ pldm_msgbuf_extract(buf, req->sensor_id);
+ rc = pldm_msgbuf_extract(buf, req->field_count);
+ if (rc) {
+ return rc;
+ }
+
+ if (req->field_count < 1 ||
+ req->field_count > PLDM_SET_STATE_SENSOR_ENABLES_MAX_COUNT) {
+ return -EPROTO;
+ }
+
+ for (uint8_t i = 0; i < req->field_count; i++) {
+ uint8_t event_enable_val = 0;
+ uint8_t op_state_val = 0;
+
+ pldm_msgbuf_extract(buf, op_state_val);
+ rc = pldm_msgbuf_extract(buf, event_enable_val);
+ if (rc) {
+ return pldm_msgbuf_discard(buf, rc);
+ }
+
+ if (op_state_val > PLDM_SET_SENSOR_UNAVAILABLE) {
+ return pldm_msgbuf_discard(buf, -EPROTO);
+ }
+
+ if (event_enable_val > PLDM_STATE_EVENTS_ONLY_ENABLED) {
+ return pldm_msgbuf_discard(buf, -EPROTO);
+ }
+
+ req->fields[i].op_state = op_state_val;
+ req->fields[i].event_enable = event_enable_val;
+ }
+
+ return pldm_msgbuf_complete_consumed(buf);
+}
+
+LIBPLDM_ABI_TESTING
int encode_get_event_receiver_req(uint8_t instance_id, struct pldm_msg *msg,
size_t payload_length LIBPLDM_CC_UNUSED)
{