blob: 6fdbf064ffb6890106f6e4f80d0a33ac7cdaf18c [file] [log] [blame]
Sampa Misra0db1dfa2019-03-19 00:15:31 -05001#ifndef PLATFORM_H
2#define PLATFORM_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include "base.h"
12
13/* Maximum size for request */
14#define PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES 19
15/* Response lengths are inclusive of completion code */
16#define PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES 1
17
Sampa Misra7fcfb662019-05-08 13:13:53 -050018#define PLDM_GET_PDR_REQ_BYTES 13
19/* Minimum response length */
20#define PLDM_GET_PDR_MIN_RESP_BYTES 12
21
Sampa Misra0db1dfa2019-03-19 00:15:31 -050022enum set_request { PLDM_NO_CHANGE = 0x00, PLDM_REQUEST_SET = 0x01 };
23
24enum effecter_state { PLDM_INVALID_VALUE = 0xFF };
25
26enum pldm_platform_commands {
27 PLDM_SET_STATE_EFFECTER_STATES = 0x39,
Sampa Misra7fcfb662019-05-08 13:13:53 -050028 PLDM_GET_PDR = 0x51,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050029};
30
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050031/** @brief PLDM PDR types
32 */
33enum pldm_pdr_types {
34 PLDM_STATE_EFFECTER_PDR = 11,
35};
36
37/** @brief PLDM effecter initialization schemes
38 */
39enum pldm_effecter_init {
40 PLDM_NO_INIT,
41 PLDM_USE_INIT_PDR,
42 PLDM_ENABLE_EFFECTER,
43 PLDM_DISABLE_EFECTER
44};
45
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053046/** @brief PLDM Platform M&C completion codes
47 */
48enum pldm_platform_completion_codes {
Sampa Misraa2fa0702019-05-31 01:28:55 -050049 PLDM_PLATFORM_INVALID_EFFECTER_ID = 0x80,
50 PLDM_PLATFORM_INVALID_STATE_VALUE = 0x81,
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053051 PLDM_PLATFORM_INVALID_RECORD_HANDLE = 0x82,
Sampa Misraa2fa0702019-05-31 01:28:55 -050052 PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE = 0x82,
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053053};
54
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050055/** @struct pldm_pdr_hdr
56 *
57 * Structure representing PLDM common PDR header
58 */
59struct pldm_pdr_hdr {
60 uint32_t record_handle;
61 uint8_t version;
62 uint8_t type;
63 uint16_t record_change_num;
64 uint16_t length;
65} __attribute__((packed));
66
67/** @struct pldm_state_effecter_pdr
68 *
69 * Structure representing PLDM state effecter PDR
70 */
71struct pldm_state_effecter_pdr {
72 struct pldm_pdr_hdr hdr;
73 uint16_t terminus_handle;
74 uint16_t effecter_id;
75 uint16_t entity_type;
76 uint16_t entity_instance;
77 uint16_t container_id;
78 uint16_t effecter_semantic_id;
79 uint8_t effecter_init;
80 bool8_t has_description_pdr;
81 uint8_t composite_effecter_count;
82 uint8_t possible_states[1];
83} __attribute__((packed));
84
85/** @struct state_effecter_possible_states
86 *
87 * Structure representing state enums for state effecter
88 */
89struct state_effecter_possible_states {
90 uint16_t state_set_id;
91 uint8_t possible_states_size;
92 bitfield8_t states[1];
93} __attribute__((packed));
94
Sampa Misra0db1dfa2019-03-19 00:15:31 -050095/** @struct set_effecter_state_field
96 *
97 * Structure representing a stateField in SetStateEffecterStates command */
98
99typedef struct state_field_for_state_effecter_set {
100 uint8_t set_request; //!< Whether to change the state
101 uint8_t effecter_state; //!< Expected state of the effecter
102} __attribute__((packed)) set_effecter_state_field;
103
Priyanga7257fdf2019-06-10 01:59:45 -0500104/** @struct PLDM_SetStateEffecterStates_Request
105 *
106 * Structure representing PLDM set state effecter states request.
107 */
108struct pldm_set_state_effecter_states_req {
109 uint16_t effecter_id;
110 uint8_t comp_effecter_count;
111 set_effecter_state_field field[8];
112} __attribute__((packed));
113
Sampa Misra7fcfb662019-05-08 13:13:53 -0500114/** @struct pldm_get_pdr_resp
115 *
116 * structure representing GetPDR response packet
117 * transfer CRC is not part of the structure and will be
118 * added at the end of last packet in multipart transfer
119 */
120struct pldm_get_pdr_resp {
121 uint8_t completion_code;
122 uint32_t next_record_handle;
123 uint32_t next_data_transfer_handle;
124 uint8_t transfer_flag;
125 uint16_t response_count;
126 uint8_t record_data[1];
127} __attribute__((packed));
128
129/** @struct pldm_get_pdr_req
130 *
131 * structure representing GetPDR request packet
132 */
133struct pldm_get_pdr_req {
134 uint32_t record_handle;
135 uint32_t data_transfer_handle;
136 uint8_t transfer_op_flag;
137 uint16_t request_count;
138 uint16_t record_change_number;
139} __attribute__((packed));
140
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500141/* Responder */
142
143/* SetStateEffecterStates */
144
145/** @brief Create a PLDM response message for SetStateEffecterStates
146 *
147 * @param[in] instance_id - Message's instance id
148 * @param[in] completion_code - PLDM completion code
149 * @param[out] msg - Message will be written to this
150 * @return pldm_completion_codes
151 * @note Caller is responsible for memory alloc and dealloc of param
152 * 'msg.body.payload'
153 */
154
155int encode_set_state_effecter_states_resp(uint8_t instance_id,
156 uint8_t completion_code,
157 struct pldm_msg *msg);
158
159/** @brief Decode SetStateEffecterStates request data
160 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500161 * @param[in] msg - Request message
vkaverapa6575b82019-04-03 05:33:52 -0500162 * @param[in] payload_length - Length of request message payload
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500163 * @param[out] effecter_id - used to identify and access the effecter
164 * @param[out] comp_effecter_count - number of individual sets of effecter
165 * information. Upto eight sets of state effecter info can be accessed
166 * for a given effecter.
167 * @param[out] field - each unit is an instance of the stateFileld structure
168 * that is used to set the requested state for a particular effecter
169 * within the state effecter. This field holds the starting address of
170 * the stateField values. The user is responsible to allocate the
171 * memory prior to calling this command. Since the state field count is
172 * not known in advance, the user should allocate the maximum size
173 * always, which is 8 in number.
174 * @return pldm_completion_codes
175 */
vkaverapa6575b82019-04-03 05:33:52 -0500176
Zahed Hossain223a73d2019-07-04 12:46:18 -0500177int decode_set_state_effecter_states_req(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -0500178 size_t payload_length,
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500179 uint16_t *effecter_id,
180 uint8_t *comp_effecter_count,
181 set_effecter_state_field *field);
182
Sampa Misra7fcfb662019-05-08 13:13:53 -0500183/* GetPDR */
184
185/** @brief Create a PLDM response message for GetPDR
186 *
187 * @param[in] instance_id - Message's instance id
188 * @param[in] completion_code - PLDM completion code
189 * @param[in] next_record_hndl - The recordHandle for the PDR that is next in
190 * the PDR Repository
191 * @param[in] next_data_transfer_hndl - A handle that identifies the next
192 * portion of the PDR data to be transferred, if any
193 * @param[in] transfer_flag - Indicates the portion of PDR data being
194 * transferred
195 * @param[in] resp_cnt - The number of recordData bytes returned in this
196 * response
197 * @param[in] record_data - PDR data bytes of length resp_cnt
198 * @param[in] transfer_crc - A CRC-8 for the overall PDR. This is present only
199 * in the last part of a PDR being transferred
200 * @param[out] msg - Message will be written to this
201 * @return pldm_completion_codes
202 * @note Caller is responsible for memory alloc and dealloc of param
203 * 'msg.payload'
204 */
205int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code,
206 uint32_t next_record_hndl,
207 uint32_t next_data_transfer_hndl, uint8_t transfer_flag,
208 uint16_t resp_cnt, const uint8_t *record_data,
209 uint8_t transfer_crc, struct pldm_msg *msg);
210
211/** @brief Decode GetPDR request data
212 *
213 * @param[in] msg - Request message
214 * @param[in] payload_length - Length of request message payload
215 * @param[out] record_hndl - The recordHandle value for the PDR to be retrieved
216 * @param[out] data_transfer_hndl - Handle used to identify a particular
217 * multipart PDR data transfer operation
218 * @param[out] transfer_op_flag - Flag to indicate the first or subsequent
219 * portion of transfer
220 * @param[out] request_cnt - The maximum number of record bytes requested
221 * @param[out] record_chg_num - Used to determine whether the PDR has changed
222 * while PDR transfer is going on
223 * @return pldm_completion_codes
224 */
225
226int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length,
227 uint32_t *record_hndl, uint32_t *data_transfer_hndl,
228 uint8_t *transfer_op_flag, uint16_t *request_cnt,
229 uint16_t *record_chg_num);
230
231/* Requester */
232
233/* SetStateEffecterStates */
234
vkaverap98a2c192019-04-03 05:33:52 -0500235/** @brief Create a PLDM request message for SetStateEffecterStates
236 *
237 * @param[in] instance_id - Message's instance id
238 * @param[in] effecter_id - used to identify and access the effecter
239 * @param[in] comp_effecter_count - number of individual sets of effecter
240 * information. Upto eight sets of state effecter info can be accessed
241 * for a given effecter.
242 * @param[in] field - each unit is an instance of the stateField structure
243 * that is used to set the requested state for a particular effecter
244 * within the state effecter. This field holds the starting address of
245 * the stateField values. The user is responsible to allocate the
246 * memory prior to calling this command. The user has to allocate the
247 * field parameter as sizeof(set_effecter_state_field) *
248 * comp_effecter_count
249 * @param[out] msg - Message will be written to this
250 * @return pldm_completion_codes
251 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500252 * 'msg.payload'
vkaverap98a2c192019-04-03 05:33:52 -0500253 */
254
255int encode_set_state_effecter_states_req(uint8_t instance_id,
256 uint16_t effecter_id,
257 uint8_t comp_effecter_count,
258 set_effecter_state_field *field,
259 struct pldm_msg *msg);
260
261/** @brief Decode SetStateEffecterStates response data
Zahed Hossain223a73d2019-07-04 12:46:18 -0500262 * @param[in] msg - Request message
vkaverapa6575b82019-04-03 05:33:52 -0500263 * @param[in] payload_length - Length of response message payload
vkaverap98a2c192019-04-03 05:33:52 -0500264 * @param[out] completion_code - PLDM completion code
265 * @return pldm_completion_codes
266 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500267int decode_set_state_effecter_states_resp(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -0500268 size_t payload_length,
vkaverap98a2c192019-04-03 05:33:52 -0500269 uint8_t *completion_code);
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500270#ifdef __cplusplus
271}
272#endif
273
274#endif /* PLATFORM_H */