blob: 0cce1b4c2afaeaa60f3cde55fe7df540aa1b3e56 [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
George Liu30b859f2020-01-07 15:03:22 +080018#define PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES 1
19#define PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES 4
20
Sampa Misra7fcfb662019-05-08 13:13:53 -050021#define PLDM_GET_PDR_REQ_BYTES 13
22/* Minimum response length */
23#define PLDM_GET_PDR_MIN_RESP_BYTES 12
24
George Liu30b859f2020-01-07 15:03:22 +080025enum pldm_effecter_data_size {
26 PLDM_EFFECTER_DATA_SIZE_UINT8,
27 PLDM_EFFECTER_DATA_SIZE_SINT8,
28 PLDM_EFFECTER_DATA_SIZE_UINT16,
29 PLDM_EFFECTER_DATA_SIZE_SINT16,
30 PLDM_EFFECTER_DATA_SIZE_UINT32,
31 PLDM_EFFECTER_DATA_SIZE_SINT32
32};
33
Sampa Misra0db1dfa2019-03-19 00:15:31 -050034enum set_request { PLDM_NO_CHANGE = 0x00, PLDM_REQUEST_SET = 0x01 };
35
36enum effecter_state { PLDM_INVALID_VALUE = 0xFF };
37
38enum pldm_platform_commands {
George Liu30b859f2020-01-07 15:03:22 +080039 PLDM_SET_NUMERIC_EFFECTER_VALUE = 0x31,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050040 PLDM_SET_STATE_EFFECTER_STATES = 0x39,
Sampa Misra7fcfb662019-05-08 13:13:53 -050041 PLDM_GET_PDR = 0x51,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050042};
43
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050044/** @brief PLDM PDR types
45 */
46enum pldm_pdr_types {
47 PLDM_STATE_EFFECTER_PDR = 11,
Deepak Kodihallidb914672020-02-07 02:47:45 -060048 PLDM_PDR_FRU_RECORD_SET = 20,
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050049};
50
51/** @brief PLDM effecter initialization schemes
52 */
53enum pldm_effecter_init {
54 PLDM_NO_INIT,
55 PLDM_USE_INIT_PDR,
56 PLDM_ENABLE_EFFECTER,
57 PLDM_DISABLE_EFECTER
58};
59
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053060/** @brief PLDM Platform M&C completion codes
61 */
62enum pldm_platform_completion_codes {
Sampa Misraa2fa0702019-05-31 01:28:55 -050063 PLDM_PLATFORM_INVALID_EFFECTER_ID = 0x80,
64 PLDM_PLATFORM_INVALID_STATE_VALUE = 0x81,
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053065 PLDM_PLATFORM_INVALID_RECORD_HANDLE = 0x82,
Sampa Misraa2fa0702019-05-31 01:28:55 -050066 PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE = 0x82,
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053067};
68
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050069/** @struct pldm_pdr_hdr
70 *
71 * Structure representing PLDM common PDR header
72 */
73struct pldm_pdr_hdr {
74 uint32_t record_handle;
75 uint8_t version;
76 uint8_t type;
77 uint16_t record_change_num;
78 uint16_t length;
79} __attribute__((packed));
80
Deepak Kodihallidb914672020-02-07 02:47:45 -060081/** @struct pldm_pdr_fru_record_set
82 *
83 * Structure representing PLDM FRU record set PDR
84 */
85struct pldm_pdr_fru_record_set {
86 uint16_t terminus_handle;
87 uint16_t fru_rsi;
88 uint16_t entity_type;
89 uint16_t entity_instance_num;
90 uint16_t container_id;
91} __attribute__((packed));
92
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050093/** @struct pldm_state_effecter_pdr
94 *
95 * Structure representing PLDM state effecter PDR
96 */
97struct pldm_state_effecter_pdr {
98 struct pldm_pdr_hdr hdr;
99 uint16_t terminus_handle;
100 uint16_t effecter_id;
101 uint16_t entity_type;
102 uint16_t entity_instance;
103 uint16_t container_id;
104 uint16_t effecter_semantic_id;
105 uint8_t effecter_init;
106 bool8_t has_description_pdr;
107 uint8_t composite_effecter_count;
108 uint8_t possible_states[1];
109} __attribute__((packed));
110
111/** @struct state_effecter_possible_states
112 *
113 * Structure representing state enums for state effecter
114 */
115struct state_effecter_possible_states {
116 uint16_t state_set_id;
117 uint8_t possible_states_size;
118 bitfield8_t states[1];
119} __attribute__((packed));
120
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500121/** @struct set_effecter_state_field
122 *
123 * Structure representing a stateField in SetStateEffecterStates command */
124
125typedef struct state_field_for_state_effecter_set {
126 uint8_t set_request; //!< Whether to change the state
127 uint8_t effecter_state; //!< Expected state of the effecter
128} __attribute__((packed)) set_effecter_state_field;
129
Priyanga7257fdf2019-06-10 01:59:45 -0500130/** @struct PLDM_SetStateEffecterStates_Request
131 *
132 * Structure representing PLDM set state effecter states request.
133 */
134struct pldm_set_state_effecter_states_req {
135 uint16_t effecter_id;
136 uint8_t comp_effecter_count;
137 set_effecter_state_field field[8];
138} __attribute__((packed));
139
Sampa Misra7fcfb662019-05-08 13:13:53 -0500140/** @struct pldm_get_pdr_resp
141 *
142 * structure representing GetPDR response packet
143 * transfer CRC is not part of the structure and will be
144 * added at the end of last packet in multipart transfer
145 */
146struct pldm_get_pdr_resp {
147 uint8_t completion_code;
148 uint32_t next_record_handle;
149 uint32_t next_data_transfer_handle;
150 uint8_t transfer_flag;
151 uint16_t response_count;
152 uint8_t record_data[1];
153} __attribute__((packed));
154
155/** @struct pldm_get_pdr_req
156 *
157 * structure representing GetPDR request packet
158 */
159struct pldm_get_pdr_req {
160 uint32_t record_handle;
161 uint32_t data_transfer_handle;
162 uint8_t transfer_op_flag;
163 uint16_t request_count;
164 uint16_t record_change_number;
165} __attribute__((packed));
166
George Liu30b859f2020-01-07 15:03:22 +0800167/** @struct pldm_set_numeric_effecter_value_req
168 *
169 * structure representing SetNumericEffecterValue request packet
170 */
171struct pldm_set_numeric_effecter_value_req {
172 uint16_t effecter_id;
173 uint8_t effecter_data_size;
174 uint8_t effecter_value[1];
175} __attribute__((packed));
176
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500177/* Responder */
178
George Liu30b859f2020-01-07 15:03:22 +0800179/* SetNumericEffecterValue */
180
181/** @brief Decode SetNumericEffecterValue request data
182 *
183 * @param[in] msg - Request message
184 * @param[in] payload_length - Length of request message payload
185 * @param[out] effecter_id - used to identify and access the effecter
186 * @param[out] effecter_data_size - The bit width and format of the setting
187 * value for the effecter.
188 * value:{uint8,sint8,uint16,sint16,uint32,sint32}
189 * @param[out] effecter_value - The setting value of numeric effecter being
190 * requested.
191 * @return pldm_completion_codes
192 */
193int decode_set_numeric_effecter_value_req(const struct pldm_msg *msg,
194 size_t payload_length,
195 uint16_t *effecter_id,
196 uint8_t *effecter_data_size,
197 uint8_t *effecter_value);
198
199/** @brief Create a PLDM response message for SetNumericEffecterValue
200 *
201 * @param[in] instance_id - Message's instance id
202 * @param[in] completion_code - PLDM completion code
203 * @param[out] msg - Message will be written to this
204 * @param[in] payload_length - Length of request message payload
205 * @return pldm_completion_codes
206 * @note Caller is responsible for memory alloc and dealloc of param
207 * 'msg.body.payload'
208 */
209int encode_set_numeric_effecter_value_resp(uint8_t instance_id,
210 uint8_t completion_code,
211 struct pldm_msg *msg,
212 size_t payload_length);
213
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500214/* SetStateEffecterStates */
215
216/** @brief Create a PLDM response message for SetStateEffecterStates
217 *
218 * @param[in] instance_id - Message's instance id
219 * @param[in] completion_code - PLDM completion code
220 * @param[out] msg - Message will be written to this
221 * @return pldm_completion_codes
222 * @note Caller is responsible for memory alloc and dealloc of param
223 * 'msg.body.payload'
224 */
225
226int encode_set_state_effecter_states_resp(uint8_t instance_id,
227 uint8_t completion_code,
228 struct pldm_msg *msg);
229
230/** @brief Decode SetStateEffecterStates request data
231 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500232 * @param[in] msg - Request message
vkaverapa6575b82019-04-03 05:33:52 -0500233 * @param[in] payload_length - Length of request message payload
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500234 * @param[out] effecter_id - used to identify and access the effecter
235 * @param[out] comp_effecter_count - number of individual sets of effecter
236 * information. Upto eight sets of state effecter info can be accessed
237 * for a given effecter.
238 * @param[out] field - each unit is an instance of the stateFileld structure
239 * that is used to set the requested state for a particular effecter
240 * within the state effecter. This field holds the starting address of
241 * the stateField values. The user is responsible to allocate the
242 * memory prior to calling this command. Since the state field count is
243 * not known in advance, the user should allocate the maximum size
244 * always, which is 8 in number.
245 * @return pldm_completion_codes
246 */
vkaverapa6575b82019-04-03 05:33:52 -0500247
Zahed Hossain223a73d2019-07-04 12:46:18 -0500248int decode_set_state_effecter_states_req(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -0500249 size_t payload_length,
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500250 uint16_t *effecter_id,
251 uint8_t *comp_effecter_count,
252 set_effecter_state_field *field);
253
Sampa Misra7fcfb662019-05-08 13:13:53 -0500254/* GetPDR */
255
256/** @brief Create a PLDM response message for GetPDR
257 *
258 * @param[in] instance_id - Message's instance id
259 * @param[in] completion_code - PLDM completion code
260 * @param[in] next_record_hndl - The recordHandle for the PDR that is next in
261 * the PDR Repository
262 * @param[in] next_data_transfer_hndl - A handle that identifies the next
263 * portion of the PDR data to be transferred, if any
264 * @param[in] transfer_flag - Indicates the portion of PDR data being
265 * transferred
266 * @param[in] resp_cnt - The number of recordData bytes returned in this
267 * response
268 * @param[in] record_data - PDR data bytes of length resp_cnt
269 * @param[in] transfer_crc - A CRC-8 for the overall PDR. This is present only
270 * in the last part of a PDR being transferred
271 * @param[out] msg - Message will be written to this
272 * @return pldm_completion_codes
273 * @note Caller is responsible for memory alloc and dealloc of param
274 * 'msg.payload'
275 */
276int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code,
277 uint32_t next_record_hndl,
278 uint32_t next_data_transfer_hndl, uint8_t transfer_flag,
279 uint16_t resp_cnt, const uint8_t *record_data,
280 uint8_t transfer_crc, struct pldm_msg *msg);
281
282/** @brief Decode GetPDR request data
283 *
284 * @param[in] msg - Request message
285 * @param[in] payload_length - Length of request message payload
286 * @param[out] record_hndl - The recordHandle value for the PDR to be retrieved
287 * @param[out] data_transfer_hndl - Handle used to identify a particular
288 * multipart PDR data transfer operation
289 * @param[out] transfer_op_flag - Flag to indicate the first or subsequent
290 * portion of transfer
291 * @param[out] request_cnt - The maximum number of record bytes requested
292 * @param[out] record_chg_num - Used to determine whether the PDR has changed
293 * while PDR transfer is going on
294 * @return pldm_completion_codes
295 */
296
297int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length,
298 uint32_t *record_hndl, uint32_t *data_transfer_hndl,
299 uint8_t *transfer_op_flag, uint16_t *request_cnt,
300 uint16_t *record_chg_num);
301
302/* Requester */
303
George Liu820a9a52019-11-26 14:43:59 +0800304/* GetPDR */
305
306/** @brief Create a PLDM request message for GetPDR
307 *
308 * @param[in] instance_id - Message's instance id
309 * @param[in] record_hndl - The recordHandle value for the PDR to be retrieved
310 * @param[in] data_transfer_hndl - Handle used to identify a particular
311 * multipart PDR data transfer operation
312 * @param[in] transfer_op_flag - Flag to indicate the first or subsequent
313 * portion of transfer
314 * @param[in] request_cnt - The maximum number of record bytes requested
315 * @param[in] record_chg_num - Used to determine whether the PDR has changed
316 * while PDR transfer is going on
317 * @param[out] msg - Message will be written to this
318 * @param[in] payload_length - Length of request message payload
319 * @return pldm_completion_codes
320 * @note Caller is responsible for memory alloc and dealloc of param
321 * 'msg.payload'
322 */
323int encode_get_pdr_req(uint8_t instance_id, uint32_t record_hndl,
324 uint32_t data_transfer_hndl, uint8_t transfer_op_flag,
325 uint16_t request_cnt, uint16_t record_chg_num,
326 struct pldm_msg *msg, size_t payload_length);
327
328/** @brief Decode GetPDR response data
329 *
George Liu684a7162019-12-06 15:10:52 +0800330 * Note:
331 * * If the return value is not PLDM_SUCCESS, it represents a
332 * transport layer error.
333 * * If the completion_code value is not PLDM_SUCCESS, it represents a
334 * protocol layer error and all the out-parameters are invalid.
335 *
George Liu820a9a52019-11-26 14:43:59 +0800336 * @param[in] msg - Request message
337 * @param[in] payload_length - Length of request message payload
338 * @param[out] completion_code - PLDM completion code
339 * @param[out] next_record_hndl - The recordHandle for the PDR that is next in
340 * the PDR Repository
341 * @param[out] next_data_transfer_hndl - A handle that identifies the next
342 * portion of the PDR data to be transferred, if any
343 * @param[out] transfer_flag - Indicates the portion of PDR data being
344 * transferred
345 * @param[out] resp_cnt - The number of recordData bytes returned in this
346 * response
347 * @param[out] record_data - PDR data bytes of length resp_cnt
348 * @param[in] record_data_length - Length of record_data
349 * @param[out] transfer_crc - A CRC-8 for the overall PDR. This is present only
350 * in the last part of a PDR being transferred
351 * @return pldm_completion_codes
352 */
353int decode_get_pdr_resp(const struct pldm_msg *msg, size_t payload_length,
354 uint8_t *completion_code, uint32_t *next_record_hndl,
355 uint32_t *next_data_transfer_hndl,
356 uint8_t *transfer_flag, uint16_t *resp_cnt,
357 uint8_t *record_data, size_t record_data_length,
358 uint8_t *transfer_crc);
359
Sampa Misra7fcfb662019-05-08 13:13:53 -0500360/* SetStateEffecterStates */
361
vkaverap98a2c192019-04-03 05:33:52 -0500362/** @brief Create a PLDM request message for SetStateEffecterStates
363 *
364 * @param[in] instance_id - Message's instance id
365 * @param[in] effecter_id - used to identify and access the effecter
366 * @param[in] comp_effecter_count - number of individual sets of effecter
367 * information. Upto eight sets of state effecter info can be accessed
368 * for a given effecter.
369 * @param[in] field - each unit is an instance of the stateField structure
370 * that is used to set the requested state for a particular effecter
371 * within the state effecter. This field holds the starting address of
372 * the stateField values. The user is responsible to allocate the
373 * memory prior to calling this command. The user has to allocate the
374 * field parameter as sizeof(set_effecter_state_field) *
375 * comp_effecter_count
376 * @param[out] msg - Message will be written to this
377 * @return pldm_completion_codes
378 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500379 * 'msg.payload'
vkaverap98a2c192019-04-03 05:33:52 -0500380 */
381
382int encode_set_state_effecter_states_req(uint8_t instance_id,
383 uint16_t effecter_id,
384 uint8_t comp_effecter_count,
385 set_effecter_state_field *field,
386 struct pldm_msg *msg);
387
388/** @brief Decode SetStateEffecterStates response data
George Liu684a7162019-12-06 15:10:52 +0800389 *
390 * Note:
391 * * If the return value is not PLDM_SUCCESS, it represents a
392 * transport layer error.
393 * * If the completion_code value is not PLDM_SUCCESS, it represents a
394 * protocol layer error and all the out-parameters are invalid.
395 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500396 * @param[in] msg - Request message
vkaverapa6575b82019-04-03 05:33:52 -0500397 * @param[in] payload_length - Length of response message payload
vkaverap98a2c192019-04-03 05:33:52 -0500398 * @param[out] completion_code - PLDM completion code
399 * @return pldm_completion_codes
400 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500401int decode_set_state_effecter_states_resp(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -0500402 size_t payload_length,
vkaverap98a2c192019-04-03 05:33:52 -0500403 uint8_t *completion_code);
George Liu30b859f2020-01-07 15:03:22 +0800404
405/* SetNumericEffecterValue */
406
407/** @brief Create a PLDM request message for SetNumericEffecterValue
408 *
409 * @param[in] instance_id - Message's instance id
410 * @param[in] effecter_id - used to identify and access the effecter
411 * @param[in] effecter_data_size - The bit width and format of the setting
412 * value for the effecter.
413 * value:{uint8,sint8,uint16,sint16,uint32,sint32}
414 * @param[in] effecter_value - The setting value of numeric effecter being
415 * requested.
416 * @param[in] payload_length - Length of request message payload
417 * @param[out] msg - Message will be written to this
418 * @return pldm_completion_codes
419 * @note Caller is responsible for memory alloc and dealloc of param
420 * 'msg.payload'
421 */
422int encode_set_numeric_effecter_value_req(
423 uint8_t instance_id, uint16_t effecter_id, uint8_t effecter_data_size,
424 uint8_t *effecter_value, struct pldm_msg *msg, size_t payload_length);
425
426/** @brief Decode SetNumericEffecterValue response data
427 * @param[in] msg - Request message
428 * @param[in] payload_length - Length of response message payload
429 * @param[out] completion_code - PLDM completion code
430 * @return pldm_completion_codes
431 */
432int decode_set_numeric_effecter_value_resp(const struct pldm_msg *msg,
433 size_t payload_length,
434 uint8_t *completion_code);
435
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500436#ifdef __cplusplus
437}
438#endif
439
440#endif /* PLATFORM_H */