blob: 5341f6fa09f3d3540ab9903085ad1379708f924f [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,
48};
49
50/** @brief PLDM effecter initialization schemes
51 */
52enum pldm_effecter_init {
53 PLDM_NO_INIT,
54 PLDM_USE_INIT_PDR,
55 PLDM_ENABLE_EFFECTER,
56 PLDM_DISABLE_EFECTER
57};
58
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053059/** @brief PLDM Platform M&C completion codes
60 */
61enum pldm_platform_completion_codes {
Sampa Misraa2fa0702019-05-31 01:28:55 -050062 PLDM_PLATFORM_INVALID_EFFECTER_ID = 0x80,
63 PLDM_PLATFORM_INVALID_STATE_VALUE = 0x81,
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053064 PLDM_PLATFORM_INVALID_RECORD_HANDLE = 0x82,
Sampa Misraa2fa0702019-05-31 01:28:55 -050065 PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE = 0x82,
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053066};
67
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050068/** @struct pldm_pdr_hdr
69 *
70 * Structure representing PLDM common PDR header
71 */
72struct pldm_pdr_hdr {
73 uint32_t record_handle;
74 uint8_t version;
75 uint8_t type;
76 uint16_t record_change_num;
77 uint16_t length;
78} __attribute__((packed));
79
80/** @struct pldm_state_effecter_pdr
81 *
82 * Structure representing PLDM state effecter PDR
83 */
84struct pldm_state_effecter_pdr {
85 struct pldm_pdr_hdr hdr;
86 uint16_t terminus_handle;
87 uint16_t effecter_id;
88 uint16_t entity_type;
89 uint16_t entity_instance;
90 uint16_t container_id;
91 uint16_t effecter_semantic_id;
92 uint8_t effecter_init;
93 bool8_t has_description_pdr;
94 uint8_t composite_effecter_count;
95 uint8_t possible_states[1];
96} __attribute__((packed));
97
98/** @struct state_effecter_possible_states
99 *
100 * Structure representing state enums for state effecter
101 */
102struct state_effecter_possible_states {
103 uint16_t state_set_id;
104 uint8_t possible_states_size;
105 bitfield8_t states[1];
106} __attribute__((packed));
107
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500108/** @struct set_effecter_state_field
109 *
110 * Structure representing a stateField in SetStateEffecterStates command */
111
112typedef struct state_field_for_state_effecter_set {
113 uint8_t set_request; //!< Whether to change the state
114 uint8_t effecter_state; //!< Expected state of the effecter
115} __attribute__((packed)) set_effecter_state_field;
116
Priyanga7257fdf2019-06-10 01:59:45 -0500117/** @struct PLDM_SetStateEffecterStates_Request
118 *
119 * Structure representing PLDM set state effecter states request.
120 */
121struct pldm_set_state_effecter_states_req {
122 uint16_t effecter_id;
123 uint8_t comp_effecter_count;
124 set_effecter_state_field field[8];
125} __attribute__((packed));
126
Sampa Misra7fcfb662019-05-08 13:13:53 -0500127/** @struct pldm_get_pdr_resp
128 *
129 * structure representing GetPDR response packet
130 * transfer CRC is not part of the structure and will be
131 * added at the end of last packet in multipart transfer
132 */
133struct pldm_get_pdr_resp {
134 uint8_t completion_code;
135 uint32_t next_record_handle;
136 uint32_t next_data_transfer_handle;
137 uint8_t transfer_flag;
138 uint16_t response_count;
139 uint8_t record_data[1];
140} __attribute__((packed));
141
142/** @struct pldm_get_pdr_req
143 *
144 * structure representing GetPDR request packet
145 */
146struct pldm_get_pdr_req {
147 uint32_t record_handle;
148 uint32_t data_transfer_handle;
149 uint8_t transfer_op_flag;
150 uint16_t request_count;
151 uint16_t record_change_number;
152} __attribute__((packed));
153
George Liu30b859f2020-01-07 15:03:22 +0800154/** @struct pldm_set_numeric_effecter_value_req
155 *
156 * structure representing SetNumericEffecterValue request packet
157 */
158struct pldm_set_numeric_effecter_value_req {
159 uint16_t effecter_id;
160 uint8_t effecter_data_size;
161 uint8_t effecter_value[1];
162} __attribute__((packed));
163
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500164/* Responder */
165
George Liu30b859f2020-01-07 15:03:22 +0800166/* SetNumericEffecterValue */
167
168/** @brief Decode SetNumericEffecterValue request data
169 *
170 * @param[in] msg - Request message
171 * @param[in] payload_length - Length of request message payload
172 * @param[out] effecter_id - used to identify and access the effecter
173 * @param[out] effecter_data_size - The bit width and format of the setting
174 * value for the effecter.
175 * value:{uint8,sint8,uint16,sint16,uint32,sint32}
176 * @param[out] effecter_value - The setting value of numeric effecter being
177 * requested.
178 * @return pldm_completion_codes
179 */
180int decode_set_numeric_effecter_value_req(const struct pldm_msg *msg,
181 size_t payload_length,
182 uint16_t *effecter_id,
183 uint8_t *effecter_data_size,
184 uint8_t *effecter_value);
185
186/** @brief Create a PLDM response message for SetNumericEffecterValue
187 *
188 * @param[in] instance_id - Message's instance id
189 * @param[in] completion_code - PLDM completion code
190 * @param[out] msg - Message will be written to this
191 * @param[in] payload_length - Length of request message payload
192 * @return pldm_completion_codes
193 * @note Caller is responsible for memory alloc and dealloc of param
194 * 'msg.body.payload'
195 */
196int encode_set_numeric_effecter_value_resp(uint8_t instance_id,
197 uint8_t completion_code,
198 struct pldm_msg *msg,
199 size_t payload_length);
200
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500201/* SetStateEffecterStates */
202
203/** @brief Create a PLDM response message for SetStateEffecterStates
204 *
205 * @param[in] instance_id - Message's instance id
206 * @param[in] completion_code - PLDM completion code
207 * @param[out] msg - Message will be written to this
208 * @return pldm_completion_codes
209 * @note Caller is responsible for memory alloc and dealloc of param
210 * 'msg.body.payload'
211 */
212
213int encode_set_state_effecter_states_resp(uint8_t instance_id,
214 uint8_t completion_code,
215 struct pldm_msg *msg);
216
217/** @brief Decode SetStateEffecterStates request data
218 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500219 * @param[in] msg - Request message
vkaverapa6575b82019-04-03 05:33:52 -0500220 * @param[in] payload_length - Length of request message payload
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500221 * @param[out] effecter_id - used to identify and access the effecter
222 * @param[out] comp_effecter_count - number of individual sets of effecter
223 * information. Upto eight sets of state effecter info can be accessed
224 * for a given effecter.
225 * @param[out] field - each unit is an instance of the stateFileld structure
226 * that is used to set the requested state for a particular effecter
227 * within the state effecter. This field holds the starting address of
228 * the stateField values. The user is responsible to allocate the
229 * memory prior to calling this command. Since the state field count is
230 * not known in advance, the user should allocate the maximum size
231 * always, which is 8 in number.
232 * @return pldm_completion_codes
233 */
vkaverapa6575b82019-04-03 05:33:52 -0500234
Zahed Hossain223a73d2019-07-04 12:46:18 -0500235int decode_set_state_effecter_states_req(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -0500236 size_t payload_length,
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500237 uint16_t *effecter_id,
238 uint8_t *comp_effecter_count,
239 set_effecter_state_field *field);
240
Sampa Misra7fcfb662019-05-08 13:13:53 -0500241/* GetPDR */
242
243/** @brief Create a PLDM response message for GetPDR
244 *
245 * @param[in] instance_id - Message's instance id
246 * @param[in] completion_code - PLDM completion code
247 * @param[in] next_record_hndl - The recordHandle for the PDR that is next in
248 * the PDR Repository
249 * @param[in] next_data_transfer_hndl - A handle that identifies the next
250 * portion of the PDR data to be transferred, if any
251 * @param[in] transfer_flag - Indicates the portion of PDR data being
252 * transferred
253 * @param[in] resp_cnt - The number of recordData bytes returned in this
254 * response
255 * @param[in] record_data - PDR data bytes of length resp_cnt
256 * @param[in] transfer_crc - A CRC-8 for the overall PDR. This is present only
257 * in the last part of a PDR being transferred
258 * @param[out] msg - Message will be written to this
259 * @return pldm_completion_codes
260 * @note Caller is responsible for memory alloc and dealloc of param
261 * 'msg.payload'
262 */
263int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code,
264 uint32_t next_record_hndl,
265 uint32_t next_data_transfer_hndl, uint8_t transfer_flag,
266 uint16_t resp_cnt, const uint8_t *record_data,
267 uint8_t transfer_crc, struct pldm_msg *msg);
268
269/** @brief Decode GetPDR request data
270 *
271 * @param[in] msg - Request message
272 * @param[in] payload_length - Length of request message payload
273 * @param[out] record_hndl - The recordHandle value for the PDR to be retrieved
274 * @param[out] data_transfer_hndl - Handle used to identify a particular
275 * multipart PDR data transfer operation
276 * @param[out] transfer_op_flag - Flag to indicate the first or subsequent
277 * portion of transfer
278 * @param[out] request_cnt - The maximum number of record bytes requested
279 * @param[out] record_chg_num - Used to determine whether the PDR has changed
280 * while PDR transfer is going on
281 * @return pldm_completion_codes
282 */
283
284int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length,
285 uint32_t *record_hndl, uint32_t *data_transfer_hndl,
286 uint8_t *transfer_op_flag, uint16_t *request_cnt,
287 uint16_t *record_chg_num);
288
289/* Requester */
290
George Liu820a9a52019-11-26 14:43:59 +0800291/* GetPDR */
292
293/** @brief Create a PLDM request message for GetPDR
294 *
295 * @param[in] instance_id - Message's instance id
296 * @param[in] record_hndl - The recordHandle value for the PDR to be retrieved
297 * @param[in] data_transfer_hndl - Handle used to identify a particular
298 * multipart PDR data transfer operation
299 * @param[in] transfer_op_flag - Flag to indicate the first or subsequent
300 * portion of transfer
301 * @param[in] request_cnt - The maximum number of record bytes requested
302 * @param[in] record_chg_num - Used to determine whether the PDR has changed
303 * while PDR transfer is going on
304 * @param[out] msg - Message will be written to this
305 * @param[in] payload_length - Length of request message payload
306 * @return pldm_completion_codes
307 * @note Caller is responsible for memory alloc and dealloc of param
308 * 'msg.payload'
309 */
310int encode_get_pdr_req(uint8_t instance_id, uint32_t record_hndl,
311 uint32_t data_transfer_hndl, uint8_t transfer_op_flag,
312 uint16_t request_cnt, uint16_t record_chg_num,
313 struct pldm_msg *msg, size_t payload_length);
314
315/** @brief Decode GetPDR response data
316 *
George Liu684a7162019-12-06 15:10:52 +0800317 * Note:
318 * * If the return value is not PLDM_SUCCESS, it represents a
319 * transport layer error.
320 * * If the completion_code value is not PLDM_SUCCESS, it represents a
321 * protocol layer error and all the out-parameters are invalid.
322 *
George Liu820a9a52019-11-26 14:43:59 +0800323 * @param[in] msg - Request message
324 * @param[in] payload_length - Length of request message payload
325 * @param[out] completion_code - PLDM completion code
326 * @param[out] next_record_hndl - The recordHandle for the PDR that is next in
327 * the PDR Repository
328 * @param[out] next_data_transfer_hndl - A handle that identifies the next
329 * portion of the PDR data to be transferred, if any
330 * @param[out] transfer_flag - Indicates the portion of PDR data being
331 * transferred
332 * @param[out] resp_cnt - The number of recordData bytes returned in this
333 * response
334 * @param[out] record_data - PDR data bytes of length resp_cnt
335 * @param[in] record_data_length - Length of record_data
336 * @param[out] transfer_crc - A CRC-8 for the overall PDR. This is present only
337 * in the last part of a PDR being transferred
338 * @return pldm_completion_codes
339 */
340int decode_get_pdr_resp(const struct pldm_msg *msg, size_t payload_length,
341 uint8_t *completion_code, uint32_t *next_record_hndl,
342 uint32_t *next_data_transfer_hndl,
343 uint8_t *transfer_flag, uint16_t *resp_cnt,
344 uint8_t *record_data, size_t record_data_length,
345 uint8_t *transfer_crc);
346
Sampa Misra7fcfb662019-05-08 13:13:53 -0500347/* SetStateEffecterStates */
348
vkaverap98a2c192019-04-03 05:33:52 -0500349/** @brief Create a PLDM request message for SetStateEffecterStates
350 *
351 * @param[in] instance_id - Message's instance id
352 * @param[in] effecter_id - used to identify and access the effecter
353 * @param[in] comp_effecter_count - number of individual sets of effecter
354 * information. Upto eight sets of state effecter info can be accessed
355 * for a given effecter.
356 * @param[in] field - each unit is an instance of the stateField structure
357 * that is used to set the requested state for a particular effecter
358 * within the state effecter. This field holds the starting address of
359 * the stateField values. The user is responsible to allocate the
360 * memory prior to calling this command. The user has to allocate the
361 * field parameter as sizeof(set_effecter_state_field) *
362 * comp_effecter_count
363 * @param[out] msg - Message will be written to this
364 * @return pldm_completion_codes
365 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500366 * 'msg.payload'
vkaverap98a2c192019-04-03 05:33:52 -0500367 */
368
369int encode_set_state_effecter_states_req(uint8_t instance_id,
370 uint16_t effecter_id,
371 uint8_t comp_effecter_count,
372 set_effecter_state_field *field,
373 struct pldm_msg *msg);
374
375/** @brief Decode SetStateEffecterStates response data
George Liu684a7162019-12-06 15:10:52 +0800376 *
377 * Note:
378 * * If the return value is not PLDM_SUCCESS, it represents a
379 * transport layer error.
380 * * If the completion_code value is not PLDM_SUCCESS, it represents a
381 * protocol layer error and all the out-parameters are invalid.
382 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500383 * @param[in] msg - Request message
vkaverapa6575b82019-04-03 05:33:52 -0500384 * @param[in] payload_length - Length of response message payload
vkaverap98a2c192019-04-03 05:33:52 -0500385 * @param[out] completion_code - PLDM completion code
386 * @return pldm_completion_codes
387 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500388int decode_set_state_effecter_states_resp(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -0500389 size_t payload_length,
vkaverap98a2c192019-04-03 05:33:52 -0500390 uint8_t *completion_code);
George Liu30b859f2020-01-07 15:03:22 +0800391
392/* SetNumericEffecterValue */
393
394/** @brief Create a PLDM request message for SetNumericEffecterValue
395 *
396 * @param[in] instance_id - Message's instance id
397 * @param[in] effecter_id - used to identify and access the effecter
398 * @param[in] effecter_data_size - The bit width and format of the setting
399 * value for the effecter.
400 * value:{uint8,sint8,uint16,sint16,uint32,sint32}
401 * @param[in] effecter_value - The setting value of numeric effecter being
402 * requested.
403 * @param[in] payload_length - Length of request message payload
404 * @param[out] msg - Message will be written to this
405 * @return pldm_completion_codes
406 * @note Caller is responsible for memory alloc and dealloc of param
407 * 'msg.payload'
408 */
409int encode_set_numeric_effecter_value_req(
410 uint8_t instance_id, uint16_t effecter_id, uint8_t effecter_data_size,
411 uint8_t *effecter_value, struct pldm_msg *msg, size_t payload_length);
412
413/** @brief Decode SetNumericEffecterValue response data
414 * @param[in] msg - Request message
415 * @param[in] payload_length - Length of response message payload
416 * @param[out] completion_code - PLDM completion code
417 * @return pldm_completion_codes
418 */
419int decode_set_numeric_effecter_value_resp(const struct pldm_msg *msg,
420 size_t payload_length,
421 uint8_t *completion_code);
422
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500423#ifdef __cplusplus
424}
425#endif
426
427#endif /* PLATFORM_H */