blob: d0929d9bd6962666c9de4d0fb399ddb6b3fd8eba [file] [log] [blame]
Sampa Misra0db1dfa2019-03-19 00:15:31 -05001#include <endian.h>
2#include <string.h>
3
4#include "platform.h"
5
6int encode_set_state_effecter_states_resp(uint8_t instance_id,
7 uint8_t completion_code,
8 struct pldm_msg *msg)
9{
10 struct pldm_header_info header = {0};
11 int rc = PLDM_SUCCESS;
12
vkaverapa6575b82019-04-03 05:33:52 -050013 msg->payload[0] = completion_code;
Sampa Misra0db1dfa2019-03-19 00:15:31 -050014
15 header.msg_type = PLDM_RESPONSE;
16 header.instance = instance_id;
17 header.pldm_type = PLDM_PLATFORM;
18 header.command = PLDM_SET_STATE_EFFECTER_STATES;
19
20 rc = pack_pldm_header(&header, &(msg->hdr));
21
22 return rc;
23}
24
vkaverap98a2c192019-04-03 05:33:52 -050025int encode_set_state_effecter_states_req(uint8_t instance_id,
26 uint16_t effecter_id,
27 uint8_t comp_effecter_count,
28 set_effecter_state_field *field,
29 struct pldm_msg *msg)
30{
31 struct pldm_header_info header = {0};
32 int rc = PLDM_SUCCESS;
33
34 header.msg_type = PLDM_REQUEST;
35 header.instance = instance_id;
36 header.pldm_type = PLDM_PLATFORM;
37 header.command = PLDM_SET_STATE_EFFECTER_STATES;
38
39 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
40 return rc;
41 }
42
43 if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8) {
44 return PLDM_ERROR_INVALID_DATA;
45 }
46
Priyanga7257fdf2019-06-10 01:59:45 -050047 struct pldm_set_state_effecter_states_req *request =
48 (struct pldm_set_state_effecter_states_req *)msg->payload;
vkaverap98a2c192019-04-03 05:33:52 -050049 effecter_id = htole16(effecter_id);
Priyanga7257fdf2019-06-10 01:59:45 -050050 request->effecter_id = effecter_id;
51 request->comp_effecter_count = comp_effecter_count;
52 memcpy(request->field, field,
vkaverap98a2c192019-04-03 05:33:52 -050053 (sizeof(set_effecter_state_field) * comp_effecter_count));
54
55 return PLDM_SUCCESS;
56}
57
vkaverapa6575b82019-04-03 05:33:52 -050058int decode_set_state_effecter_states_resp(const uint8_t *msg,
59 size_t payload_length,
vkaverap98a2c192019-04-03 05:33:52 -050060 uint8_t *completion_code)
61{
62 if (msg == NULL || completion_code == NULL) {
63 return PLDM_ERROR_INVALID_DATA;
64 }
65
vkaverapa6575b82019-04-03 05:33:52 -050066 if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) {
67 return PLDM_ERROR_INVALID_LENGTH;
68 }
69
70 *completion_code = msg[0];
vkaverap98a2c192019-04-03 05:33:52 -050071
72 return PLDM_SUCCESS;
73}
74
vkaverapa6575b82019-04-03 05:33:52 -050075int decode_set_state_effecter_states_req(const uint8_t *msg,
76 size_t payload_length,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050077 uint16_t *effecter_id,
78 uint8_t *comp_effecter_count,
79 set_effecter_state_field *field)
80{
81 if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL ||
82 field == NULL) {
83 return PLDM_ERROR_INVALID_DATA;
84 }
vkaverapa6575b82019-04-03 05:33:52 -050085
86 if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) {
87 return PLDM_ERROR_INVALID_LENGTH;
88 }
89
Priyanga7257fdf2019-06-10 01:59:45 -050090 struct pldm_set_state_effecter_states_req *request =
91 (struct pldm_set_state_effecter_states_req *)msg;
92
93 *effecter_id = le16toh(request->effecter_id);
94 *comp_effecter_count = request->comp_effecter_count;
95 memcpy(field, request->field,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050096 (sizeof(set_effecter_state_field) * (*comp_effecter_count)));
97
98 return PLDM_SUCCESS;
99}