Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 2 | #include "msgbuf.h" |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 3 | #include "msgbuf/platform.h" |
| 4 | |
| 5 | #include <libpldm/base.h> |
| 6 | #include <libpldm/platform.h> |
| 7 | #include <libpldm/pldm_types.h> |
| 8 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 9 | #include <endian.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 10 | #include <stdint.h> |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 11 | #include <stdlib.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 12 | #include <string.h> |
| 13 | |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 14 | static int pldm_platform_pdr_hdr_validate(struct pldm_value_pdr_hdr *ctx, |
| 15 | size_t lower, size_t upper) |
| 16 | { |
| 17 | if (ctx->length + sizeof(*ctx) < lower) { |
| 18 | return PLDM_ERROR_INVALID_LENGTH; |
| 19 | } |
| 20 | |
| 21 | if (ctx->length > upper) { |
| 22 | return PLDM_ERROR_INVALID_LENGTH; |
| 23 | } |
| 24 | |
| 25 | return PLDM_SUCCESS; |
| 26 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 27 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 28 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 29 | int encode_state_effecter_pdr( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 30 | struct pldm_state_effecter_pdr *const effecter, |
| 31 | const size_t allocation_size, |
| 32 | const struct state_effecter_possible_states *const possible_states, |
| 33 | const size_t possible_states_size, size_t *const actual_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 34 | { |
| 35 | // Encode possible states |
| 36 | |
| 37 | size_t calculated_possible_states_size = 0; |
| 38 | |
| 39 | { |
| 40 | char *states_ptr = (char *)possible_states; |
| 41 | char *const begin_states_ptr = states_ptr; |
| 42 | |
| 43 | for (int i = 0; i < effecter->composite_effecter_count; ++i) { |
| 44 | struct state_effecter_possible_states *states = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 45 | (struct state_effecter_possible_states *) |
| 46 | states_ptr; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 47 | |
| 48 | HTOLE16(states->state_set_id); |
| 49 | |
| 50 | states_ptr += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 51 | (sizeof(*states) - sizeof(states->states) + |
| 52 | states->possible_states_size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | calculated_possible_states_size = states_ptr - begin_states_ptr; |
| 56 | } |
| 57 | |
| 58 | // Check lengths |
| 59 | |
| 60 | if (possible_states_size != calculated_possible_states_size) { |
| 61 | *actual_size = 0; |
| 62 | return PLDM_ERROR; |
| 63 | } |
| 64 | |
| 65 | *actual_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 66 | (sizeof(struct pldm_state_effecter_pdr) + possible_states_size - |
| 67 | sizeof(effecter->possible_states)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 68 | |
| 69 | if (allocation_size < *actual_size) { |
| 70 | *actual_size = 0; |
| 71 | return PLDM_ERROR_INVALID_LENGTH; |
| 72 | } |
| 73 | |
| 74 | // Encode rest of PDR |
| 75 | |
| 76 | effecter->hdr.version = 1; |
| 77 | effecter->hdr.type = PLDM_STATE_EFFECTER_PDR; |
| 78 | effecter->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr); |
| 79 | |
| 80 | memcpy(effecter->possible_states, possible_states, |
| 81 | possible_states_size); |
| 82 | |
| 83 | // Convert effecter PDR body |
| 84 | HTOLE16(effecter->terminus_handle); |
| 85 | HTOLE16(effecter->effecter_id); |
| 86 | HTOLE16(effecter->entity_type); |
| 87 | HTOLE16(effecter->entity_instance); |
| 88 | HTOLE16(effecter->container_id); |
| 89 | HTOLE16(effecter->effecter_semantic_id); |
| 90 | |
| 91 | // Convert header |
| 92 | HTOLE32(effecter->hdr.record_handle); |
| 93 | HTOLE16(effecter->hdr.record_change_num); |
| 94 | HTOLE16(effecter->hdr.length); |
| 95 | |
| 96 | return PLDM_SUCCESS; |
| 97 | } |
| 98 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 99 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 100 | int encode_state_sensor_pdr( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 101 | struct pldm_state_sensor_pdr *const sensor, |
| 102 | const size_t allocation_size, |
| 103 | const struct state_sensor_possible_states *const possible_states, |
| 104 | const size_t possible_states_size, size_t *const actual_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 105 | { |
| 106 | // Encode possible states |
| 107 | |
| 108 | size_t calculated_possible_states_size = 0; |
| 109 | |
| 110 | { |
Andrew Jeffery | fbe61d7 | 2023-04-05 20:28:23 +0930 | [diff] [blame] | 111 | char *states_ptr = (char *)possible_states; |
| 112 | char *const begin_states_ptr = states_ptr; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 113 | |
| 114 | for (int i = 0; i < sensor->composite_sensor_count; ++i) { |
| 115 | struct state_sensor_possible_states *states = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 116 | (struct state_sensor_possible_states *) |
| 117 | states_ptr; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 118 | |
| 119 | HTOLE16(states->state_set_id); |
| 120 | |
| 121 | states_ptr += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 122 | (sizeof(*states) - sizeof(states->states) + |
| 123 | states->possible_states_size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | calculated_possible_states_size = states_ptr - begin_states_ptr; |
| 127 | } |
| 128 | |
| 129 | // Check lengths |
| 130 | |
| 131 | if (possible_states_size != calculated_possible_states_size) { |
| 132 | *actual_size = 0; |
| 133 | return PLDM_ERROR; |
| 134 | } |
| 135 | |
| 136 | *actual_size = (sizeof(struct pldm_state_sensor_pdr) + |
| 137 | possible_states_size - sizeof(sensor->possible_states)); |
| 138 | |
| 139 | if (allocation_size < *actual_size) { |
| 140 | *actual_size = 0; |
| 141 | return PLDM_ERROR_INVALID_LENGTH; |
| 142 | } |
| 143 | |
| 144 | // Encode rest of PDR |
| 145 | |
| 146 | sensor->hdr.version = 1; |
| 147 | sensor->hdr.type = PLDM_STATE_SENSOR_PDR; |
| 148 | sensor->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr); |
| 149 | |
| 150 | memcpy(sensor->possible_states, possible_states, possible_states_size); |
| 151 | |
| 152 | // Convert sensor PDR body |
| 153 | HTOLE16(sensor->terminus_handle); |
| 154 | HTOLE16(sensor->sensor_id); |
| 155 | HTOLE16(sensor->entity_type); |
| 156 | HTOLE16(sensor->entity_instance); |
| 157 | HTOLE16(sensor->container_id); |
| 158 | |
| 159 | // Convert header |
| 160 | HTOLE32(sensor->hdr.record_handle); |
| 161 | HTOLE16(sensor->hdr.record_change_num); |
| 162 | HTOLE16(sensor->hdr.length); |
| 163 | |
| 164 | return PLDM_SUCCESS; |
| 165 | } |
| 166 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 167 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 168 | int encode_set_state_effecter_states_resp(uint8_t instance_id, |
| 169 | uint8_t completion_code, |
| 170 | struct pldm_msg *msg) |
| 171 | { |
| 172 | if (msg == NULL) { |
| 173 | return PLDM_ERROR_INVALID_DATA; |
| 174 | } |
| 175 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 176 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 177 | header.msg_type = PLDM_RESPONSE; |
| 178 | header.instance = instance_id; |
| 179 | header.pldm_type = PLDM_PLATFORM; |
| 180 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 181 | |
| 182 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 183 | if (rc != PLDM_SUCCESS) { |
| 184 | return rc; |
| 185 | } |
| 186 | |
| 187 | msg->payload[0] = completion_code; |
| 188 | |
| 189 | return PLDM_SUCCESS; |
| 190 | } |
| 191 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 192 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 193 | int encode_set_state_effecter_states_req(uint8_t instance_id, |
| 194 | uint16_t effecter_id, |
| 195 | uint8_t comp_effecter_count, |
| 196 | set_effecter_state_field *field, |
| 197 | struct pldm_msg *msg) |
| 198 | { |
| 199 | if (msg == NULL) { |
| 200 | return PLDM_ERROR_INVALID_DATA; |
| 201 | } |
| 202 | |
| 203 | if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8 || |
| 204 | field == NULL) { |
| 205 | return PLDM_ERROR_INVALID_DATA; |
| 206 | } |
| 207 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 208 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 209 | header.msg_type = PLDM_REQUEST; |
| 210 | header.instance = instance_id; |
| 211 | header.pldm_type = PLDM_PLATFORM; |
| 212 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 213 | |
| 214 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 215 | if (rc != PLDM_SUCCESS) { |
| 216 | return rc; |
| 217 | } |
| 218 | |
| 219 | struct pldm_set_state_effecter_states_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 220 | (struct pldm_set_state_effecter_states_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 221 | effecter_id = htole16(effecter_id); |
| 222 | request->effecter_id = effecter_id; |
| 223 | request->comp_effecter_count = comp_effecter_count; |
| 224 | memcpy(request->field, field, |
| 225 | (sizeof(set_effecter_state_field) * comp_effecter_count)); |
| 226 | |
| 227 | return PLDM_SUCCESS; |
| 228 | } |
| 229 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 230 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 231 | int decode_set_state_effecter_states_resp(const struct pldm_msg *msg, |
| 232 | size_t payload_length, |
| 233 | uint8_t *completion_code) |
| 234 | { |
| 235 | if (msg == NULL || completion_code == NULL) { |
| 236 | return PLDM_ERROR_INVALID_DATA; |
| 237 | } |
| 238 | |
| 239 | *completion_code = msg->payload[0]; |
| 240 | if (PLDM_SUCCESS != *completion_code) { |
| 241 | return PLDM_SUCCESS; |
| 242 | } |
| 243 | |
| 244 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) { |
| 245 | return PLDM_ERROR_INVALID_LENGTH; |
| 246 | } |
| 247 | |
| 248 | return PLDM_SUCCESS; |
| 249 | } |
| 250 | |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 251 | #define PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE 3 |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 252 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 253 | int decode_set_state_effecter_states_req(const struct pldm_msg *msg, |
| 254 | size_t payload_length, |
| 255 | uint16_t *effecter_id, |
| 256 | uint8_t *comp_effecter_count, |
| 257 | set_effecter_state_field *field) |
| 258 | { |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 259 | struct pldm_msgbuf _buf; |
| 260 | struct pldm_msgbuf *buf = &_buf; |
| 261 | int rc; |
| 262 | int i; |
| 263 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 264 | if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL || |
| 265 | field == NULL) { |
| 266 | return PLDM_ERROR_INVALID_DATA; |
| 267 | } |
| 268 | |
| 269 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) { |
| 270 | return PLDM_ERROR_INVALID_LENGTH; |
| 271 | } |
| 272 | |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 273 | rc = pldm_msgbuf_init(buf, PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE, |
| 274 | msg->payload, payload_length); |
| 275 | if (rc) { |
| 276 | return rc; |
| 277 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 278 | |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 279 | pldm_msgbuf_extract(buf, effecter_id); |
| 280 | pldm_msgbuf_extract(buf, comp_effecter_count); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 281 | |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 282 | if (*comp_effecter_count > 8) { |
| 283 | return PLDM_ERROR_INVALID_DATA; |
| 284 | } |
| 285 | |
| 286 | for (i = 0; i < *comp_effecter_count; i++) { |
| 287 | pldm_msgbuf_extract(buf, &field[i].set_request); |
| 288 | pldm_msgbuf_extract(buf, &field[i].effecter_state); |
| 289 | } |
| 290 | |
| 291 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 292 | } |
| 293 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 294 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 295 | int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length, |
| 296 | uint32_t *record_hndl, uint32_t *data_transfer_hndl, |
| 297 | uint8_t *transfer_op_flag, uint16_t *request_cnt, |
| 298 | uint16_t *record_chg_num) |
| 299 | { |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 300 | struct pldm_msgbuf _buf; |
| 301 | struct pldm_msgbuf *buf = &_buf; |
| 302 | int rc; |
| 303 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 304 | if (msg == NULL || record_hndl == NULL || data_transfer_hndl == NULL || |
| 305 | transfer_op_flag == NULL || request_cnt == NULL || |
| 306 | record_chg_num == NULL) { |
| 307 | return PLDM_ERROR_INVALID_DATA; |
| 308 | } |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 309 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 310 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 311 | return PLDM_ERROR_INVALID_LENGTH; |
| 312 | } |
| 313 | |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 314 | rc = pldm_msgbuf_init(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload, |
| 315 | payload_length); |
| 316 | if (rc) { |
| 317 | return rc; |
| 318 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 319 | |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 320 | pldm_msgbuf_extract(buf, record_hndl); |
| 321 | pldm_msgbuf_extract(buf, data_transfer_hndl); |
| 322 | pldm_msgbuf_extract(buf, transfer_op_flag); |
| 323 | pldm_msgbuf_extract(buf, request_cnt); |
| 324 | pldm_msgbuf_extract(buf, record_chg_num); |
| 325 | |
| 326 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 327 | } |
| 328 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 329 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 330 | int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code, |
| 331 | uint32_t next_record_hndl, |
| 332 | uint32_t next_data_transfer_hndl, uint8_t transfer_flag, |
| 333 | uint16_t resp_cnt, const uint8_t *record_data, |
| 334 | uint8_t transfer_crc, struct pldm_msg *msg) |
| 335 | { |
| 336 | if (msg == NULL) { |
| 337 | return PLDM_ERROR_INVALID_DATA; |
| 338 | } |
| 339 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 340 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 341 | header.msg_type = PLDM_RESPONSE; |
| 342 | header.instance = instance_id; |
| 343 | header.pldm_type = PLDM_PLATFORM; |
| 344 | header.command = PLDM_GET_PDR; |
| 345 | |
| 346 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 347 | if (rc != PLDM_SUCCESS) { |
| 348 | return rc; |
| 349 | } |
| 350 | |
| 351 | struct pldm_get_pdr_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 352 | (struct pldm_get_pdr_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 353 | response->completion_code = completion_code; |
| 354 | |
| 355 | if (response->completion_code == PLDM_SUCCESS) { |
| 356 | response->next_record_handle = htole32(next_record_hndl); |
| 357 | response->next_data_transfer_handle = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 358 | htole32(next_data_transfer_hndl); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 359 | response->transfer_flag = transfer_flag; |
| 360 | response->response_count = htole16(resp_cnt); |
| 361 | if (record_data != NULL && resp_cnt > 0) { |
| 362 | memcpy(response->record_data, record_data, resp_cnt); |
| 363 | } |
| 364 | if (transfer_flag == PLDM_END) { |
| 365 | uint8_t *dst = msg->payload; |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 366 | dst += (sizeof(struct pldm_get_pdr_resp) - 1) + |
| 367 | resp_cnt; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 368 | *dst = transfer_crc; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | return PLDM_SUCCESS; |
| 373 | } |
| 374 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 375 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 376 | int encode_get_pdr_repository_info_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 377 | uint8_t instance_id, uint8_t completion_code, uint8_t repository_state, |
| 378 | const uint8_t *update_time, const uint8_t *oem_update_time, |
| 379 | uint32_t record_count, uint32_t repository_size, |
| 380 | uint32_t largest_record_size, uint8_t data_transfer_handle_timeout, |
| 381 | struct pldm_msg *msg) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 382 | { |
| 383 | if (msg == NULL) { |
| 384 | return PLDM_ERROR_INVALID_DATA; |
| 385 | } |
| 386 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 387 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 388 | header.msg_type = PLDM_RESPONSE; |
| 389 | header.instance = instance_id; |
| 390 | header.pldm_type = PLDM_PLATFORM; |
| 391 | header.command = PLDM_GET_PDR_REPOSITORY_INFO; |
| 392 | |
| 393 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 394 | if (rc != PLDM_SUCCESS) { |
| 395 | return rc; |
| 396 | } |
| 397 | |
| 398 | struct pldm_pdr_repository_info_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 399 | (struct pldm_pdr_repository_info_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 400 | response->completion_code = completion_code; |
| 401 | |
| 402 | if (response->completion_code == PLDM_SUCCESS) { |
| 403 | response->repository_state = repository_state; |
| 404 | if (update_time != NULL) { |
| 405 | memcpy(response->update_time, update_time, |
| 406 | PLDM_TIMESTAMP104_SIZE); |
| 407 | } |
| 408 | if (oem_update_time != NULL) { |
| 409 | memcpy(response->oem_update_time, oem_update_time, |
| 410 | PLDM_TIMESTAMP104_SIZE); |
| 411 | } |
| 412 | response->record_count = htole32(record_count); |
| 413 | response->repository_size = htole32(repository_size); |
| 414 | response->largest_record_size = htole32(largest_record_size); |
| 415 | response->data_transfer_handle_timeout = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 416 | data_transfer_handle_timeout; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | return PLDM_SUCCESS; |
| 420 | } |
| 421 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 422 | LIBPLDM_ABI_STABLE |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 423 | int decode_get_pdr_repository_info_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 424 | const struct pldm_msg *msg, size_t payload_length, |
| 425 | uint8_t *completion_code, uint8_t *repository_state, |
| 426 | uint8_t *update_time, uint8_t *oem_update_time, uint32_t *record_count, |
| 427 | uint32_t *repository_size, uint32_t *largest_record_size, |
| 428 | uint8_t *data_transfer_handle_timeout) |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 429 | { |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 430 | struct pldm_msgbuf _buf; |
| 431 | struct pldm_msgbuf *buf = &_buf; |
| 432 | int rc; |
| 433 | |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 434 | if (msg == NULL || completion_code == NULL || |
| 435 | repository_state == NULL || update_time == NULL || |
| 436 | oem_update_time == NULL || record_count == NULL || |
| 437 | repository_size == NULL || largest_record_size == NULL || |
| 438 | data_transfer_handle_timeout == NULL) { |
| 439 | return PLDM_ERROR_INVALID_DATA; |
| 440 | } |
| 441 | |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 442 | rc = pldm_msgbuf_init(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, |
| 443 | msg->payload, payload_length); |
| 444 | if (rc) { |
| 445 | return rc; |
| 446 | } |
| 447 | |
| 448 | pldm_msgbuf_extract(buf, completion_code); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 449 | if (PLDM_SUCCESS != *completion_code) { |
| 450 | return PLDM_SUCCESS; |
| 451 | } |
| 452 | |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 453 | pldm_msgbuf_extract(buf, repository_state); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 454 | if (*repository_state > PLDM_FAILED) { |
| 455 | return PLDM_ERROR_INVALID_DATA; |
| 456 | } |
| 457 | |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 458 | pldm_msgbuf_extract_array(buf, update_time, PLDM_TIMESTAMP104_SIZE); |
| 459 | pldm_msgbuf_extract_array(buf, oem_update_time, PLDM_TIMESTAMP104_SIZE); |
| 460 | pldm_msgbuf_extract(buf, record_count); |
| 461 | pldm_msgbuf_extract(buf, repository_size); |
| 462 | pldm_msgbuf_extract(buf, largest_record_size); |
| 463 | pldm_msgbuf_extract(buf, data_transfer_handle_timeout); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 464 | |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 465 | return pldm_msgbuf_destroy(buf); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 466 | } |
| 467 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 468 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 469 | int encode_get_pdr_req(uint8_t instance_id, uint32_t record_hndl, |
| 470 | uint32_t data_transfer_hndl, uint8_t transfer_op_flag, |
| 471 | uint16_t request_cnt, uint16_t record_chg_num, |
| 472 | struct pldm_msg *msg, size_t payload_length) |
| 473 | { |
| 474 | if (msg == NULL) { |
| 475 | return PLDM_ERROR_INVALID_DATA; |
| 476 | } |
| 477 | |
| 478 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 479 | return PLDM_ERROR_INVALID_LENGTH; |
| 480 | } |
| 481 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 482 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 483 | header.msg_type = PLDM_REQUEST; |
| 484 | header.instance = instance_id; |
| 485 | header.pldm_type = PLDM_PLATFORM; |
| 486 | header.command = PLDM_GET_PDR; |
| 487 | |
| 488 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 489 | if (rc != PLDM_SUCCESS) { |
| 490 | return rc; |
| 491 | } |
| 492 | |
| 493 | struct pldm_get_pdr_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 494 | (struct pldm_get_pdr_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 495 | request->record_handle = htole32(record_hndl); |
| 496 | request->data_transfer_handle = htole32(data_transfer_hndl); |
| 497 | request->transfer_op_flag = transfer_op_flag; |
| 498 | request->request_count = htole16(request_cnt); |
| 499 | request->record_change_number = htole16(record_chg_num); |
| 500 | |
| 501 | return PLDM_SUCCESS; |
| 502 | } |
| 503 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 504 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 505 | int decode_get_pdr_resp(const struct pldm_msg *msg, size_t payload_length, |
| 506 | uint8_t *completion_code, uint32_t *next_record_hndl, |
| 507 | uint32_t *next_data_transfer_hndl, |
| 508 | uint8_t *transfer_flag, uint16_t *resp_cnt, |
| 509 | uint8_t *record_data, size_t record_data_length, |
| 510 | uint8_t *transfer_crc) |
| 511 | { |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 512 | struct pldm_msgbuf _buf; |
| 513 | struct pldm_msgbuf *buf = &_buf; |
| 514 | int rc; |
| 515 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 516 | if (msg == NULL || completion_code == NULL || |
| 517 | next_record_hndl == NULL || next_data_transfer_hndl == NULL || |
| 518 | transfer_flag == NULL || resp_cnt == NULL || transfer_crc == NULL) { |
| 519 | return PLDM_ERROR_INVALID_DATA; |
| 520 | } |
| 521 | |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 522 | rc = pldm_msgbuf_init(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload, |
| 523 | payload_length); |
| 524 | if (rc) { |
| 525 | return rc; |
| 526 | } |
| 527 | |
| 528 | pldm_msgbuf_extract(buf, completion_code); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 529 | if (PLDM_SUCCESS != *completion_code) { |
| 530 | return PLDM_SUCCESS; |
| 531 | } |
| 532 | |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 533 | pldm_msgbuf_extract(buf, next_record_hndl); |
| 534 | pldm_msgbuf_extract(buf, next_data_transfer_hndl); |
| 535 | pldm_msgbuf_extract(buf, transfer_flag); |
| 536 | rc = pldm_msgbuf_extract(buf, resp_cnt); |
| 537 | if (rc) { |
| 538 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | if (*resp_cnt > 0 && record_data != NULL) { |
| 542 | if (record_data_length < *resp_cnt) { |
| 543 | return PLDM_ERROR_INVALID_LENGTH; |
| 544 | } |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 545 | pldm_msgbuf_extract_array(buf, record_data, *resp_cnt); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if (*transfer_flag == PLDM_END) { |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 549 | pldm_msgbuf_extract(buf, transfer_crc); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 550 | } |
| 551 | |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 552 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 553 | } |
| 554 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 555 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 556 | int decode_set_numeric_effecter_value_req(const struct pldm_msg *msg, |
| 557 | size_t payload_length, |
| 558 | uint16_t *effecter_id, |
| 559 | uint8_t *effecter_data_size, |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 560 | uint8_t effecter_value[4]) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 561 | { |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 562 | struct pldm_msgbuf _buf; |
| 563 | struct pldm_msgbuf *buf = &_buf; |
| 564 | int rc; |
| 565 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 566 | if (msg == NULL || effecter_id == NULL || effecter_data_size == NULL || |
| 567 | effecter_value == NULL) { |
| 568 | return PLDM_ERROR_INVALID_DATA; |
| 569 | } |
| 570 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 571 | rc = pldm_msgbuf_init(buf, |
| 572 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES, |
| 573 | msg->payload, payload_length); |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 574 | if (rc) { |
| 575 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 576 | } |
| 577 | |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 578 | pldm_msgbuf_extract(buf, effecter_id); |
| 579 | rc = pldm_msgbuf_extract(buf, effecter_data_size); |
| 580 | if (rc) { |
| 581 | return PLDM_ERROR_INVALID_DATA; |
| 582 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 583 | |
| 584 | if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 585 | return PLDM_ERROR_INVALID_DATA; |
| 586 | } |
| 587 | |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 588 | pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size, |
| 589 | effecter_value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 590 | |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 591 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 592 | } |
| 593 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 594 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 595 | int encode_set_numeric_effecter_value_resp(uint8_t instance_id, |
| 596 | uint8_t completion_code, |
| 597 | struct pldm_msg *msg, |
| 598 | size_t payload_length) |
| 599 | { |
| 600 | if (msg == NULL) { |
| 601 | return PLDM_ERROR_INVALID_DATA; |
| 602 | } |
| 603 | |
| 604 | if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) { |
| 605 | return PLDM_ERROR_INVALID_LENGTH; |
| 606 | } |
| 607 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 608 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 609 | header.msg_type = PLDM_RESPONSE; |
| 610 | header.instance = instance_id; |
| 611 | header.pldm_type = PLDM_PLATFORM; |
| 612 | header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE; |
| 613 | |
| 614 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 615 | if (rc != PLDM_SUCCESS) { |
| 616 | return rc; |
| 617 | } |
| 618 | |
| 619 | msg->payload[0] = completion_code; |
| 620 | |
| 621 | return rc; |
| 622 | } |
| 623 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 624 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 625 | int encode_set_numeric_effecter_value_req(uint8_t instance_id, |
| 626 | uint16_t effecter_id, |
| 627 | uint8_t effecter_data_size, |
| 628 | const uint8_t *effecter_value, |
| 629 | struct pldm_msg *msg, |
| 630 | size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 631 | { |
| 632 | if (msg == NULL || effecter_value == NULL) { |
| 633 | return PLDM_ERROR_INVALID_DATA; |
| 634 | } |
| 635 | |
| 636 | if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 637 | return PLDM_ERROR_INVALID_DATA; |
| 638 | } |
| 639 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 640 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 641 | header.msg_type = PLDM_REQUEST; |
| 642 | header.instance = instance_id; |
| 643 | header.pldm_type = PLDM_PLATFORM; |
| 644 | header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE; |
| 645 | |
| 646 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 647 | if (rc != PLDM_SUCCESS) { |
| 648 | return rc; |
| 649 | } |
| 650 | |
| 651 | struct pldm_set_numeric_effecter_value_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 652 | (struct pldm_set_numeric_effecter_value_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 653 | if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 654 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 655 | if (payload_length != |
| 656 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES) { |
| 657 | return PLDM_ERROR_INVALID_LENGTH; |
| 658 | } |
| 659 | request->effecter_value[0] = *effecter_value; |
| 660 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 661 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 662 | if (payload_length != |
| 663 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1) { |
| 664 | return PLDM_ERROR_INVALID_LENGTH; |
| 665 | } |
| 666 | |
| 667 | uint16_t val = *(uint16_t *)(effecter_value); |
| 668 | val = htole16(val); |
| 669 | memcpy(request->effecter_value, &val, sizeof(uint16_t)); |
| 670 | |
| 671 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 672 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 673 | if (payload_length != |
| 674 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3) { |
| 675 | return PLDM_ERROR_INVALID_LENGTH; |
| 676 | } |
| 677 | |
| 678 | uint32_t val = *(uint32_t *)(effecter_value); |
| 679 | val = htole32(val); |
| 680 | memcpy(request->effecter_value, &val, sizeof(uint32_t)); |
| 681 | } |
| 682 | |
| 683 | request->effecter_id = htole16(effecter_id); |
| 684 | request->effecter_data_size = effecter_data_size; |
| 685 | |
| 686 | return PLDM_SUCCESS; |
| 687 | } |
| 688 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 689 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 690 | int decode_set_numeric_effecter_value_resp(const struct pldm_msg *msg, |
| 691 | size_t payload_length, |
| 692 | uint8_t *completion_code) |
| 693 | { |
| 694 | if (msg == NULL || completion_code == NULL) { |
| 695 | return PLDM_ERROR_INVALID_DATA; |
| 696 | } |
| 697 | |
| 698 | if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) { |
| 699 | return PLDM_ERROR_INVALID_LENGTH; |
| 700 | } |
| 701 | |
| 702 | *completion_code = msg->payload[0]; |
| 703 | |
| 704 | return PLDM_SUCCESS; |
| 705 | } |
| 706 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 707 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 708 | int encode_get_state_sensor_readings_resp(uint8_t instance_id, |
| 709 | uint8_t completion_code, |
| 710 | uint8_t comp_sensor_count, |
| 711 | get_sensor_state_field *field, |
| 712 | struct pldm_msg *msg) |
| 713 | { |
| 714 | if (msg == NULL) { |
| 715 | return PLDM_ERROR_INVALID_DATA; |
| 716 | } |
| 717 | |
| 718 | if (comp_sensor_count < 0x1 || comp_sensor_count > 0x8) { |
| 719 | return PLDM_ERROR_INVALID_DATA; |
| 720 | } |
| 721 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 722 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 723 | header.msg_type = PLDM_RESPONSE; |
| 724 | header.instance = instance_id; |
| 725 | header.pldm_type = PLDM_PLATFORM; |
| 726 | header.command = PLDM_GET_STATE_SENSOR_READINGS; |
| 727 | |
| 728 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 729 | if (rc != PLDM_SUCCESS) { |
| 730 | return rc; |
| 731 | } |
| 732 | |
| 733 | struct pldm_get_state_sensor_readings_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 734 | (struct pldm_get_state_sensor_readings_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 735 | |
| 736 | response->completion_code = completion_code; |
| 737 | response->comp_sensor_count = comp_sensor_count; |
| 738 | memcpy(response->field, field, |
| 739 | (sizeof(get_sensor_state_field) * comp_sensor_count)); |
| 740 | |
| 741 | return PLDM_SUCCESS; |
| 742 | } |
| 743 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 744 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 745 | int encode_get_state_sensor_readings_req(uint8_t instance_id, |
| 746 | uint16_t sensor_id, |
| 747 | bitfield8_t sensor_rearm, |
| 748 | uint8_t reserved, struct pldm_msg *msg) |
| 749 | { |
| 750 | if (msg == NULL) { |
| 751 | return PLDM_ERROR_INVALID_DATA; |
| 752 | } |
| 753 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 754 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 755 | header.msg_type = PLDM_REQUEST; |
| 756 | header.instance = instance_id; |
| 757 | header.pldm_type = PLDM_PLATFORM; |
| 758 | header.command = PLDM_GET_STATE_SENSOR_READINGS; |
| 759 | |
| 760 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 761 | if (rc != PLDM_SUCCESS) { |
| 762 | return rc; |
| 763 | } |
| 764 | |
| 765 | struct pldm_get_state_sensor_readings_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 766 | (struct pldm_get_state_sensor_readings_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 767 | |
| 768 | request->sensor_id = htole16(sensor_id); |
| 769 | request->reserved = reserved; |
| 770 | request->sensor_rearm = sensor_rearm; |
| 771 | |
| 772 | return PLDM_SUCCESS; |
| 773 | } |
| 774 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 775 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 776 | int decode_get_state_sensor_readings_resp(const struct pldm_msg *msg, |
| 777 | size_t payload_length, |
| 778 | uint8_t *completion_code, |
| 779 | uint8_t *comp_sensor_count, |
| 780 | get_sensor_state_field *field) |
| 781 | { |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 782 | struct pldm_msgbuf _buf; |
| 783 | struct pldm_msgbuf *buf = &_buf; |
| 784 | uint8_t i; |
| 785 | int rc; |
| 786 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 787 | if (msg == NULL || completion_code == NULL || |
| 788 | comp_sensor_count == NULL || field == NULL) { |
| 789 | return PLDM_ERROR_INVALID_DATA; |
| 790 | } |
| 791 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 792 | rc = pldm_msgbuf_init(buf, |
| 793 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES, |
| 794 | msg->payload, payload_length); |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 795 | if (rc) { |
| 796 | return rc; |
| 797 | } |
| 798 | |
| 799 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 800 | if (rc) { |
| 801 | return rc; |
| 802 | } |
| 803 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 804 | if (PLDM_SUCCESS != *completion_code) { |
| 805 | return PLDM_SUCCESS; |
| 806 | } |
| 807 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 808 | rc = pldm_msgbuf_extract(buf, comp_sensor_count); |
| 809 | if (rc) { |
| 810 | return rc; |
| 811 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 812 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 813 | if (*comp_sensor_count < 0x1 || *comp_sensor_count > 0x8) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 814 | return PLDM_ERROR_INVALID_DATA; |
| 815 | } |
| 816 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 817 | for (i = 0; i < *comp_sensor_count; i++) { |
| 818 | pldm_msgbuf_extract(buf, &field[i].sensor_op_state); |
| 819 | pldm_msgbuf_extract(buf, &field[i].present_state); |
| 820 | pldm_msgbuf_extract(buf, &field[i].previous_state); |
| 821 | pldm_msgbuf_extract(buf, &field[i].event_state); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 822 | } |
| 823 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 824 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 825 | } |
| 826 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 827 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 828 | int decode_get_state_sensor_readings_req(const struct pldm_msg *msg, |
| 829 | size_t payload_length, |
| 830 | uint16_t *sensor_id, |
| 831 | bitfield8_t *sensor_rearm, |
| 832 | uint8_t *reserved) |
| 833 | { |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 834 | struct pldm_msgbuf _buf; |
| 835 | struct pldm_msgbuf *buf = &_buf; |
| 836 | int rc; |
| 837 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 838 | if (msg == NULL || sensor_id == NULL || sensor_rearm == NULL) { |
| 839 | return PLDM_ERROR_INVALID_DATA; |
| 840 | } |
| 841 | |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 842 | rc = pldm_msgbuf_init(buf, PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES, |
| 843 | msg->payload, payload_length); |
| 844 | if (rc) { |
| 845 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 846 | } |
| 847 | |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 848 | pldm_msgbuf_extract(buf, sensor_id); |
| 849 | pldm_msgbuf_extract(buf, &sensor_rearm->byte); |
| 850 | pldm_msgbuf_extract(buf, reserved); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 851 | |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 852 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 853 | } |
| 854 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 855 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 856 | int encode_sensor_event_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 857 | struct pldm_sensor_event_data *const event_data, |
| 858 | const size_t event_data_size, const uint16_t sensor_id, |
| 859 | const enum sensor_event_class_states sensor_event_class, |
| 860 | const uint8_t sensor_offset, const uint8_t event_state, |
| 861 | const uint8_t previous_event_state, |
| 862 | size_t *const actual_event_data_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 863 | { |
| 864 | *actual_event_data_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 865 | (sizeof(*event_data) - sizeof(event_data->event_class) + |
| 866 | sizeof(struct pldm_sensor_event_state_sensor_state)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 867 | |
| 868 | if (!event_data) { |
| 869 | return PLDM_SUCCESS; |
| 870 | } |
| 871 | |
| 872 | if (event_data_size < *actual_event_data_size) { |
| 873 | *actual_event_data_size = 0; |
| 874 | return PLDM_ERROR_INVALID_LENGTH; |
| 875 | } |
| 876 | |
| 877 | event_data->sensor_id = htole16(sensor_id); |
| 878 | event_data->sensor_event_class_type = sensor_event_class; |
| 879 | |
| 880 | struct pldm_sensor_event_state_sensor_state *const state_data = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 881 | (struct pldm_sensor_event_state_sensor_state *) |
| 882 | event_data->event_class; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 883 | |
| 884 | state_data->sensor_offset = sensor_offset; |
| 885 | state_data->event_state = event_state; |
| 886 | state_data->previous_event_state = previous_event_state; |
| 887 | |
| 888 | return PLDM_SUCCESS; |
| 889 | } |
| 890 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 891 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 892 | int decode_platform_event_message_req(const struct pldm_msg *msg, |
| 893 | size_t payload_length, |
| 894 | uint8_t *format_version, uint8_t *tid, |
| 895 | uint8_t *event_class, |
| 896 | size_t *event_data_offset) |
| 897 | { |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 898 | struct pldm_msgbuf _buf; |
| 899 | struct pldm_msgbuf *buf = &_buf; |
| 900 | int rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 901 | |
| 902 | if (msg == NULL || format_version == NULL || tid == NULL || |
| 903 | event_class == NULL || event_data_offset == NULL) { |
| 904 | return PLDM_ERROR_INVALID_DATA; |
| 905 | } |
| 906 | |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 907 | rc = pldm_msgbuf_init(buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES, |
| 908 | msg->payload, payload_length); |
| 909 | if (rc) { |
| 910 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 911 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 912 | |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 913 | pldm_msgbuf_extract(buf, format_version); |
| 914 | pldm_msgbuf_extract(buf, tid); |
| 915 | pldm_msgbuf_extract(buf, event_class); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 916 | *event_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 917 | sizeof(*format_version) + sizeof(*tid) + sizeof(*event_class); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 918 | |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 919 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 920 | } |
| 921 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 922 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 923 | int decode_poll_for_platform_event_message_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 924 | const struct pldm_msg *msg, size_t payload_length, |
| 925 | uint8_t *format_version, uint8_t *transfer_operation_flag, |
| 926 | uint32_t *data_transfer_handle, uint16_t *event_id_to_acknowledge) |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 927 | { |
| 928 | struct pldm_msgbuf _buf; |
| 929 | struct pldm_msgbuf *buf = &_buf; |
| 930 | int rc; |
| 931 | |
| 932 | if (msg == NULL) { |
| 933 | return PLDM_ERROR_INVALID_DATA; |
| 934 | } |
| 935 | |
| 936 | rc = pldm_msgbuf_init(buf, |
| 937 | PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES, |
| 938 | msg->payload, payload_length); |
| 939 | if (rc) { |
| 940 | return rc; |
| 941 | } |
| 942 | |
| 943 | pldm_msgbuf_extract(buf, format_version); |
| 944 | rc = pldm_msgbuf_extract(buf, transfer_operation_flag); |
| 945 | if (rc) { |
| 946 | return rc; |
| 947 | } |
| 948 | if (*transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY) { |
| 949 | return PLDM_ERROR_INVALID_DATA; |
| 950 | } |
| 951 | |
| 952 | pldm_msgbuf_extract(buf, data_transfer_handle); |
| 953 | rc = pldm_msgbuf_extract(buf, event_id_to_acknowledge); |
| 954 | if (rc) { |
| 955 | return rc; |
| 956 | } |
| 957 | |
| 958 | if (!(((*transfer_operation_flag == PLDM_GET_NEXTPART) && |
| 959 | (*event_id_to_acknowledge == 0xFFFF)) || |
| 960 | ((*transfer_operation_flag == PLDM_GET_FIRSTPART) && |
| 961 | (*event_id_to_acknowledge == 0x000)) || |
| 962 | (*transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY))) { |
| 963 | return PLDM_ERROR_INVALID_DATA; |
| 964 | } |
| 965 | |
| 966 | return pldm_msgbuf_destroy(buf); |
| 967 | } |
| 968 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 969 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 970 | int encode_platform_event_message_resp(uint8_t instance_id, |
| 971 | uint8_t completion_code, |
| 972 | uint8_t platform_event_status, |
| 973 | struct pldm_msg *msg) |
| 974 | { |
| 975 | if (msg == NULL) { |
| 976 | return PLDM_ERROR_INVALID_DATA; |
| 977 | } |
| 978 | |
| 979 | if (platform_event_status > PLDM_EVENT_LOGGING_REJECTED) { |
| 980 | return PLDM_ERROR_INVALID_DATA; |
| 981 | } |
| 982 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 983 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 984 | header.msg_type = PLDM_RESPONSE; |
| 985 | header.instance = instance_id; |
| 986 | header.pldm_type = PLDM_PLATFORM; |
| 987 | header.command = PLDM_PLATFORM_EVENT_MESSAGE; |
| 988 | |
| 989 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 990 | if (rc != PLDM_SUCCESS) { |
| 991 | return rc; |
| 992 | } |
| 993 | |
| 994 | struct pldm_platform_event_message_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 995 | (struct pldm_platform_event_message_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 996 | response->completion_code = completion_code; |
| 997 | response->platform_event_status = platform_event_status; |
| 998 | |
| 999 | return PLDM_SUCCESS; |
| 1000 | } |
| 1001 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1002 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1003 | int encode_poll_for_platform_event_message_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1004 | uint8_t instance_id, uint8_t completion_code, uint8_t tid, |
| 1005 | uint16_t event_id, uint32_t next_data_transfer_handle, |
| 1006 | uint8_t transfer_flag, uint8_t event_class, uint32_t event_data_size, |
| 1007 | uint8_t *event_data, uint32_t checksum, struct pldm_msg *msg, |
| 1008 | size_t payload_length) |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1009 | { |
| 1010 | struct pldm_msgbuf _buf; |
| 1011 | struct pldm_msgbuf *buf = &_buf; |
| 1012 | int rc; |
| 1013 | |
| 1014 | if (!msg) { |
| 1015 | return PLDM_ERROR_INVALID_DATA; |
| 1016 | } |
| 1017 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1018 | struct pldm_header_info header = { 0 }; |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1019 | header.msg_type = PLDM_RESPONSE; |
| 1020 | header.instance = instance_id; |
| 1021 | header.pldm_type = PLDM_PLATFORM; |
| 1022 | header.command = PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE; |
| 1023 | |
| 1024 | rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1025 | if (rc != PLDM_SUCCESS) { |
| 1026 | return rc; |
| 1027 | } |
| 1028 | |
| 1029 | rc = pldm_msgbuf_init( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1030 | buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES, |
| 1031 | msg->payload, payload_length); |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1032 | if (rc) { |
| 1033 | return rc; |
| 1034 | } |
| 1035 | |
| 1036 | pldm_msgbuf_insert(buf, completion_code); |
| 1037 | pldm_msgbuf_insert(buf, tid); |
| 1038 | pldm_msgbuf_insert(buf, event_id); |
| 1039 | |
| 1040 | if (event_id == 0xffff || event_id == 0x0000) { |
| 1041 | if (PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES != |
| 1042 | payload_length) { |
| 1043 | return PLDM_ERROR_INVALID_LENGTH; |
| 1044 | } |
| 1045 | return pldm_msgbuf_destroy(buf); |
| 1046 | } |
| 1047 | |
| 1048 | if ((event_data == NULL) && (event_data_size > 0)) { |
| 1049 | return PLDM_ERROR_INVALID_DATA; |
| 1050 | } |
| 1051 | |
| 1052 | pldm_msgbuf_insert(buf, next_data_transfer_handle); |
| 1053 | pldm_msgbuf_insert(buf, transfer_flag); |
| 1054 | pldm_msgbuf_insert(buf, event_class); |
| 1055 | pldm_msgbuf_insert(buf, event_data_size); |
| 1056 | |
| 1057 | if ((event_data_size > 0) && event_data) { |
| 1058 | pldm_msgbuf_insert_array(buf, event_data, event_data_size); |
| 1059 | } |
| 1060 | |
| 1061 | if (transfer_flag == PLDM_END || transfer_flag == PLDM_START_AND_END) { |
| 1062 | pldm_msgbuf_insert(buf, checksum); |
| 1063 | } |
| 1064 | |
| 1065 | return pldm_msgbuf_destroy(buf); |
| 1066 | } |
| 1067 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1068 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1069 | int encode_platform_event_message_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1070 | uint8_t instance_id, uint8_t format_version, uint8_t tid, |
| 1071 | uint8_t event_class, const uint8_t *event_data, |
| 1072 | size_t event_data_length, struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1073 | |
| 1074 | { |
| 1075 | if (format_version != 1) { |
| 1076 | return PLDM_ERROR_INVALID_DATA; |
| 1077 | } |
| 1078 | |
| 1079 | if (msg == NULL || event_data == NULL) { |
| 1080 | return PLDM_ERROR_INVALID_DATA; |
| 1081 | } |
| 1082 | |
| 1083 | if (event_data_length == 0) { |
| 1084 | return PLDM_ERROR_INVALID_DATA; |
| 1085 | } |
| 1086 | |
| 1087 | if (payload_length != |
| 1088 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_length) { |
| 1089 | return PLDM_ERROR_INVALID_LENGTH; |
| 1090 | } |
| 1091 | |
| 1092 | if (event_class > PLDM_HEARTBEAT_TIMER_ELAPSED_EVENT && |
| 1093 | !(event_class >= 0xF0 && event_class <= 0xFE)) { |
| 1094 | return PLDM_ERROR_INVALID_DATA; |
| 1095 | } |
| 1096 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1097 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1098 | header.msg_type = PLDM_REQUEST; |
| 1099 | header.instance = instance_id; |
| 1100 | header.pldm_type = PLDM_PLATFORM; |
| 1101 | header.command = PLDM_PLATFORM_EVENT_MESSAGE; |
| 1102 | |
| 1103 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1104 | if (rc != PLDM_SUCCESS) { |
| 1105 | return rc; |
| 1106 | } |
| 1107 | |
| 1108 | struct pldm_platform_event_message_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1109 | (struct pldm_platform_event_message_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1110 | request->format_version = format_version; |
| 1111 | request->tid = tid; |
| 1112 | request->event_class = event_class; |
| 1113 | memcpy(request->event_data, event_data, event_data_length); |
| 1114 | |
| 1115 | return PLDM_SUCCESS; |
| 1116 | } |
| 1117 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1118 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1119 | int decode_platform_event_message_resp(const struct pldm_msg *msg, |
| 1120 | size_t payload_length, |
| 1121 | uint8_t *completion_code, |
| 1122 | uint8_t *platform_event_status) |
| 1123 | { |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1124 | struct pldm_msgbuf _buf; |
| 1125 | struct pldm_msgbuf *buf = &_buf; |
| 1126 | int rc; |
| 1127 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1128 | if (msg == NULL || completion_code == NULL || |
| 1129 | platform_event_status == NULL) { |
| 1130 | return PLDM_ERROR_INVALID_DATA; |
| 1131 | } |
| 1132 | |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1133 | rc = pldm_msgbuf_init(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, |
| 1134 | msg->payload, payload_length); |
| 1135 | if (rc) { |
| 1136 | return rc; |
| 1137 | } |
| 1138 | |
| 1139 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 1140 | if (rc) { |
| 1141 | return rc; |
| 1142 | } |
| 1143 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1144 | if (PLDM_SUCCESS != *completion_code) { |
| 1145 | return PLDM_SUCCESS; |
| 1146 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1147 | |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1148 | rc = pldm_msgbuf_extract(buf, platform_event_status); |
| 1149 | if (rc) { |
| 1150 | return rc; |
| 1151 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1152 | |
| 1153 | if (*platform_event_status > PLDM_EVENT_LOGGING_REJECTED) { |
| 1154 | return PLDM_ERROR_INVALID_DATA; |
| 1155 | } |
| 1156 | |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1157 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1158 | } |
| 1159 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1160 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1161 | int encode_event_message_buffer_size_req(uint8_t instance_id, |
| 1162 | uint16_t event_receiver_max_buffer_size, |
| 1163 | struct pldm_msg *msg) |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1164 | { |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1165 | struct pldm_header_info header = { 0 }; |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1166 | header.msg_type = PLDM_REQUEST; |
| 1167 | header.instance = instance_id; |
| 1168 | header.pldm_type = PLDM_PLATFORM; |
| 1169 | header.command = PLDM_EVENT_MESSAGE_BUFFER_SIZE; |
| 1170 | |
| 1171 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1172 | if (rc != PLDM_SUCCESS) { |
| 1173 | return rc; |
| 1174 | } |
| 1175 | |
| 1176 | struct pldm_event_message_buffer_size_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1177 | (struct pldm_event_message_buffer_size_req *)msg->payload; |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1178 | request->event_receiver_max_buffer_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1179 | event_receiver_max_buffer_size; |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1180 | |
| 1181 | return PLDM_SUCCESS; |
| 1182 | } |
| 1183 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1184 | LIBPLDM_ABI_STABLE |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1185 | int decode_event_message_buffer_size_resp(const struct pldm_msg *msg, |
| 1186 | size_t payload_length, |
| 1187 | uint8_t *completion_code, |
| 1188 | uint16_t *terminus_max_buffer_size) |
| 1189 | { |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1190 | struct pldm_msgbuf _buf; |
| 1191 | struct pldm_msgbuf *buf = &_buf; |
| 1192 | int rc; |
| 1193 | |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1194 | if (msg == NULL || completion_code == NULL || |
| 1195 | terminus_max_buffer_size == NULL) { |
| 1196 | return PLDM_ERROR_INVALID_DATA; |
| 1197 | } |
| 1198 | |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1199 | rc = pldm_msgbuf_init(buf, PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES, |
| 1200 | msg->payload, payload_length); |
| 1201 | if (rc) { |
| 1202 | return rc; |
| 1203 | } |
| 1204 | |
| 1205 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 1206 | if (rc) { |
| 1207 | return rc; |
| 1208 | } |
| 1209 | |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1210 | if (PLDM_SUCCESS != *completion_code) { |
| 1211 | return PLDM_SUCCESS; |
| 1212 | } |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1213 | |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1214 | pldm_msgbuf_extract(buf, terminus_max_buffer_size); |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1215 | |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1216 | return pldm_msgbuf_destroy_consumed(buf); |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1217 | } |
| 1218 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1219 | LIBPLDM_ABI_STABLE |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1220 | int encode_event_message_supported_req(uint8_t instance_id, |
| 1221 | uint8_t format_version, |
| 1222 | struct pldm_msg *msg) |
| 1223 | { |
| 1224 | if (format_version != 1) { |
| 1225 | return PLDM_ERROR_INVALID_DATA; |
| 1226 | } |
| 1227 | |
| 1228 | if (msg == NULL) { |
| 1229 | return PLDM_ERROR_INVALID_DATA; |
| 1230 | } |
| 1231 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1232 | struct pldm_header_info header = { 0 }; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1233 | header.msg_type = PLDM_REQUEST; |
| 1234 | header.instance = instance_id; |
| 1235 | header.pldm_type = PLDM_PLATFORM; |
| 1236 | header.command = PLDM_EVENT_MESSAGE_SUPPORTED; |
| 1237 | |
| 1238 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1239 | if (rc != PLDM_SUCCESS) { |
| 1240 | return rc; |
| 1241 | } |
| 1242 | |
| 1243 | struct pldm_event_message_supported_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1244 | (struct pldm_event_message_supported_req *)msg->payload; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1245 | request->format_version = format_version; |
| 1246 | |
| 1247 | return PLDM_SUCCESS; |
| 1248 | } |
| 1249 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1250 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1251 | int decode_event_message_supported_resp(const struct pldm_msg *msg, |
| 1252 | size_t payload_length, |
| 1253 | uint8_t *completion_code, |
| 1254 | uint8_t *synchrony_config, |
| 1255 | bitfield8_t *synchrony_config_support, |
| 1256 | uint8_t *number_event_class_returned, |
| 1257 | uint8_t *event_class, |
| 1258 | uint8_t event_class_count) |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1259 | { |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1260 | struct pldm_msgbuf _buf; |
| 1261 | struct pldm_msgbuf *buf = &_buf; |
| 1262 | int i; |
| 1263 | int rc; |
| 1264 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1265 | if (msg == NULL || completion_code == NULL || |
| 1266 | synchrony_config == NULL || synchrony_config_support == NULL || |
| 1267 | number_event_class_returned == NULL || event_class == NULL) { |
| 1268 | return PLDM_ERROR_INVALID_DATA; |
| 1269 | } |
| 1270 | |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1271 | rc = pldm_msgbuf_init(buf, PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES, |
| 1272 | msg->payload, payload_length); |
| 1273 | if (rc) { |
| 1274 | return rc; |
| 1275 | } |
| 1276 | |
| 1277 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 1278 | if (rc) { |
| 1279 | return rc; |
| 1280 | } |
| 1281 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1282 | if (PLDM_SUCCESS != *completion_code) { |
| 1283 | return PLDM_SUCCESS; |
| 1284 | } |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1285 | |
| 1286 | rc = pldm_msgbuf_extract(buf, synchrony_config); |
| 1287 | if (rc) { |
| 1288 | return rc; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1291 | if (*synchrony_config > PLDM_MESSAGE_TYPE_ASYNCHRONOUS_WITH_HEARTBEAT) { |
| 1292 | return PLDM_ERROR_INVALID_DATA; |
| 1293 | } |
| 1294 | |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1295 | pldm_msgbuf_extract(buf, &synchrony_config_support->byte); |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1296 | |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1297 | rc = pldm_msgbuf_extract(buf, number_event_class_returned); |
| 1298 | if (rc) { |
| 1299 | return rc; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1302 | if (*number_event_class_returned == 0) { |
| 1303 | return pldm_msgbuf_destroy(buf); |
| 1304 | } |
| 1305 | |
| 1306 | if (event_class_count < *number_event_class_returned) { |
| 1307 | return PLDM_ERROR_INVALID_LENGTH; |
| 1308 | } |
| 1309 | |
| 1310 | for (i = 0; i < *number_event_class_returned; i++) { |
| 1311 | pldm_msgbuf_extract(buf, &event_class[i]); |
| 1312 | } |
| 1313 | |
| 1314 | return pldm_msgbuf_destroy_consumed(buf); |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1317 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1318 | int decode_sensor_event_data(const uint8_t *event_data, |
| 1319 | size_t event_data_length, uint16_t *sensor_id, |
| 1320 | uint8_t *sensor_event_class_type, |
| 1321 | size_t *event_class_data_offset) |
| 1322 | { |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1323 | struct pldm_msgbuf _buf; |
| 1324 | struct pldm_msgbuf *buf = &_buf; |
| 1325 | int rc; |
| 1326 | |
| 1327 | rc = pldm_msgbuf_init(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH, |
| 1328 | event_data, event_data_length); |
| 1329 | if (rc) { |
| 1330 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | size_t event_class_data_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1334 | event_data_length - PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1335 | |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1336 | pldm_msgbuf_extract(buf, sensor_id); |
| 1337 | rc = pldm_msgbuf_extract(buf, sensor_event_class_type); |
| 1338 | if (rc) { |
| 1339 | return rc; |
| 1340 | } |
| 1341 | |
| 1342 | if (*sensor_event_class_type == PLDM_SENSOR_OP_STATE) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1343 | if (event_class_data_length != |
| 1344 | PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH) { |
| 1345 | return PLDM_ERROR_INVALID_LENGTH; |
| 1346 | } |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1347 | } else if (*sensor_event_class_type == PLDM_STATE_SENSOR_STATE) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1348 | if (event_class_data_length != |
| 1349 | PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH) { |
| 1350 | return PLDM_ERROR_INVALID_LENGTH; |
| 1351 | } |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1352 | } else if (*sensor_event_class_type == PLDM_NUMERIC_SENSOR_STATE) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1353 | if (event_class_data_length < |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1354 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1355 | event_class_data_length > |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1356 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1357 | return PLDM_ERROR_INVALID_LENGTH; |
| 1358 | } |
| 1359 | } else { |
| 1360 | return PLDM_ERROR_INVALID_DATA; |
| 1361 | } |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1362 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1363 | *event_class_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1364 | sizeof(*sensor_id) + sizeof(*sensor_event_class_type); |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1365 | |
| 1366 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1367 | } |
| 1368 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1369 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1370 | int decode_sensor_op_data(const uint8_t *sensor_data, size_t sensor_data_length, |
| 1371 | uint8_t *present_op_state, uint8_t *previous_op_state) |
| 1372 | { |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1373 | struct pldm_msgbuf _buf; |
| 1374 | struct pldm_msgbuf *buf = &_buf; |
| 1375 | int rc; |
| 1376 | |
| 1377 | if (present_op_state == NULL || previous_op_state == NULL) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1378 | return PLDM_ERROR_INVALID_DATA; |
| 1379 | } |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1380 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1381 | rc = pldm_msgbuf_init(buf, |
| 1382 | PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH, |
| 1383 | sensor_data, sensor_data_length); |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1384 | if (rc) { |
| 1385 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1386 | } |
| 1387 | |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1388 | pldm_msgbuf_extract(buf, present_op_state); |
| 1389 | pldm_msgbuf_extract(buf, previous_op_state); |
| 1390 | |
| 1391 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1392 | } |
| 1393 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1394 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1395 | int decode_state_sensor_data(const uint8_t *sensor_data, |
| 1396 | size_t sensor_data_length, uint8_t *sensor_offset, |
| 1397 | uint8_t *event_state, |
| 1398 | uint8_t *previous_event_state) |
| 1399 | { |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1400 | struct pldm_msgbuf _buf; |
| 1401 | struct pldm_msgbuf *buf = &_buf; |
| 1402 | int rc; |
| 1403 | |
| 1404 | if (sensor_offset == NULL || event_state == NULL || |
| 1405 | previous_event_state == NULL) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1406 | return PLDM_ERROR_INVALID_DATA; |
| 1407 | } |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1408 | |
| 1409 | rc = pldm_msgbuf_init(buf, |
| 1410 | PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH, |
| 1411 | sensor_data, sensor_data_length); |
| 1412 | if (rc) { |
| 1413 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1414 | } |
| 1415 | |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1416 | pldm_msgbuf_extract(buf, sensor_offset); |
| 1417 | pldm_msgbuf_extract(buf, event_state); |
| 1418 | pldm_msgbuf_extract(buf, previous_event_state); |
| 1419 | |
| 1420 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1421 | } |
| 1422 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1423 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1424 | int decode_numeric_sensor_data(const uint8_t *sensor_data, |
| 1425 | size_t sensor_data_length, uint8_t *event_state, |
| 1426 | uint8_t *previous_event_state, |
| 1427 | uint8_t *sensor_data_size, |
| 1428 | uint32_t *present_reading) |
| 1429 | { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1430 | struct pldm_msgbuf _buf; |
| 1431 | struct pldm_msgbuf *buf = &_buf; |
| 1432 | int rc; |
| 1433 | |
| 1434 | if (sensor_data_size == NULL || event_state == NULL || |
| 1435 | previous_event_state == NULL || present_reading == NULL) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1436 | return PLDM_ERROR_INVALID_DATA; |
| 1437 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1438 | |
| 1439 | if (sensor_data_length > |
| 1440 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1441 | return PLDM_ERROR_INVALID_LENGTH; |
| 1442 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1443 | |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1444 | rc = pldm_msgbuf_init( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1445 | buf, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH, |
| 1446 | sensor_data, sensor_data_length); |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1447 | if (rc) { |
| 1448 | return rc; |
| 1449 | } |
| 1450 | |
| 1451 | pldm_msgbuf_extract(buf, event_state); |
| 1452 | pldm_msgbuf_extract(buf, previous_event_state); |
| 1453 | rc = pldm_msgbuf_extract(buf, sensor_data_size); |
| 1454 | if (rc) { |
| 1455 | return rc; |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * The implementation below is bonkers, but it's because the function |
| 1460 | * prototype is bonkers. The `present_reading` argument should have been |
| 1461 | * a tagged union. |
| 1462 | */ |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1463 | switch (*sensor_data_size) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1464 | case PLDM_SENSOR_DATA_SIZE_UINT8: { |
| 1465 | uint8_t val; |
| 1466 | if (!pldm_msgbuf_extract(buf, &val)) { |
| 1467 | *present_reading = (uint32_t)val; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1468 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1469 | break; |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1470 | } |
| 1471 | case PLDM_SENSOR_DATA_SIZE_SINT8: { |
| 1472 | int8_t val; |
| 1473 | if (!pldm_msgbuf_extract(buf, &val)) { |
| 1474 | *present_reading = (uint32_t)(int32_t)val; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1475 | } |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1476 | break; |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1477 | } |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1478 | case PLDM_SENSOR_DATA_SIZE_UINT16: { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1479 | uint16_t val; |
| 1480 | if (!pldm_msgbuf_extract(buf, &val)) { |
| 1481 | *present_reading = (uint32_t)val; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1482 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1483 | break; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1484 | } |
| 1485 | case PLDM_SENSOR_DATA_SIZE_SINT16: { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1486 | int16_t val; |
| 1487 | if (!pldm_msgbuf_extract(buf, &val)) { |
| 1488 | *present_reading = (uint32_t)(int32_t)val; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1489 | } |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1490 | break; |
| 1491 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1492 | case PLDM_SENSOR_DATA_SIZE_UINT32: { |
| 1493 | uint32_t val; |
| 1494 | if (!pldm_msgbuf_extract(buf, &val)) { |
| 1495 | *present_reading = (uint32_t)val; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1496 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1497 | break; |
| 1498 | } |
| 1499 | case PLDM_SENSOR_DATA_SIZE_SINT32: { |
| 1500 | int32_t val; |
| 1501 | if (!pldm_msgbuf_extract(buf, &val)) { |
| 1502 | *present_reading = (uint32_t)val; |
| 1503 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1504 | break; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1505 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1506 | default: |
| 1507 | return PLDM_ERROR_INVALID_DATA; |
| 1508 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1509 | |
| 1510 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1511 | } |
| 1512 | |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1513 | #define PLDM_NUMERIC_SENSOR_VALUE_PDR_MIN_SIZE 69 |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1514 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1515 | int decode_numeric_sensor_pdr_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1516 | const void *pdr_data, size_t pdr_data_length, |
| 1517 | struct pldm_numeric_sensor_value_pdr *pdr_value) |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1518 | { |
| 1519 | struct pldm_msgbuf _buf; |
| 1520 | struct pldm_msgbuf *buf = &_buf; |
| 1521 | int rc; |
| 1522 | |
| 1523 | rc = pldm_msgbuf_init(buf, PLDM_NUMERIC_SENSOR_VALUE_PDR_MIN_SIZE, |
| 1524 | pdr_data, pdr_data_length); |
| 1525 | if (rc) { |
| 1526 | return rc; |
| 1527 | } |
| 1528 | |
| 1529 | rc = pldm_msgbuf_extract_value_pdr_hdr(buf, &pdr_value->hdr); |
| 1530 | if (rc) { |
| 1531 | return rc; |
| 1532 | } |
| 1533 | |
| 1534 | rc = pldm_platform_pdr_hdr_validate( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1535 | &pdr_value->hdr, PLDM_NUMERIC_SENSOR_VALUE_PDR_MIN_SIZE, |
| 1536 | pdr_data_length); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1537 | if (rc) { |
| 1538 | return rc; |
| 1539 | } |
| 1540 | |
| 1541 | pldm_msgbuf_extract(buf, &pdr_value->terminus_handle); |
| 1542 | pldm_msgbuf_extract(buf, &pdr_value->sensor_id); |
| 1543 | pldm_msgbuf_extract(buf, &pdr_value->entity_type); |
| 1544 | pldm_msgbuf_extract(buf, &pdr_value->entity_instance_num); |
| 1545 | pldm_msgbuf_extract(buf, &pdr_value->container_id); |
| 1546 | pldm_msgbuf_extract(buf, &pdr_value->sensor_init); |
| 1547 | pldm_msgbuf_extract(buf, &pdr_value->sensor_auxiliary_names_pdr); |
| 1548 | pldm_msgbuf_extract(buf, &pdr_value->base_unit); |
| 1549 | pldm_msgbuf_extract(buf, &pdr_value->unit_modifier); |
| 1550 | pldm_msgbuf_extract(buf, &pdr_value->rate_unit); |
| 1551 | pldm_msgbuf_extract(buf, &pdr_value->base_oem_unit_handle); |
| 1552 | pldm_msgbuf_extract(buf, &pdr_value->aux_unit); |
| 1553 | pldm_msgbuf_extract(buf, &pdr_value->aux_unit_modifier); |
| 1554 | pldm_msgbuf_extract(buf, &pdr_value->aux_rate_unit); |
| 1555 | pldm_msgbuf_extract(buf, &pdr_value->rel); |
| 1556 | pldm_msgbuf_extract(buf, &pdr_value->aux_oem_unit_handle); |
| 1557 | pldm_msgbuf_extract(buf, &pdr_value->is_linear); |
| 1558 | |
| 1559 | rc = pldm_msgbuf_extract(buf, &pdr_value->sensor_data_size); |
| 1560 | if (rc) { |
| 1561 | return rc; |
| 1562 | } |
| 1563 | if (pdr_value->sensor_data_size > PLDM_SENSOR_DATA_SIZE_MAX) { |
| 1564 | return PLDM_ERROR_INVALID_DATA; |
| 1565 | } |
| 1566 | |
| 1567 | pldm_msgbuf_extract(buf, &pdr_value->resolution); |
| 1568 | pldm_msgbuf_extract(buf, &pdr_value->offset); |
| 1569 | pldm_msgbuf_extract(buf, &pdr_value->accuracy); |
| 1570 | pldm_msgbuf_extract(buf, &pdr_value->plus_tolerance); |
| 1571 | pldm_msgbuf_extract(buf, &pdr_value->minus_tolerance); |
| 1572 | pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size, |
| 1573 | &pdr_value->hysteresis); |
| 1574 | pldm_msgbuf_extract(buf, &pdr_value->supported_thresholds.byte); |
| 1575 | pldm_msgbuf_extract( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1576 | buf, &pdr_value->threshold_and_hysteresis_volatility.byte); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1577 | pldm_msgbuf_extract(buf, &pdr_value->state_transition_interval); |
| 1578 | pldm_msgbuf_extract(buf, &pdr_value->update_interval); |
| 1579 | pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size, |
| 1580 | &pdr_value->max_readable); |
| 1581 | pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size, |
| 1582 | &pdr_value->min_readable); |
| 1583 | |
| 1584 | rc = pldm_msgbuf_extract(buf, &pdr_value->range_field_format); |
| 1585 | if (rc) { |
| 1586 | return rc; |
| 1587 | } |
| 1588 | if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) { |
| 1589 | return PLDM_ERROR_INVALID_DATA; |
| 1590 | } |
| 1591 | |
| 1592 | pldm_msgbuf_extract(buf, &pdr_value->range_field_support.byte); |
| 1593 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1594 | buf, pdr_value->range_field_format, &pdr_value->nominal_value); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1595 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1596 | buf, pdr_value->range_field_format, &pdr_value->normal_max); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1597 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1598 | buf, pdr_value->range_field_format, &pdr_value->normal_min); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1599 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1600 | buf, pdr_value->range_field_format, &pdr_value->warning_high); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1601 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1602 | buf, pdr_value->range_field_format, &pdr_value->warning_low); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1603 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1604 | buf, pdr_value->range_field_format, &pdr_value->critical_high); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1605 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1606 | buf, pdr_value->range_field_format, &pdr_value->critical_low); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1607 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1608 | buf, pdr_value->range_field_format, &pdr_value->fatal_high); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1609 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1610 | buf, pdr_value->range_field_format, &pdr_value->fatal_low); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1611 | |
| 1612 | return pldm_msgbuf_destroy(buf); |
| 1613 | } |
| 1614 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1615 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1616 | int encode_get_numeric_effecter_value_req(uint8_t instance_id, |
| 1617 | uint16_t effecter_id, |
| 1618 | struct pldm_msg *msg) |
| 1619 | { |
| 1620 | if (msg == NULL) { |
| 1621 | return PLDM_ERROR_INVALID_DATA; |
| 1622 | } |
| 1623 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1624 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1625 | header.msg_type = PLDM_REQUEST; |
| 1626 | header.instance = instance_id; |
| 1627 | header.pldm_type = PLDM_PLATFORM; |
| 1628 | header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE; |
| 1629 | |
| 1630 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1631 | if (rc != PLDM_SUCCESS) { |
| 1632 | return rc; |
| 1633 | } |
| 1634 | |
| 1635 | struct pldm_get_numeric_effecter_value_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1636 | (struct pldm_get_numeric_effecter_value_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1637 | request->effecter_id = htole16(effecter_id); |
| 1638 | |
| 1639 | return PLDM_SUCCESS; |
| 1640 | } |
| 1641 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1642 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1643 | int encode_get_numeric_effecter_value_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1644 | uint8_t instance_id, uint8_t completion_code, |
| 1645 | uint8_t effecter_data_size, uint8_t effecter_oper_state, |
| 1646 | const uint8_t *pending_value, const uint8_t *present_value, |
| 1647 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1648 | { |
| 1649 | if (msg == NULL || pending_value == NULL || present_value == NULL) { |
| 1650 | return PLDM_ERROR_INVALID_DATA; |
| 1651 | } |
| 1652 | |
| 1653 | if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1654 | return PLDM_ERROR_INVALID_DATA; |
| 1655 | } |
| 1656 | |
| 1657 | if (effecter_oper_state > EFFECTER_OPER_STATE_INTEST) { |
| 1658 | return PLDM_ERROR_INVALID_DATA; |
| 1659 | } |
| 1660 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1661 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1662 | header.msg_type = PLDM_RESPONSE; |
| 1663 | header.instance = instance_id; |
| 1664 | header.pldm_type = PLDM_PLATFORM; |
| 1665 | header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE; |
| 1666 | |
| 1667 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1668 | if (rc != PLDM_SUCCESS) { |
| 1669 | return rc; |
| 1670 | } |
| 1671 | |
| 1672 | struct pldm_get_numeric_effecter_value_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1673 | (struct pldm_get_numeric_effecter_value_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1674 | |
| 1675 | response->completion_code = completion_code; |
| 1676 | response->effecter_data_size = effecter_data_size; |
| 1677 | response->effecter_oper_state = effecter_oper_state; |
| 1678 | |
| 1679 | if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 1680 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 1681 | if (payload_length != |
| 1682 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES) { |
| 1683 | return PLDM_ERROR_INVALID_LENGTH; |
| 1684 | } |
| 1685 | response->pending_and_present_values[0] = *pending_value; |
| 1686 | response->pending_and_present_values[1] = *present_value; |
| 1687 | |
| 1688 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1689 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 1690 | if (payload_length != |
| 1691 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) { |
| 1692 | return PLDM_ERROR_INVALID_LENGTH; |
| 1693 | } |
| 1694 | uint16_t val_pending = *(uint16_t *)pending_value; |
| 1695 | val_pending = htole16(val_pending); |
| 1696 | memcpy(response->pending_and_present_values, &val_pending, |
| 1697 | sizeof(uint16_t)); |
| 1698 | uint16_t val_present = *(uint16_t *)present_value; |
| 1699 | val_present = htole16(val_present); |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1700 | memcpy((response->pending_and_present_values + |
| 1701 | sizeof(uint16_t)), |
| 1702 | &val_present, sizeof(uint16_t)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1703 | |
| 1704 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1705 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1706 | if (payload_length != |
| 1707 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) { |
| 1708 | return PLDM_ERROR_INVALID_LENGTH; |
| 1709 | } |
| 1710 | uint32_t val_pending = *(uint32_t *)pending_value; |
| 1711 | val_pending = htole32(val_pending); |
| 1712 | memcpy(response->pending_and_present_values, &val_pending, |
| 1713 | sizeof(uint32_t)); |
| 1714 | uint32_t val_present = *(uint32_t *)present_value; |
| 1715 | val_present = htole32(val_present); |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1716 | memcpy((response->pending_and_present_values + |
| 1717 | sizeof(uint32_t)), |
| 1718 | &val_present, sizeof(uint32_t)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1719 | } |
| 1720 | return PLDM_SUCCESS; |
| 1721 | } |
| 1722 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1723 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1724 | int decode_get_numeric_effecter_value_req(const struct pldm_msg *msg, |
| 1725 | size_t payload_length, |
| 1726 | uint16_t *effecter_id) |
| 1727 | { |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1728 | struct pldm_msgbuf _buf; |
| 1729 | struct pldm_msgbuf *buf = &_buf; |
| 1730 | int rc; |
| 1731 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1732 | if (msg == NULL || effecter_id == NULL) { |
| 1733 | return PLDM_ERROR_INVALID_DATA; |
| 1734 | } |
| 1735 | |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1736 | rc = pldm_msgbuf_init(buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES, |
| 1737 | msg->payload, payload_length); |
| 1738 | if (rc) { |
| 1739 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1740 | } |
| 1741 | |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1742 | pldm_msgbuf_extract(buf, effecter_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1743 | |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1744 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1745 | } |
| 1746 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1747 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1748 | int decode_get_numeric_effecter_value_resp(const struct pldm_msg *msg, |
| 1749 | size_t payload_length, |
| 1750 | uint8_t *completion_code, |
| 1751 | uint8_t *effecter_data_size, |
| 1752 | uint8_t *effecter_oper_state, |
| 1753 | uint8_t *pending_value, |
| 1754 | uint8_t *present_value) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1755 | { |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1756 | struct pldm_msgbuf _buf; |
| 1757 | struct pldm_msgbuf *buf = &_buf; |
| 1758 | int rc; |
| 1759 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1760 | if (msg == NULL || effecter_data_size == NULL || |
| 1761 | effecter_oper_state == NULL || pending_value == NULL || |
| 1762 | present_value == NULL) { |
| 1763 | return PLDM_ERROR_INVALID_DATA; |
| 1764 | } |
| 1765 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1766 | rc = pldm_msgbuf_init(buf, |
| 1767 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES, |
| 1768 | msg->payload, payload_length); |
| 1769 | if (rc) { |
| 1770 | return rc; |
| 1771 | } |
| 1772 | |
| 1773 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 1774 | if (rc) { |
| 1775 | return rc; |
| 1776 | } |
| 1777 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1778 | if (PLDM_SUCCESS != *completion_code) { |
| 1779 | return PLDM_SUCCESS; |
| 1780 | } |
| 1781 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1782 | rc = pldm_msgbuf_extract(buf, effecter_data_size); |
| 1783 | if (rc) { |
| 1784 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1785 | } |
| 1786 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1787 | if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1788 | return PLDM_ERROR_INVALID_DATA; |
| 1789 | } |
| 1790 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1791 | rc = pldm_msgbuf_extract(buf, effecter_oper_state); |
| 1792 | if (rc) { |
| 1793 | return rc; |
| 1794 | } |
| 1795 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1796 | if (*effecter_oper_state > EFFECTER_OPER_STATE_INTEST) { |
| 1797 | return PLDM_ERROR_INVALID_DATA; |
| 1798 | } |
| 1799 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1800 | pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size, |
| 1801 | pending_value); |
| 1802 | pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size, |
| 1803 | present_value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1804 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1805 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1806 | } |
| 1807 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1808 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1809 | int encode_pldm_pdr_repository_chg_event_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1810 | uint8_t event_data_format, uint8_t number_of_change_records, |
| 1811 | const uint8_t *event_data_operations, |
| 1812 | const uint8_t *numbers_of_change_entries, |
| 1813 | const uint32_t *const *change_entries, |
| 1814 | struct pldm_pdr_repository_chg_event_data *event_data, |
| 1815 | size_t *actual_change_records_size, size_t max_change_records_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1816 | { |
| 1817 | if (event_data_operations == NULL || |
| 1818 | numbers_of_change_entries == NULL || change_entries == NULL) { |
| 1819 | return PLDM_ERROR_INVALID_DATA; |
| 1820 | } |
| 1821 | |
| 1822 | size_t expected_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1823 | sizeof(event_data_format) + sizeof(number_of_change_records); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1824 | |
| 1825 | expected_size += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1826 | sizeof(*event_data_operations) * number_of_change_records; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1827 | expected_size += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1828 | sizeof(*numbers_of_change_entries) * number_of_change_records; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1829 | |
| 1830 | for (uint8_t i = 0; i < number_of_change_records; ++i) { |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1831 | expected_size += sizeof(*change_entries[0]) * |
| 1832 | numbers_of_change_entries[i]; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | *actual_change_records_size = expected_size; |
| 1836 | |
| 1837 | if (event_data == NULL) { |
| 1838 | return PLDM_SUCCESS; |
| 1839 | } |
| 1840 | |
| 1841 | if (max_change_records_size < expected_size) { |
| 1842 | return PLDM_ERROR_INVALID_LENGTH; |
| 1843 | } |
| 1844 | |
| 1845 | event_data->event_data_format = event_data_format; |
| 1846 | event_data->number_of_change_records = number_of_change_records; |
| 1847 | |
| 1848 | struct pldm_pdr_repository_change_record_data *record_data = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1849 | (struct pldm_pdr_repository_change_record_data *) |
| 1850 | event_data->change_records; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1851 | |
| 1852 | for (uint8_t i = 0; i < number_of_change_records; ++i) { |
| 1853 | record_data->event_data_operation = event_data_operations[i]; |
| 1854 | record_data->number_of_change_entries = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1855 | numbers_of_change_entries[i]; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1856 | |
| 1857 | for (uint8_t j = 0; j < record_data->number_of_change_entries; |
| 1858 | ++j) { |
| 1859 | record_data->change_entry[j] = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1860 | htole32(change_entries[i][j]); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1861 | } |
| 1862 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1863 | record_data = |
| 1864 | (struct pldm_pdr_repository_change_record_data |
| 1865 | *)(record_data->change_entry + |
| 1866 | record_data->number_of_change_entries); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | return PLDM_SUCCESS; |
| 1870 | } |
| 1871 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1872 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1873 | int decode_pldm_pdr_repository_chg_event_data(const uint8_t *event_data, |
| 1874 | size_t event_data_size, |
| 1875 | uint8_t *event_data_format, |
| 1876 | uint8_t *number_of_change_records, |
| 1877 | size_t *change_record_data_offset) |
| 1878 | { |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 1879 | struct pldm_msgbuf _buf; |
| 1880 | struct pldm_msgbuf *buf = &_buf; |
| 1881 | int rc; |
| 1882 | |
| 1883 | if (event_data_format == NULL || number_of_change_records == NULL || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1884 | change_record_data_offset == NULL) { |
| 1885 | return PLDM_ERROR_INVALID_DATA; |
| 1886 | } |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 1887 | |
| 1888 | rc = pldm_msgbuf_init(buf, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH, |
| 1889 | event_data, event_data_size); |
| 1890 | if (rc) { |
| 1891 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1892 | } |
| 1893 | |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 1894 | pldm_msgbuf_extract(buf, event_data_format); |
| 1895 | pldm_msgbuf_extract(buf, number_of_change_records); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1896 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1897 | *change_record_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1898 | sizeof(*event_data_format) + sizeof(*number_of_change_records); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1899 | |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 1900 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1901 | } |
| 1902 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1903 | LIBPLDM_ABI_TESTING |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 1904 | int decode_pldm_message_poll_event_data(const uint8_t *event_data, |
| 1905 | size_t event_data_length, |
| 1906 | uint8_t *format_version, |
| 1907 | uint16_t *event_id, |
| 1908 | uint32_t *data_transfer_handle) |
| 1909 | { |
| 1910 | struct pldm_msgbuf _buf; |
| 1911 | struct pldm_msgbuf *buf = &_buf; |
| 1912 | int rc; |
| 1913 | |
| 1914 | if (event_data == NULL || format_version == NULL || event_id == NULL || |
| 1915 | data_transfer_handle == NULL) { |
| 1916 | return PLDM_ERROR_INVALID_DATA; |
| 1917 | } |
| 1918 | |
| 1919 | rc = pldm_msgbuf_init(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data, |
| 1920 | event_data_length); |
| 1921 | if (rc) { |
| 1922 | return rc; |
| 1923 | } |
| 1924 | |
| 1925 | pldm_msgbuf_extract(buf, format_version); |
| 1926 | rc = pldm_msgbuf_extract(buf, event_id); |
| 1927 | if (rc) { |
| 1928 | return rc; |
| 1929 | } |
| 1930 | |
| 1931 | if (*event_id == 0x0000 || *event_id == 0xffff) { |
| 1932 | return PLDM_ERROR_INVALID_DATA; |
| 1933 | } |
| 1934 | |
| 1935 | pldm_msgbuf_extract(buf, data_transfer_handle); |
| 1936 | |
| 1937 | return pldm_msgbuf_destroy_consumed(buf); |
| 1938 | } |
| 1939 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1940 | LIBPLDM_ABI_TESTING |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 1941 | int encode_pldm_message_poll_event_data(uint8_t format_version, |
| 1942 | uint16_t event_id, |
| 1943 | uint32_t data_transfer_handle, |
| 1944 | uint8_t *event_data, |
| 1945 | size_t event_data_length) |
| 1946 | { |
| 1947 | struct pldm_msgbuf _buf; |
| 1948 | struct pldm_msgbuf *buf = &_buf; |
| 1949 | int rc; |
| 1950 | |
| 1951 | if (event_data == NULL) { |
| 1952 | return PLDM_ERROR_INVALID_DATA; |
| 1953 | } |
| 1954 | |
| 1955 | if (event_id == 0x0000 || event_id == 0xffff) { |
| 1956 | return PLDM_ERROR_INVALID_DATA; |
| 1957 | } |
| 1958 | |
| 1959 | rc = pldm_msgbuf_init(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data, |
| 1960 | event_data_length); |
| 1961 | if (rc) { |
| 1962 | return rc; |
| 1963 | } |
| 1964 | pldm_msgbuf_insert(buf, format_version); |
| 1965 | pldm_msgbuf_insert(buf, event_id); |
| 1966 | pldm_msgbuf_insert(buf, data_transfer_handle); |
| 1967 | |
| 1968 | return pldm_msgbuf_destroy(buf); |
| 1969 | } |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1970 | |
| 1971 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1972 | int decode_pldm_pdr_repository_change_record_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1973 | const uint8_t *change_record_data, size_t change_record_data_size, |
| 1974 | uint8_t *event_data_operation, uint8_t *number_of_change_entries, |
| 1975 | size_t *change_entry_data_offset) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1976 | { |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 1977 | struct pldm_msgbuf _buf; |
| 1978 | struct pldm_msgbuf *buf = &_buf; |
| 1979 | int rc; |
| 1980 | |
| 1981 | if (event_data_operation == NULL || number_of_change_entries == NULL || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1982 | change_entry_data_offset == NULL) { |
| 1983 | return PLDM_ERROR_INVALID_DATA; |
| 1984 | } |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 1985 | |
| 1986 | rc = pldm_msgbuf_init(buf, PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH, |
| 1987 | change_record_data, change_record_data_size); |
| 1988 | if (rc) { |
| 1989 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1990 | } |
| 1991 | |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 1992 | pldm_msgbuf_extract(buf, event_data_operation); |
| 1993 | pldm_msgbuf_extract(buf, number_of_change_entries); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1994 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1995 | *change_entry_data_offset = sizeof(*event_data_operation) + |
| 1996 | sizeof(*number_of_change_entries); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1997 | |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 1998 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1999 | } |
| 2000 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2001 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2002 | int encode_get_sensor_reading_req(uint8_t instance_id, uint16_t sensor_id, |
| 2003 | uint8_t rearm_event_state, |
| 2004 | struct pldm_msg *msg) |
| 2005 | { |
| 2006 | if (msg == NULL) { |
| 2007 | return PLDM_ERROR_INVALID_DATA; |
| 2008 | } |
| 2009 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2010 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2011 | header.msg_type = PLDM_REQUEST; |
| 2012 | header.instance = instance_id; |
| 2013 | header.pldm_type = PLDM_PLATFORM; |
| 2014 | header.command = PLDM_GET_SENSOR_READING; |
| 2015 | |
| 2016 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2017 | if (rc != PLDM_SUCCESS) { |
| 2018 | return rc; |
| 2019 | } |
| 2020 | |
| 2021 | struct pldm_get_sensor_reading_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2022 | (struct pldm_get_sensor_reading_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2023 | |
| 2024 | request->sensor_id = htole16(sensor_id); |
| 2025 | request->rearm_event_state = rearm_event_state; |
| 2026 | |
| 2027 | return PLDM_SUCCESS; |
| 2028 | } |
| 2029 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2030 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2031 | int decode_get_sensor_reading_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2032 | const struct pldm_msg *msg, size_t payload_length, |
| 2033 | uint8_t *completion_code, uint8_t *sensor_data_size, |
| 2034 | uint8_t *sensor_operational_state, uint8_t *sensor_event_message_enable, |
| 2035 | uint8_t *present_state, uint8_t *previous_state, uint8_t *event_state, |
| 2036 | uint8_t *present_reading) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2037 | { |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2038 | struct pldm_msgbuf _buf; |
| 2039 | struct pldm_msgbuf *buf = &_buf; |
| 2040 | int rc; |
| 2041 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2042 | if (msg == NULL || completion_code == NULL || |
| 2043 | sensor_data_size == NULL || sensor_operational_state == NULL || |
| 2044 | sensor_event_message_enable == NULL || present_state == NULL || |
| 2045 | previous_state == NULL || event_state == NULL || |
| 2046 | present_reading == NULL) { |
| 2047 | return PLDM_ERROR_INVALID_DATA; |
| 2048 | } |
| 2049 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2050 | rc = pldm_msgbuf_init(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES, |
| 2051 | msg->payload, payload_length); |
| 2052 | if (rc) { |
| 2053 | return rc; |
| 2054 | } |
| 2055 | |
| 2056 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 2057 | if (rc) { |
| 2058 | return rc; |
| 2059 | } |
| 2060 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2061 | if (PLDM_SUCCESS != *completion_code) { |
| 2062 | return PLDM_SUCCESS; |
| 2063 | } |
| 2064 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2065 | rc = pldm_msgbuf_extract(buf, sensor_data_size); |
| 2066 | if (rc) { |
| 2067 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2068 | } |
| 2069 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2070 | if (*sensor_data_size > PLDM_SENSOR_DATA_SIZE_SINT32) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2071 | return PLDM_ERROR_INVALID_DATA; |
| 2072 | } |
| 2073 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2074 | pldm_msgbuf_extract(buf, sensor_operational_state); |
| 2075 | pldm_msgbuf_extract(buf, sensor_event_message_enable); |
| 2076 | pldm_msgbuf_extract(buf, present_state); |
| 2077 | pldm_msgbuf_extract(buf, previous_state); |
| 2078 | pldm_msgbuf_extract(buf, event_state); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2079 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2080 | pldm_msgbuf_extract_sensor_value(buf, *sensor_data_size, |
| 2081 | present_reading); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2082 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2083 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2084 | } |
| 2085 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2086 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2087 | int encode_get_sensor_reading_resp(uint8_t instance_id, uint8_t completion_code, |
| 2088 | uint8_t sensor_data_size, |
| 2089 | uint8_t sensor_operational_state, |
| 2090 | uint8_t sensor_event_message_enable, |
| 2091 | uint8_t present_state, |
| 2092 | uint8_t previous_state, uint8_t event_state, |
| 2093 | const uint8_t *present_reading, |
| 2094 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2095 | { |
| 2096 | if (msg == NULL || present_reading == NULL) { |
| 2097 | return PLDM_ERROR_INVALID_DATA; |
| 2098 | } |
| 2099 | |
| 2100 | if (sensor_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 2101 | return PLDM_ERROR_INVALID_DATA; |
| 2102 | } |
| 2103 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2104 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2105 | header.msg_type = PLDM_RESPONSE; |
| 2106 | header.instance = instance_id; |
| 2107 | header.pldm_type = PLDM_PLATFORM; |
| 2108 | header.command = PLDM_GET_SENSOR_READING; |
| 2109 | |
| 2110 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2111 | if (rc != PLDM_SUCCESS) { |
| 2112 | return rc; |
| 2113 | } |
| 2114 | |
| 2115 | struct pldm_get_sensor_reading_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2116 | (struct pldm_get_sensor_reading_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2117 | |
| 2118 | response->completion_code = completion_code; |
| 2119 | response->sensor_data_size = sensor_data_size; |
| 2120 | response->sensor_operational_state = sensor_operational_state; |
| 2121 | response->sensor_event_message_enable = sensor_event_message_enable; |
| 2122 | response->present_state = present_state; |
| 2123 | response->previous_state = previous_state; |
| 2124 | response->event_state = event_state; |
| 2125 | |
| 2126 | if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 2127 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 2128 | if (payload_length != PLDM_GET_SENSOR_READING_MIN_RESP_BYTES) { |
| 2129 | return PLDM_ERROR_INVALID_LENGTH; |
| 2130 | } |
| 2131 | response->present_reading[0] = *present_reading; |
| 2132 | |
| 2133 | } else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 2134 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 2135 | if (payload_length != |
| 2136 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1) { |
| 2137 | return PLDM_ERROR_INVALID_LENGTH; |
| 2138 | } |
| 2139 | uint16_t val = *(uint16_t *)present_reading; |
| 2140 | val = htole16(val); |
| 2141 | memcpy(response->present_reading, &val, 2); |
| 2142 | |
| 2143 | } else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 2144 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 2145 | if (payload_length != |
| 2146 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3) { |
| 2147 | return PLDM_ERROR_INVALID_LENGTH; |
| 2148 | } |
| 2149 | uint32_t val = *(uint32_t *)present_reading; |
| 2150 | val = htole32(val); |
| 2151 | memcpy(response->present_reading, &val, 4); |
| 2152 | } |
| 2153 | |
| 2154 | return PLDM_SUCCESS; |
| 2155 | } |
| 2156 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2157 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2158 | int decode_get_sensor_reading_req(const struct pldm_msg *msg, |
| 2159 | size_t payload_length, uint16_t *sensor_id, |
| 2160 | uint8_t *rearm_event_state) |
| 2161 | { |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2162 | struct pldm_msgbuf _buf; |
| 2163 | struct pldm_msgbuf *buf = &_buf; |
| 2164 | int rc; |
| 2165 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2166 | if (msg == NULL || sensor_id == NULL || rearm_event_state == NULL) { |
| 2167 | return PLDM_ERROR_INVALID_DATA; |
| 2168 | } |
| 2169 | |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2170 | rc = pldm_msgbuf_init(buf, PLDM_GET_SENSOR_READING_REQ_BYTES, |
| 2171 | msg->payload, payload_length); |
| 2172 | if (rc) { |
| 2173 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2174 | } |
| 2175 | |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2176 | pldm_msgbuf_extract(buf, sensor_id); |
| 2177 | pldm_msgbuf_extract(buf, rearm_event_state); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2178 | |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2179 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2180 | } |
| 2181 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2182 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2183 | int encode_set_event_receiver_req(uint8_t instance_id, |
| 2184 | uint8_t event_message_global_enable, |
| 2185 | uint8_t transport_protocol_type, |
| 2186 | uint8_t event_receiver_address_info, |
| 2187 | uint16_t heartbeat_timer, |
| 2188 | struct pldm_msg *msg) |
| 2189 | { |
| 2190 | if (msg == NULL) { |
| 2191 | return PLDM_ERROR_INVALID_DATA; |
| 2192 | } |
| 2193 | |
| 2194 | if (transport_protocol_type != PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) { |
| 2195 | return PLDM_ERROR_INVALID_DATA; |
| 2196 | } |
| 2197 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2198 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2199 | header.msg_type = PLDM_REQUEST; |
| 2200 | header.instance = instance_id; |
| 2201 | header.pldm_type = PLDM_PLATFORM; |
| 2202 | header.command = PLDM_SET_EVENT_RECEIVER; |
| 2203 | |
| 2204 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2205 | if (rc != PLDM_SUCCESS) { |
| 2206 | return rc; |
| 2207 | } |
| 2208 | |
| 2209 | struct pldm_set_event_receiver_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2210 | (struct pldm_set_event_receiver_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2211 | request->event_message_global_enable = event_message_global_enable; |
| 2212 | |
| 2213 | request->transport_protocol_type = transport_protocol_type; |
| 2214 | request->event_receiver_address_info = event_receiver_address_info; |
| 2215 | |
| 2216 | if (event_message_global_enable == |
| 2217 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) { |
| 2218 | if (heartbeat_timer == 0) { |
| 2219 | return PLDM_ERROR_INVALID_DATA; |
| 2220 | } |
| 2221 | request->heartbeat_timer = htole16(heartbeat_timer); |
| 2222 | } |
| 2223 | |
| 2224 | return PLDM_SUCCESS; |
| 2225 | } |
| 2226 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2227 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2228 | int decode_set_event_receiver_resp(const struct pldm_msg *msg, |
| 2229 | size_t payload_length, |
| 2230 | uint8_t *completion_code) |
| 2231 | { |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2232 | struct pldm_msgbuf _buf; |
| 2233 | struct pldm_msgbuf *buf = &_buf; |
| 2234 | int rc; |
| 2235 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2236 | if (msg == NULL || completion_code == NULL) { |
| 2237 | return PLDM_ERROR_INVALID_DATA; |
| 2238 | } |
| 2239 | |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2240 | rc = pldm_msgbuf_init(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES, |
| 2241 | msg->payload, payload_length); |
| 2242 | if (rc) { |
| 2243 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2244 | } |
| 2245 | |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2246 | pldm_msgbuf_extract(buf, completion_code); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2247 | |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2248 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2249 | } |
| 2250 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2251 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2252 | int decode_set_event_receiver_req(const struct pldm_msg *msg, |
| 2253 | size_t payload_length, |
| 2254 | uint8_t *event_message_global_enable, |
| 2255 | uint8_t *transport_protocol_type, |
| 2256 | uint8_t *event_receiver_address_info, |
| 2257 | uint16_t *heartbeat_timer) |
| 2258 | |
| 2259 | { |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2260 | struct pldm_msgbuf _buf; |
| 2261 | struct pldm_msgbuf *buf = &_buf; |
| 2262 | int rc; |
| 2263 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2264 | if (msg == NULL || event_message_global_enable == NULL || |
| 2265 | transport_protocol_type == NULL || |
| 2266 | event_receiver_address_info == NULL || heartbeat_timer == NULL) { |
| 2267 | return PLDM_ERROR_INVALID_DATA; |
| 2268 | } |
| 2269 | |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2270 | rc = pldm_msgbuf_init(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES, |
| 2271 | msg->payload, payload_length); |
| 2272 | if (rc) { |
| 2273 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2274 | } |
| 2275 | |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2276 | pldm_msgbuf_extract(buf, event_message_global_enable); |
| 2277 | pldm_msgbuf_extract(buf, transport_protocol_type); |
| 2278 | pldm_msgbuf_extract(buf, event_receiver_address_info); |
| 2279 | pldm_msgbuf_extract(buf, heartbeat_timer); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2280 | |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2281 | rc = pldm_msgbuf_destroy(buf); |
| 2282 | if (rc) { |
| 2283 | return rc; |
| 2284 | } |
Andrew Jeffery | 6ef2aa9 | 2023-04-14 00:21:27 +0930 | [diff] [blame] | 2285 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2286 | if ((*event_message_global_enable == |
| 2287 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) && |
| 2288 | (*heartbeat_timer == 0)) { |
| 2289 | return PLDM_ERROR_INVALID_DATA; |
| 2290 | } |
| 2291 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2292 | return PLDM_SUCCESS; |
| 2293 | } |
| 2294 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2295 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2296 | int encode_set_event_receiver_resp(uint8_t instance_id, uint8_t completion_code, |
| 2297 | struct pldm_msg *msg) |
| 2298 | |
| 2299 | { |
| 2300 | if (msg == NULL) { |
| 2301 | return PLDM_ERROR_INVALID_DATA; |
| 2302 | } |
| 2303 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2304 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2305 | header.instance = instance_id; |
| 2306 | header.msg_type = PLDM_RESPONSE; |
| 2307 | header.pldm_type = PLDM_PLATFORM; |
| 2308 | header.command = PLDM_SET_EVENT_RECEIVER; |
| 2309 | |
| 2310 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2311 | if (rc != PLDM_SUCCESS) { |
| 2312 | return rc; |
| 2313 | } |
| 2314 | |
| 2315 | msg->payload[0] = completion_code; |
| 2316 | |
| 2317 | return PLDM_SUCCESS; |
| 2318 | } |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2319 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2320 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2321 | int encode_poll_for_platform_event_message_req(uint8_t instance_id, |
| 2322 | uint8_t format_version, |
| 2323 | uint8_t transfer_operation_flag, |
| 2324 | uint32_t data_transfer_handle, |
| 2325 | uint16_t event_id_to_acknowledge, |
| 2326 | struct pldm_msg *msg, |
| 2327 | size_t payload_length) |
| 2328 | { |
| 2329 | struct pldm_msgbuf _buf; |
| 2330 | struct pldm_msgbuf *buf = &_buf; |
| 2331 | int rc; |
| 2332 | |
| 2333 | if (msg == NULL) { |
| 2334 | return PLDM_ERROR_INVALID_DATA; |
| 2335 | } |
| 2336 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2337 | struct pldm_header_info header = { 0 }; |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2338 | header.msg_type = PLDM_REQUEST; |
| 2339 | header.instance = instance_id; |
| 2340 | header.pldm_type = PLDM_PLATFORM; |
| 2341 | header.command = PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE; |
| 2342 | |
| 2343 | rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2344 | if (rc != PLDM_SUCCESS) { |
| 2345 | return rc; |
| 2346 | } |
| 2347 | |
| 2348 | rc = pldm_msgbuf_init( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2349 | buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES, |
| 2350 | msg->payload, payload_length); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2351 | if (rc) { |
| 2352 | return rc; |
| 2353 | } |
| 2354 | |
| 2355 | pldm_msgbuf_insert(buf, format_version); |
| 2356 | pldm_msgbuf_insert(buf, transfer_operation_flag); |
| 2357 | pldm_msgbuf_insert(buf, data_transfer_handle); |
| 2358 | pldm_msgbuf_insert(buf, event_id_to_acknowledge); |
| 2359 | |
| 2360 | return pldm_msgbuf_destroy(buf); |
| 2361 | } |
| 2362 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2363 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2364 | int decode_poll_for_platform_event_message_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2365 | const struct pldm_msg *msg, size_t payload_length, |
| 2366 | uint8_t *completion_code, uint8_t *tid, uint16_t *event_id, |
| 2367 | uint32_t *next_data_transfer_handle, uint8_t *transfer_flag, |
| 2368 | uint8_t *event_class, uint32_t *event_data_size, void **event_data, |
| 2369 | uint32_t *event_data_integrity_checksum) |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2370 | { |
| 2371 | struct pldm_msgbuf _buf; |
| 2372 | struct pldm_msgbuf *buf = &_buf; |
| 2373 | int rc; |
| 2374 | |
| 2375 | if (msg == NULL || completion_code == NULL || tid == NULL || |
| 2376 | event_id == NULL || next_data_transfer_handle == NULL || |
| 2377 | transfer_flag == NULL || event_class == NULL || |
| 2378 | event_data_size == NULL || event_data == NULL || |
| 2379 | event_data_integrity_checksum == NULL) { |
| 2380 | return PLDM_ERROR_INVALID_DATA; |
| 2381 | } |
| 2382 | |
| 2383 | rc = pldm_msgbuf_init( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2384 | buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES, |
| 2385 | msg->payload, payload_length); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2386 | if (rc) { |
| 2387 | return rc; |
| 2388 | } |
| 2389 | |
| 2390 | rc = pldm_msgbuf_extract(buf, completion_code); |
| 2391 | if (rc) { |
| 2392 | return rc; |
| 2393 | } |
| 2394 | if (PLDM_SUCCESS != *completion_code) { |
| 2395 | return *completion_code; |
| 2396 | } |
| 2397 | |
| 2398 | pldm_msgbuf_extract(buf, tid); |
| 2399 | rc = pldm_msgbuf_extract(buf, event_id); |
| 2400 | if (rc) { |
| 2401 | return rc; |
| 2402 | } |
| 2403 | if ((*event_id == 0) || (*event_id == 0xffff)) { |
| 2404 | return PLDM_SUCCESS; |
| 2405 | } |
| 2406 | |
| 2407 | pldm_msgbuf_extract(buf, next_data_transfer_handle); |
| 2408 | rc = pldm_msgbuf_extract(buf, transfer_flag); |
| 2409 | if (rc) { |
| 2410 | return rc; |
| 2411 | } |
| 2412 | |
| 2413 | pldm_msgbuf_extract(buf, event_class); |
| 2414 | rc = pldm_msgbuf_extract(buf, event_data_size); |
| 2415 | if (rc) { |
| 2416 | return rc; |
| 2417 | } |
| 2418 | if (*event_data_size > payload_length) { |
| 2419 | return PLDM_ERROR_INVALID_DATA; |
| 2420 | } |
| 2421 | |
| 2422 | if (*event_data_size > 0) { |
| 2423 | pldm_msgbuf_span_required(buf, *event_data_size, event_data); |
| 2424 | } |
| 2425 | |
| 2426 | if (*transfer_flag == PLDM_END || |
| 2427 | *transfer_flag == PLDM_START_AND_END) { |
| 2428 | pldm_msgbuf_extract(buf, event_data_integrity_checksum); |
| 2429 | } |
| 2430 | |
| 2431 | return pldm_msgbuf_destroy_consumed(buf); |
| 2432 | } |