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 */ |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2 | #include "dsp/base.h" |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 3 | #include "msgbuf.h" |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 4 | #include "msgbuf/platform.h" |
| 5 | |
| 6 | #include <libpldm/base.h> |
| 7 | #include <libpldm/platform.h> |
| 8 | #include <libpldm/pldm_types.h> |
| 9 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 10 | #include <endian.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 11 | #include <stdint.h> |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 12 | #include <stdlib.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 13 | #include <string.h> |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 14 | #include <uchar.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 15 | |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 16 | static int pldm_platform_pdr_hdr_validate(struct pldm_value_pdr_hdr *ctx, |
| 17 | size_t lower, size_t upper) |
| 18 | { |
| 19 | if (ctx->length + sizeof(*ctx) < lower) { |
| 20 | return PLDM_ERROR_INVALID_LENGTH; |
| 21 | } |
| 22 | |
| 23 | if (ctx->length > upper) { |
| 24 | return PLDM_ERROR_INVALID_LENGTH; |
| 25 | } |
| 26 | |
| 27 | return PLDM_SUCCESS; |
| 28 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 29 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 30 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 31 | int encode_state_effecter_pdr( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 32 | struct pldm_state_effecter_pdr *const effecter, |
| 33 | const size_t allocation_size, |
| 34 | const struct state_effecter_possible_states *const possible_states, |
| 35 | const size_t possible_states_size, size_t *const actual_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 36 | { |
| 37 | // Encode possible states |
| 38 | |
| 39 | size_t calculated_possible_states_size = 0; |
| 40 | |
| 41 | { |
| 42 | char *states_ptr = (char *)possible_states; |
| 43 | char *const begin_states_ptr = states_ptr; |
| 44 | |
| 45 | for (int i = 0; i < effecter->composite_effecter_count; ++i) { |
| 46 | struct state_effecter_possible_states *states = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 47 | (struct state_effecter_possible_states *) |
| 48 | states_ptr; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 49 | |
| 50 | HTOLE16(states->state_set_id); |
| 51 | |
| 52 | states_ptr += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 53 | (sizeof(*states) - sizeof(states->states) + |
| 54 | states->possible_states_size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | calculated_possible_states_size = states_ptr - begin_states_ptr; |
| 58 | } |
| 59 | |
| 60 | // Check lengths |
| 61 | |
| 62 | if (possible_states_size != calculated_possible_states_size) { |
| 63 | *actual_size = 0; |
| 64 | return PLDM_ERROR; |
| 65 | } |
| 66 | |
| 67 | *actual_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 68 | (sizeof(struct pldm_state_effecter_pdr) + possible_states_size - |
| 69 | sizeof(effecter->possible_states)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 70 | |
| 71 | if (allocation_size < *actual_size) { |
| 72 | *actual_size = 0; |
| 73 | return PLDM_ERROR_INVALID_LENGTH; |
| 74 | } |
| 75 | |
| 76 | // Encode rest of PDR |
| 77 | |
| 78 | effecter->hdr.version = 1; |
| 79 | effecter->hdr.type = PLDM_STATE_EFFECTER_PDR; |
| 80 | effecter->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr); |
| 81 | |
| 82 | memcpy(effecter->possible_states, possible_states, |
| 83 | possible_states_size); |
| 84 | |
| 85 | // Convert effecter PDR body |
| 86 | HTOLE16(effecter->terminus_handle); |
| 87 | HTOLE16(effecter->effecter_id); |
| 88 | HTOLE16(effecter->entity_type); |
| 89 | HTOLE16(effecter->entity_instance); |
| 90 | HTOLE16(effecter->container_id); |
| 91 | HTOLE16(effecter->effecter_semantic_id); |
| 92 | |
| 93 | // Convert header |
| 94 | HTOLE32(effecter->hdr.record_handle); |
| 95 | HTOLE16(effecter->hdr.record_change_num); |
| 96 | HTOLE16(effecter->hdr.length); |
| 97 | |
| 98 | return PLDM_SUCCESS; |
| 99 | } |
| 100 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 101 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 102 | int encode_state_sensor_pdr( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 103 | struct pldm_state_sensor_pdr *const sensor, |
| 104 | const size_t allocation_size, |
| 105 | const struct state_sensor_possible_states *const possible_states, |
| 106 | const size_t possible_states_size, size_t *const actual_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 107 | { |
| 108 | // Encode possible states |
| 109 | |
| 110 | size_t calculated_possible_states_size = 0; |
| 111 | |
| 112 | { |
Andrew Jeffery | fbe61d7 | 2023-04-05 20:28:23 +0930 | [diff] [blame] | 113 | char *states_ptr = (char *)possible_states; |
| 114 | char *const begin_states_ptr = states_ptr; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 115 | |
| 116 | for (int i = 0; i < sensor->composite_sensor_count; ++i) { |
| 117 | struct state_sensor_possible_states *states = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 118 | (struct state_sensor_possible_states *) |
| 119 | states_ptr; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 120 | |
| 121 | HTOLE16(states->state_set_id); |
| 122 | |
| 123 | states_ptr += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 124 | (sizeof(*states) - sizeof(states->states) + |
| 125 | states->possible_states_size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | calculated_possible_states_size = states_ptr - begin_states_ptr; |
| 129 | } |
| 130 | |
| 131 | // Check lengths |
| 132 | |
| 133 | if (possible_states_size != calculated_possible_states_size) { |
| 134 | *actual_size = 0; |
| 135 | return PLDM_ERROR; |
| 136 | } |
| 137 | |
| 138 | *actual_size = (sizeof(struct pldm_state_sensor_pdr) + |
| 139 | possible_states_size - sizeof(sensor->possible_states)); |
| 140 | |
| 141 | if (allocation_size < *actual_size) { |
| 142 | *actual_size = 0; |
| 143 | return PLDM_ERROR_INVALID_LENGTH; |
| 144 | } |
| 145 | |
| 146 | // Encode rest of PDR |
| 147 | |
| 148 | sensor->hdr.version = 1; |
| 149 | sensor->hdr.type = PLDM_STATE_SENSOR_PDR; |
| 150 | sensor->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr); |
| 151 | |
| 152 | memcpy(sensor->possible_states, possible_states, possible_states_size); |
| 153 | |
| 154 | // Convert sensor PDR body |
| 155 | HTOLE16(sensor->terminus_handle); |
| 156 | HTOLE16(sensor->sensor_id); |
| 157 | HTOLE16(sensor->entity_type); |
| 158 | HTOLE16(sensor->entity_instance); |
| 159 | HTOLE16(sensor->container_id); |
| 160 | |
| 161 | // Convert header |
| 162 | HTOLE32(sensor->hdr.record_handle); |
| 163 | HTOLE16(sensor->hdr.record_change_num); |
| 164 | HTOLE16(sensor->hdr.length); |
| 165 | |
| 166 | return PLDM_SUCCESS; |
| 167 | } |
| 168 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 169 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 170 | int encode_set_state_effecter_states_resp(uint8_t instance_id, |
| 171 | uint8_t completion_code, |
| 172 | struct pldm_msg *msg) |
| 173 | { |
| 174 | if (msg == NULL) { |
| 175 | return PLDM_ERROR_INVALID_DATA; |
| 176 | } |
| 177 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 178 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 179 | header.msg_type = PLDM_RESPONSE; |
| 180 | header.instance = instance_id; |
| 181 | header.pldm_type = PLDM_PLATFORM; |
| 182 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 183 | |
| 184 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 185 | if (rc != PLDM_SUCCESS) { |
| 186 | return rc; |
| 187 | } |
| 188 | |
| 189 | msg->payload[0] = completion_code; |
| 190 | |
| 191 | return PLDM_SUCCESS; |
| 192 | } |
| 193 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 194 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 195 | int encode_set_state_effecter_states_req(uint8_t instance_id, |
| 196 | uint16_t effecter_id, |
| 197 | uint8_t comp_effecter_count, |
| 198 | set_effecter_state_field *field, |
| 199 | struct pldm_msg *msg) |
| 200 | { |
| 201 | if (msg == NULL) { |
| 202 | return PLDM_ERROR_INVALID_DATA; |
| 203 | } |
| 204 | |
| 205 | if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8 || |
| 206 | field == NULL) { |
| 207 | return PLDM_ERROR_INVALID_DATA; |
| 208 | } |
| 209 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 210 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 211 | header.msg_type = PLDM_REQUEST; |
| 212 | header.instance = instance_id; |
| 213 | header.pldm_type = PLDM_PLATFORM; |
| 214 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 215 | |
| 216 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 217 | if (rc != PLDM_SUCCESS) { |
| 218 | return rc; |
| 219 | } |
| 220 | |
| 221 | struct pldm_set_state_effecter_states_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 222 | (struct pldm_set_state_effecter_states_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 223 | effecter_id = htole16(effecter_id); |
| 224 | request->effecter_id = effecter_id; |
| 225 | request->comp_effecter_count = comp_effecter_count; |
| 226 | memcpy(request->field, field, |
| 227 | (sizeof(set_effecter_state_field) * comp_effecter_count)); |
| 228 | |
| 229 | return PLDM_SUCCESS; |
| 230 | } |
| 231 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 232 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 233 | int decode_set_state_effecter_states_resp(const struct pldm_msg *msg, |
| 234 | size_t payload_length, |
| 235 | uint8_t *completion_code) |
| 236 | { |
| 237 | if (msg == NULL || completion_code == NULL) { |
| 238 | return PLDM_ERROR_INVALID_DATA; |
| 239 | } |
| 240 | |
| 241 | *completion_code = msg->payload[0]; |
| 242 | if (PLDM_SUCCESS != *completion_code) { |
| 243 | return PLDM_SUCCESS; |
| 244 | } |
| 245 | |
| 246 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) { |
| 247 | return PLDM_ERROR_INVALID_LENGTH; |
| 248 | } |
| 249 | |
| 250 | return PLDM_SUCCESS; |
| 251 | } |
| 252 | |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 253 | #define PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE 3 |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 254 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 255 | int decode_set_state_effecter_states_req(const struct pldm_msg *msg, |
| 256 | size_t payload_length, |
| 257 | uint16_t *effecter_id, |
| 258 | uint8_t *comp_effecter_count, |
| 259 | set_effecter_state_field *field) |
| 260 | { |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 261 | struct pldm_msgbuf _buf; |
| 262 | struct pldm_msgbuf *buf = &_buf; |
| 263 | int rc; |
| 264 | int i; |
| 265 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 266 | if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL || |
| 267 | field == NULL) { |
| 268 | return PLDM_ERROR_INVALID_DATA; |
| 269 | } |
| 270 | |
| 271 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) { |
| 272 | return PLDM_ERROR_INVALID_LENGTH; |
| 273 | } |
| 274 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 275 | rc = pldm_msgbuf_init_cc(buf, PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE, |
| 276 | msg->payload, payload_length); |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 277 | if (rc) { |
| 278 | return rc; |
| 279 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 280 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 281 | pldm_msgbuf_extract_p(buf, effecter_id); |
| 282 | pldm_msgbuf_extract_p(buf, comp_effecter_count); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 283 | |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 284 | if (*comp_effecter_count > 8) { |
| 285 | return PLDM_ERROR_INVALID_DATA; |
| 286 | } |
| 287 | |
| 288 | for (i = 0; i < *comp_effecter_count; i++) { |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 289 | pldm_msgbuf_extract(buf, field[i].set_request); |
| 290 | pldm_msgbuf_extract(buf, field[i].effecter_state); |
Andrew Jeffery | 5d773b3 | 2023-04-04 10:52:57 +0930 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 294 | } |
| 295 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 296 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 297 | int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length, |
| 298 | uint32_t *record_hndl, uint32_t *data_transfer_hndl, |
| 299 | uint8_t *transfer_op_flag, uint16_t *request_cnt, |
| 300 | uint16_t *record_chg_num) |
| 301 | { |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 302 | struct pldm_msgbuf _buf; |
| 303 | struct pldm_msgbuf *buf = &_buf; |
| 304 | int rc; |
| 305 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 306 | if (msg == NULL || record_hndl == NULL || data_transfer_hndl == NULL || |
| 307 | transfer_op_flag == NULL || request_cnt == NULL || |
| 308 | record_chg_num == NULL) { |
| 309 | return PLDM_ERROR_INVALID_DATA; |
| 310 | } |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 311 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 312 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 313 | return PLDM_ERROR_INVALID_LENGTH; |
| 314 | } |
| 315 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 316 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload, |
| 317 | payload_length); |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 318 | if (rc) { |
| 319 | return rc; |
| 320 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 321 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 322 | pldm_msgbuf_extract_p(buf, record_hndl); |
| 323 | pldm_msgbuf_extract_p(buf, data_transfer_hndl); |
| 324 | pldm_msgbuf_extract_p(buf, transfer_op_flag); |
| 325 | pldm_msgbuf_extract_p(buf, request_cnt); |
| 326 | pldm_msgbuf_extract_p(buf, record_chg_num); |
Andrew Jeffery | 891781e | 2023-04-04 11:04:18 +0930 | [diff] [blame] | 327 | |
| 328 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 329 | } |
| 330 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 331 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 332 | int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code, |
| 333 | uint32_t next_record_hndl, |
| 334 | uint32_t next_data_transfer_hndl, uint8_t transfer_flag, |
| 335 | uint16_t resp_cnt, const uint8_t *record_data, |
| 336 | uint8_t transfer_crc, struct pldm_msg *msg) |
| 337 | { |
| 338 | if (msg == NULL) { |
| 339 | return PLDM_ERROR_INVALID_DATA; |
| 340 | } |
| 341 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 342 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 343 | header.msg_type = PLDM_RESPONSE; |
| 344 | header.instance = instance_id; |
| 345 | header.pldm_type = PLDM_PLATFORM; |
| 346 | header.command = PLDM_GET_PDR; |
| 347 | |
| 348 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 349 | if (rc != PLDM_SUCCESS) { |
| 350 | return rc; |
| 351 | } |
| 352 | |
| 353 | struct pldm_get_pdr_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 354 | (struct pldm_get_pdr_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 355 | response->completion_code = completion_code; |
| 356 | |
| 357 | if (response->completion_code == PLDM_SUCCESS) { |
| 358 | response->next_record_handle = htole32(next_record_hndl); |
| 359 | response->next_data_transfer_handle = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 360 | htole32(next_data_transfer_hndl); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 361 | response->transfer_flag = transfer_flag; |
| 362 | response->response_count = htole16(resp_cnt); |
| 363 | if (record_data != NULL && resp_cnt > 0) { |
| 364 | memcpy(response->record_data, record_data, resp_cnt); |
| 365 | } |
| 366 | if (transfer_flag == PLDM_END) { |
| 367 | uint8_t *dst = msg->payload; |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 368 | dst += (sizeof(struct pldm_get_pdr_resp) - 1) + |
| 369 | resp_cnt; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 370 | *dst = transfer_crc; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return PLDM_SUCCESS; |
| 375 | } |
| 376 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 377 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 378 | int encode_get_pdr_repository_info_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 379 | uint8_t instance_id, uint8_t completion_code, uint8_t repository_state, |
| 380 | const uint8_t *update_time, const uint8_t *oem_update_time, |
| 381 | uint32_t record_count, uint32_t repository_size, |
| 382 | uint32_t largest_record_size, uint8_t data_transfer_handle_timeout, |
| 383 | struct pldm_msg *msg) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 384 | { |
| 385 | if (msg == NULL) { |
| 386 | return PLDM_ERROR_INVALID_DATA; |
| 387 | } |
| 388 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 389 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 390 | header.msg_type = PLDM_RESPONSE; |
| 391 | header.instance = instance_id; |
| 392 | header.pldm_type = PLDM_PLATFORM; |
| 393 | header.command = PLDM_GET_PDR_REPOSITORY_INFO; |
| 394 | |
| 395 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 396 | if (rc != PLDM_SUCCESS) { |
| 397 | return rc; |
| 398 | } |
| 399 | |
| 400 | struct pldm_pdr_repository_info_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 401 | (struct pldm_pdr_repository_info_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 402 | response->completion_code = completion_code; |
| 403 | |
| 404 | if (response->completion_code == PLDM_SUCCESS) { |
| 405 | response->repository_state = repository_state; |
| 406 | if (update_time != NULL) { |
| 407 | memcpy(response->update_time, update_time, |
| 408 | PLDM_TIMESTAMP104_SIZE); |
| 409 | } |
| 410 | if (oem_update_time != NULL) { |
| 411 | memcpy(response->oem_update_time, oem_update_time, |
| 412 | PLDM_TIMESTAMP104_SIZE); |
| 413 | } |
| 414 | response->record_count = htole32(record_count); |
| 415 | response->repository_size = htole32(repository_size); |
| 416 | response->largest_record_size = htole32(largest_record_size); |
| 417 | response->data_transfer_handle_timeout = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 418 | data_transfer_handle_timeout; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | return PLDM_SUCCESS; |
| 422 | } |
| 423 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 424 | LIBPLDM_ABI_DEPRECATED |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 425 | int decode_get_pdr_repository_info_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 426 | const struct pldm_msg *msg, size_t payload_length, |
| 427 | uint8_t *completion_code, uint8_t *repository_state, |
| 428 | uint8_t *update_time, uint8_t *oem_update_time, uint32_t *record_count, |
| 429 | uint32_t *repository_size, uint32_t *largest_record_size, |
| 430 | uint8_t *data_transfer_handle_timeout) |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 431 | { |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 432 | struct pldm_msgbuf _buf; |
| 433 | struct pldm_msgbuf *buf = &_buf; |
| 434 | int rc; |
| 435 | |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 436 | if (msg == NULL || completion_code == NULL || |
| 437 | repository_state == NULL || update_time == NULL || |
| 438 | oem_update_time == NULL || record_count == NULL || |
| 439 | repository_size == NULL || largest_record_size == NULL || |
| 440 | data_transfer_handle_timeout == NULL) { |
| 441 | return PLDM_ERROR_INVALID_DATA; |
| 442 | } |
| 443 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 444 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, |
| 445 | msg->payload, payload_length); |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 446 | if (rc) { |
| 447 | return rc; |
| 448 | } |
| 449 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 450 | pldm_msgbuf_extract_p(buf, completion_code); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 451 | if (PLDM_SUCCESS != *completion_code) { |
| 452 | return PLDM_SUCCESS; |
| 453 | } |
| 454 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 455 | pldm_msgbuf_extract_p(buf, repository_state); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 456 | if (*repository_state > PLDM_FAILED) { |
| 457 | return PLDM_ERROR_INVALID_DATA; |
| 458 | } |
| 459 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 460 | /* NOTE: Memory safety */ |
| 461 | rc = pldm_msgbuf_extract_array(buf, PLDM_TIMESTAMP104_SIZE, update_time, |
| 462 | PLDM_TIMESTAMP104_SIZE); |
| 463 | if (rc) { |
| 464 | return rc; |
| 465 | } |
| 466 | |
| 467 | /* NOTE: Memory safety */ |
| 468 | rc = pldm_msgbuf_extract_array(buf, PLDM_TIMESTAMP104_SIZE, |
| 469 | oem_update_time, PLDM_TIMESTAMP104_SIZE); |
| 470 | if (rc) { |
| 471 | return rc; |
| 472 | } |
| 473 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 474 | pldm_msgbuf_extract_p(buf, record_count); |
| 475 | pldm_msgbuf_extract_p(buf, repository_size); |
| 476 | pldm_msgbuf_extract_p(buf, largest_record_size); |
| 477 | pldm_msgbuf_extract_p(buf, data_transfer_handle_timeout); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 478 | |
Andrew Jeffery | 5c651b8 | 2023-04-04 11:37:56 +0930 | [diff] [blame] | 479 | return pldm_msgbuf_destroy(buf); |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 480 | } |
| 481 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 482 | LIBPLDM_ABI_TESTING |
| 483 | int decode_get_pdr_repository_info_resp_safe( |
| 484 | const struct pldm_msg *msg, size_t payload_length, |
| 485 | struct pldm_pdr_repository_info_resp *resp) |
| 486 | { |
| 487 | struct pldm_msgbuf _buf; |
| 488 | struct pldm_msgbuf *buf = &_buf; |
| 489 | int rc; |
| 490 | |
| 491 | if (msg == NULL || resp == NULL) { |
| 492 | return -EINVAL; |
| 493 | } |
| 494 | |
| 495 | rc = pldm_msg_has_error(msg, payload_length); |
| 496 | if (rc) { |
| 497 | resp->completion_code = rc; |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | rc = pldm_msgbuf_init_errno(buf, |
| 502 | PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, |
| 503 | msg->payload, payload_length); |
| 504 | if (rc) { |
| 505 | return rc; |
| 506 | } |
| 507 | |
| 508 | rc = pldm_msgbuf_extract(buf, resp->completion_code); |
| 509 | if (rc) { |
| 510 | return rc; |
| 511 | } |
| 512 | |
| 513 | pldm_msgbuf_extract(buf, resp->repository_state); |
| 514 | |
| 515 | rc = pldm_msgbuf_extract_array(buf, sizeof(resp->update_time), |
| 516 | resp->update_time, |
| 517 | sizeof(resp->update_time)); |
| 518 | if (rc) { |
| 519 | return rc; |
| 520 | } |
| 521 | |
| 522 | rc = pldm_msgbuf_extract_array(buf, sizeof(resp->oem_update_time), |
| 523 | resp->oem_update_time, |
| 524 | sizeof(resp->oem_update_time)); |
| 525 | if (rc) { |
| 526 | return rc; |
| 527 | } |
| 528 | |
| 529 | pldm_msgbuf_extract(buf, resp->record_count); |
| 530 | pldm_msgbuf_extract(buf, resp->repository_size); |
| 531 | pldm_msgbuf_extract(buf, resp->largest_record_size); |
| 532 | pldm_msgbuf_extract(buf, resp->data_transfer_handle_timeout); |
| 533 | |
| 534 | return pldm_msgbuf_destroy_consumed(buf); |
| 535 | } |
| 536 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 537 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 538 | int encode_get_pdr_req(uint8_t instance_id, uint32_t record_hndl, |
| 539 | uint32_t data_transfer_hndl, uint8_t transfer_op_flag, |
| 540 | uint16_t request_cnt, uint16_t record_chg_num, |
| 541 | struct pldm_msg *msg, size_t payload_length) |
| 542 | { |
| 543 | if (msg == NULL) { |
| 544 | return PLDM_ERROR_INVALID_DATA; |
| 545 | } |
| 546 | |
| 547 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 548 | return PLDM_ERROR_INVALID_LENGTH; |
| 549 | } |
| 550 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 551 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 552 | header.msg_type = PLDM_REQUEST; |
| 553 | header.instance = instance_id; |
| 554 | header.pldm_type = PLDM_PLATFORM; |
| 555 | header.command = PLDM_GET_PDR; |
| 556 | |
| 557 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 558 | if (rc != PLDM_SUCCESS) { |
| 559 | return rc; |
| 560 | } |
| 561 | |
| 562 | struct pldm_get_pdr_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 563 | (struct pldm_get_pdr_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 564 | request->record_handle = htole32(record_hndl); |
| 565 | request->data_transfer_handle = htole32(data_transfer_hndl); |
| 566 | request->transfer_op_flag = transfer_op_flag; |
| 567 | request->request_count = htole16(request_cnt); |
| 568 | request->record_change_number = htole16(record_chg_num); |
| 569 | |
| 570 | return PLDM_SUCCESS; |
| 571 | } |
| 572 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 573 | LIBPLDM_ABI_DEPRECATED |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 574 | int decode_get_pdr_resp(const struct pldm_msg *msg, size_t payload_length, |
| 575 | uint8_t *completion_code, uint32_t *next_record_hndl, |
| 576 | uint32_t *next_data_transfer_hndl, |
| 577 | uint8_t *transfer_flag, uint16_t *resp_cnt, |
| 578 | uint8_t *record_data, size_t record_data_length, |
| 579 | uint8_t *transfer_crc) |
| 580 | { |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 581 | struct pldm_msgbuf _buf; |
| 582 | struct pldm_msgbuf *buf = &_buf; |
| 583 | int rc; |
| 584 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 585 | if (msg == NULL || completion_code == NULL || |
| 586 | next_record_hndl == NULL || next_data_transfer_hndl == NULL || |
| 587 | transfer_flag == NULL || resp_cnt == NULL || transfer_crc == NULL) { |
| 588 | return PLDM_ERROR_INVALID_DATA; |
| 589 | } |
| 590 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 591 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload, |
| 592 | payload_length); |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 593 | if (rc) { |
| 594 | return rc; |
| 595 | } |
| 596 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 597 | pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 598 | if (PLDM_SUCCESS != *completion_code) { |
| 599 | return PLDM_SUCCESS; |
| 600 | } |
| 601 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 602 | pldm_msgbuf_extract_p(buf, next_record_hndl); |
| 603 | pldm_msgbuf_extract_p(buf, next_data_transfer_hndl); |
| 604 | pldm_msgbuf_extract_p(buf, transfer_flag); |
| 605 | rc = pldm_msgbuf_extract_p(buf, resp_cnt); |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 606 | if (rc) { |
| 607 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | if (*resp_cnt > 0 && record_data != NULL) { |
| 611 | if (record_data_length < *resp_cnt) { |
| 612 | return PLDM_ERROR_INVALID_LENGTH; |
| 613 | } |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 614 | /* NOTE: Memory safety */ |
| 615 | rc = pldm_msgbuf_extract_array(buf, *resp_cnt, record_data, |
| 616 | *resp_cnt); |
| 617 | if (rc) { |
| 618 | return rc; |
| 619 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | if (*transfer_flag == PLDM_END) { |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 623 | pldm_msgbuf_extract_p(buf, transfer_crc); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 624 | } |
| 625 | |
Andrew Jeffery | 4e5e8a2 | 2023-04-04 11:58:45 +0930 | [diff] [blame] | 626 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 627 | } |
| 628 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 629 | LIBPLDM_ABI_TESTING |
| 630 | int decode_get_pdr_resp_safe(const struct pldm_msg *msg, size_t payload_length, |
| 631 | struct pldm_get_pdr_resp *resp, size_t resp_len, |
| 632 | uint8_t *transfer_crc) |
| 633 | { |
| 634 | struct pldm_msgbuf _buf; |
| 635 | struct pldm_msgbuf *buf = &_buf; |
| 636 | int rc; |
| 637 | |
| 638 | if (msg == NULL || resp == NULL || transfer_crc == NULL) { |
| 639 | return -EINVAL; |
| 640 | } |
| 641 | |
| 642 | rc = pldm_msg_has_error(msg, payload_length); |
| 643 | if (rc) { |
| 644 | resp->completion_code = rc; |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_MIN_RESP_BYTES, |
| 649 | msg->payload, payload_length); |
| 650 | if (rc) { |
| 651 | return rc; |
| 652 | } |
| 653 | |
| 654 | pldm_msgbuf_extract(buf, resp->completion_code); |
| 655 | pldm_msgbuf_extract(buf, resp->next_record_handle); |
| 656 | pldm_msgbuf_extract(buf, resp->next_data_transfer_handle); |
| 657 | |
| 658 | rc = pldm_msgbuf_extract(buf, resp->transfer_flag); |
| 659 | if (rc) { |
| 660 | return rc; |
| 661 | } |
| 662 | |
| 663 | rc = pldm_msgbuf_extract(buf, resp->response_count); |
| 664 | if (rc) { |
| 665 | return rc; |
| 666 | } |
| 667 | |
| 668 | rc = pldm_msgbuf_extract_array( |
| 669 | buf, resp->response_count, resp->record_data, |
| 670 | resp_len - (sizeof(*resp) - sizeof(resp->record_data))); |
| 671 | if (rc) { |
| 672 | return rc; |
| 673 | } |
| 674 | |
| 675 | if (resp->transfer_flag == PLDM_END) { |
| 676 | pldm_msgbuf_extract_p(buf, transfer_crc); |
| 677 | } |
| 678 | |
| 679 | return pldm_msgbuf_destroy_consumed(buf); |
| 680 | } |
| 681 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 682 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 683 | int decode_set_numeric_effecter_value_req(const struct pldm_msg *msg, |
| 684 | size_t payload_length, |
| 685 | uint16_t *effecter_id, |
| 686 | uint8_t *effecter_data_size, |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 687 | uint8_t effecter_value[4]) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 688 | { |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 689 | struct pldm_msgbuf _buf; |
| 690 | struct pldm_msgbuf *buf = &_buf; |
| 691 | int rc; |
| 692 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 693 | if (msg == NULL || effecter_id == NULL || effecter_data_size == NULL || |
| 694 | effecter_value == NULL) { |
| 695 | return PLDM_ERROR_INVALID_DATA; |
| 696 | } |
| 697 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 698 | rc = pldm_msgbuf_init_cc(buf, |
| 699 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES, |
| 700 | msg->payload, payload_length); |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 701 | if (rc) { |
| 702 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 703 | } |
| 704 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 705 | pldm_msgbuf_extract_p(buf, effecter_id); |
| 706 | rc = pldm_msgbuf_extract_p(buf, effecter_data_size); |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 707 | if (rc) { |
| 708 | return PLDM_ERROR_INVALID_DATA; |
| 709 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 710 | |
| 711 | if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 712 | return PLDM_ERROR_INVALID_DATA; |
| 713 | } |
| 714 | |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 715 | pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size, |
| 716 | effecter_value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 717 | |
Andrew Jeffery | 3884c44 | 2023-04-12 11:13:24 +0930 | [diff] [blame] | 718 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 719 | } |
| 720 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 721 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 722 | int encode_set_numeric_effecter_value_resp(uint8_t instance_id, |
| 723 | uint8_t completion_code, |
| 724 | struct pldm_msg *msg, |
| 725 | size_t payload_length) |
| 726 | { |
| 727 | if (msg == NULL) { |
| 728 | return PLDM_ERROR_INVALID_DATA; |
| 729 | } |
| 730 | |
| 731 | if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) { |
| 732 | return PLDM_ERROR_INVALID_LENGTH; |
| 733 | } |
| 734 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 735 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 736 | header.msg_type = PLDM_RESPONSE; |
| 737 | header.instance = instance_id; |
| 738 | header.pldm_type = PLDM_PLATFORM; |
| 739 | header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE; |
| 740 | |
| 741 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 742 | if (rc != PLDM_SUCCESS) { |
| 743 | return rc; |
| 744 | } |
| 745 | |
| 746 | msg->payload[0] = completion_code; |
| 747 | |
| 748 | return rc; |
| 749 | } |
| 750 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 751 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 752 | int encode_set_numeric_effecter_value_req(uint8_t instance_id, |
| 753 | uint16_t effecter_id, |
| 754 | uint8_t effecter_data_size, |
| 755 | const uint8_t *effecter_value, |
| 756 | struct pldm_msg *msg, |
| 757 | size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 758 | { |
| 759 | if (msg == NULL || effecter_value == NULL) { |
| 760 | return PLDM_ERROR_INVALID_DATA; |
| 761 | } |
| 762 | |
| 763 | if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 764 | return PLDM_ERROR_INVALID_DATA; |
| 765 | } |
| 766 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 767 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 768 | header.msg_type = PLDM_REQUEST; |
| 769 | header.instance = instance_id; |
| 770 | header.pldm_type = PLDM_PLATFORM; |
| 771 | header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE; |
| 772 | |
| 773 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 774 | if (rc != PLDM_SUCCESS) { |
| 775 | return rc; |
| 776 | } |
| 777 | |
| 778 | struct pldm_set_numeric_effecter_value_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 779 | (struct pldm_set_numeric_effecter_value_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 780 | if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 781 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 782 | if (payload_length != |
| 783 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES) { |
| 784 | return PLDM_ERROR_INVALID_LENGTH; |
| 785 | } |
| 786 | request->effecter_value[0] = *effecter_value; |
| 787 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 788 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 789 | if (payload_length != |
| 790 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1) { |
| 791 | return PLDM_ERROR_INVALID_LENGTH; |
| 792 | } |
| 793 | |
| 794 | uint16_t val = *(uint16_t *)(effecter_value); |
| 795 | val = htole16(val); |
| 796 | memcpy(request->effecter_value, &val, sizeof(uint16_t)); |
| 797 | |
| 798 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 799 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 800 | if (payload_length != |
| 801 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3) { |
| 802 | return PLDM_ERROR_INVALID_LENGTH; |
| 803 | } |
| 804 | |
| 805 | uint32_t val = *(uint32_t *)(effecter_value); |
| 806 | val = htole32(val); |
| 807 | memcpy(request->effecter_value, &val, sizeof(uint32_t)); |
| 808 | } |
| 809 | |
| 810 | request->effecter_id = htole16(effecter_id); |
| 811 | request->effecter_data_size = effecter_data_size; |
| 812 | |
| 813 | return PLDM_SUCCESS; |
| 814 | } |
| 815 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 816 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 817 | int decode_set_numeric_effecter_value_resp(const struct pldm_msg *msg, |
| 818 | size_t payload_length, |
| 819 | uint8_t *completion_code) |
| 820 | { |
| 821 | if (msg == NULL || completion_code == NULL) { |
| 822 | return PLDM_ERROR_INVALID_DATA; |
| 823 | } |
| 824 | |
| 825 | if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) { |
| 826 | return PLDM_ERROR_INVALID_LENGTH; |
| 827 | } |
| 828 | |
| 829 | *completion_code = msg->payload[0]; |
| 830 | |
| 831 | return PLDM_SUCCESS; |
| 832 | } |
| 833 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 834 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 835 | int encode_get_state_sensor_readings_resp(uint8_t instance_id, |
| 836 | uint8_t completion_code, |
| 837 | uint8_t comp_sensor_count, |
| 838 | get_sensor_state_field *field, |
| 839 | struct pldm_msg *msg) |
| 840 | { |
| 841 | if (msg == NULL) { |
| 842 | return PLDM_ERROR_INVALID_DATA; |
| 843 | } |
| 844 | |
| 845 | if (comp_sensor_count < 0x1 || comp_sensor_count > 0x8) { |
| 846 | return PLDM_ERROR_INVALID_DATA; |
| 847 | } |
| 848 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 849 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 850 | header.msg_type = PLDM_RESPONSE; |
| 851 | header.instance = instance_id; |
| 852 | header.pldm_type = PLDM_PLATFORM; |
| 853 | header.command = PLDM_GET_STATE_SENSOR_READINGS; |
| 854 | |
| 855 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 856 | if (rc != PLDM_SUCCESS) { |
| 857 | return rc; |
| 858 | } |
| 859 | |
| 860 | struct pldm_get_state_sensor_readings_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 861 | (struct pldm_get_state_sensor_readings_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 862 | |
| 863 | response->completion_code = completion_code; |
| 864 | response->comp_sensor_count = comp_sensor_count; |
| 865 | memcpy(response->field, field, |
| 866 | (sizeof(get_sensor_state_field) * comp_sensor_count)); |
| 867 | |
| 868 | return PLDM_SUCCESS; |
| 869 | } |
| 870 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 871 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 872 | int encode_get_state_sensor_readings_req(uint8_t instance_id, |
| 873 | uint16_t sensor_id, |
| 874 | bitfield8_t sensor_rearm, |
| 875 | uint8_t reserved, struct pldm_msg *msg) |
| 876 | { |
| 877 | if (msg == NULL) { |
| 878 | return PLDM_ERROR_INVALID_DATA; |
| 879 | } |
| 880 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 881 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 882 | header.msg_type = PLDM_REQUEST; |
| 883 | header.instance = instance_id; |
| 884 | header.pldm_type = PLDM_PLATFORM; |
| 885 | header.command = PLDM_GET_STATE_SENSOR_READINGS; |
| 886 | |
| 887 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 888 | if (rc != PLDM_SUCCESS) { |
| 889 | return rc; |
| 890 | } |
| 891 | |
| 892 | struct pldm_get_state_sensor_readings_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 893 | (struct pldm_get_state_sensor_readings_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 894 | |
| 895 | request->sensor_id = htole16(sensor_id); |
| 896 | request->reserved = reserved; |
| 897 | request->sensor_rearm = sensor_rearm; |
| 898 | |
| 899 | return PLDM_SUCCESS; |
| 900 | } |
| 901 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 902 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 903 | int decode_get_state_sensor_readings_resp(const struct pldm_msg *msg, |
| 904 | size_t payload_length, |
| 905 | uint8_t *completion_code, |
| 906 | uint8_t *comp_sensor_count, |
| 907 | get_sensor_state_field *field) |
| 908 | { |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 909 | struct pldm_msgbuf _buf; |
| 910 | struct pldm_msgbuf *buf = &_buf; |
| 911 | uint8_t i; |
| 912 | int rc; |
| 913 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 914 | if (msg == NULL || completion_code == NULL || |
| 915 | comp_sensor_count == NULL || field == NULL) { |
| 916 | return PLDM_ERROR_INVALID_DATA; |
| 917 | } |
| 918 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 919 | rc = pldm_msgbuf_init_cc(buf, |
| 920 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES, |
| 921 | msg->payload, payload_length); |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 922 | if (rc) { |
| 923 | return rc; |
| 924 | } |
| 925 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 926 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 927 | if (rc) { |
| 928 | return rc; |
| 929 | } |
| 930 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 931 | if (PLDM_SUCCESS != *completion_code) { |
| 932 | return PLDM_SUCCESS; |
| 933 | } |
| 934 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 935 | rc = pldm_msgbuf_extract_p(buf, comp_sensor_count); |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 936 | if (rc) { |
| 937 | return rc; |
| 938 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 939 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 940 | if (*comp_sensor_count < 0x1 || *comp_sensor_count > 0x8) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 941 | return PLDM_ERROR_INVALID_DATA; |
| 942 | } |
| 943 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 944 | for (i = 0; i < *comp_sensor_count; i++) { |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 945 | pldm_msgbuf_extract(buf, field[i].sensor_op_state); |
| 946 | pldm_msgbuf_extract(buf, field[i].present_state); |
| 947 | pldm_msgbuf_extract(buf, field[i].previous_state); |
| 948 | pldm_msgbuf_extract(buf, field[i].event_state); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 949 | } |
| 950 | |
Andrew Jeffery | b0e22a7 | 2023-04-12 23:14:36 +0930 | [diff] [blame] | 951 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 952 | } |
| 953 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 954 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 955 | int decode_get_state_sensor_readings_req(const struct pldm_msg *msg, |
| 956 | size_t payload_length, |
| 957 | uint16_t *sensor_id, |
| 958 | bitfield8_t *sensor_rearm, |
| 959 | uint8_t *reserved) |
| 960 | { |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 961 | struct pldm_msgbuf _buf; |
| 962 | struct pldm_msgbuf *buf = &_buf; |
| 963 | int rc; |
| 964 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 965 | if (msg == NULL || sensor_id == NULL || sensor_rearm == NULL) { |
| 966 | return PLDM_ERROR_INVALID_DATA; |
| 967 | } |
| 968 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 969 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES, |
| 970 | msg->payload, payload_length); |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 971 | if (rc) { |
| 972 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 973 | } |
| 974 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 975 | pldm_msgbuf_extract_p(buf, sensor_id); |
| 976 | pldm_msgbuf_extract(buf, sensor_rearm->byte); |
| 977 | pldm_msgbuf_extract_p(buf, reserved); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 978 | |
Andrew Jeffery | f75aca6 | 2023-04-13 11:27:07 +0930 | [diff] [blame] | 979 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 980 | } |
| 981 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 982 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 983 | int encode_sensor_event_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 984 | struct pldm_sensor_event_data *const event_data, |
| 985 | const size_t event_data_size, const uint16_t sensor_id, |
| 986 | const enum sensor_event_class_states sensor_event_class, |
| 987 | const uint8_t sensor_offset, const uint8_t event_state, |
| 988 | const uint8_t previous_event_state, |
| 989 | size_t *const actual_event_data_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 990 | { |
| 991 | *actual_event_data_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 992 | (sizeof(*event_data) - sizeof(event_data->event_class) + |
| 993 | sizeof(struct pldm_sensor_event_state_sensor_state)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 994 | |
| 995 | if (!event_data) { |
| 996 | return PLDM_SUCCESS; |
| 997 | } |
| 998 | |
| 999 | if (event_data_size < *actual_event_data_size) { |
| 1000 | *actual_event_data_size = 0; |
| 1001 | return PLDM_ERROR_INVALID_LENGTH; |
| 1002 | } |
| 1003 | |
| 1004 | event_data->sensor_id = htole16(sensor_id); |
| 1005 | event_data->sensor_event_class_type = sensor_event_class; |
| 1006 | |
| 1007 | struct pldm_sensor_event_state_sensor_state *const state_data = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1008 | (struct pldm_sensor_event_state_sensor_state *) |
| 1009 | event_data->event_class; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1010 | |
| 1011 | state_data->sensor_offset = sensor_offset; |
| 1012 | state_data->event_state = event_state; |
| 1013 | state_data->previous_event_state = previous_event_state; |
| 1014 | |
| 1015 | return PLDM_SUCCESS; |
| 1016 | } |
| 1017 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1018 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1019 | int decode_platform_event_message_req(const struct pldm_msg *msg, |
| 1020 | size_t payload_length, |
| 1021 | uint8_t *format_version, uint8_t *tid, |
| 1022 | uint8_t *event_class, |
| 1023 | size_t *event_data_offset) |
| 1024 | { |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 1025 | struct pldm_msgbuf _buf; |
| 1026 | struct pldm_msgbuf *buf = &_buf; |
| 1027 | int rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1028 | |
| 1029 | if (msg == NULL || format_version == NULL || tid == NULL || |
| 1030 | event_class == NULL || event_data_offset == NULL) { |
| 1031 | return PLDM_ERROR_INVALID_DATA; |
| 1032 | } |
| 1033 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1034 | rc = pldm_msgbuf_init_cc(buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES, |
| 1035 | msg->payload, payload_length); |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 1036 | if (rc) { |
| 1037 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1038 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1039 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1040 | pldm_msgbuf_extract_p(buf, format_version); |
| 1041 | pldm_msgbuf_extract_p(buf, tid); |
| 1042 | pldm_msgbuf_extract_p(buf, event_class); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1043 | *event_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1044 | sizeof(*format_version) + sizeof(*tid) + sizeof(*event_class); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1045 | |
Andrew Jeffery | dc48ce3 | 2023-04-13 12:01:42 +0930 | [diff] [blame] | 1046 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1047 | } |
| 1048 | |
Thu Nguyen | 387b10f | 2024-09-24 11:33:16 +0000 | [diff] [blame] | 1049 | static int pldm_platform_poll_for_platform_event_message_validate( |
| 1050 | uint8_t transfer_operation_flag, uint16_t event_id_to_acknowledge) |
| 1051 | { |
| 1052 | if (((transfer_operation_flag == PLDM_GET_FIRSTPART) && |
| 1053 | (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_NULL)) || |
| 1054 | ((transfer_operation_flag == PLDM_GET_NEXTPART) && |
| 1055 | (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_FRAGMENT)) || |
| 1056 | ((transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY) && |
Thu Nguyen | 9e16b18 | 2024-10-01 03:12:16 +0000 | [diff] [blame] | 1057 | (event_id_to_acknowledge == PLDM_PLATFORM_EVENT_ID_FRAGMENT)) || |
| 1058 | ((transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY) && |
| 1059 | (event_id_to_acknowledge == PLDM_PLATFORM_EVENT_ID_NULL)) || |
Thu Nguyen | 387b10f | 2024-09-24 11:33:16 +0000 | [diff] [blame] | 1060 | (transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY)) { |
| 1061 | return -EPROTO; |
| 1062 | } |
| 1063 | |
| 1064 | return 0; |
| 1065 | } |
| 1066 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1067 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1068 | int decode_poll_for_platform_event_message_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1069 | const struct pldm_msg *msg, size_t payload_length, |
| 1070 | uint8_t *format_version, uint8_t *transfer_operation_flag, |
| 1071 | uint32_t *data_transfer_handle, uint16_t *event_id_to_acknowledge) |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1072 | { |
| 1073 | struct pldm_msgbuf _buf; |
| 1074 | struct pldm_msgbuf *buf = &_buf; |
| 1075 | int rc; |
| 1076 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 1077 | if (msg == NULL || format_version == NULL || |
| 1078 | transfer_operation_flag == NULL || data_transfer_handle == NULL || |
| 1079 | event_id_to_acknowledge == NULL) { |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1080 | return PLDM_ERROR_INVALID_DATA; |
| 1081 | } |
| 1082 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1083 | rc = pldm_msgbuf_init_cc(buf, |
| 1084 | PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES, |
| 1085 | msg->payload, payload_length); |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1086 | if (rc) { |
| 1087 | return rc; |
| 1088 | } |
| 1089 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1090 | pldm_msgbuf_extract_p(buf, format_version); |
| 1091 | rc = pldm_msgbuf_extract_p(buf, transfer_operation_flag); |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1092 | if (rc) { |
| 1093 | return rc; |
| 1094 | } |
| 1095 | if (*transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY) { |
| 1096 | return PLDM_ERROR_INVALID_DATA; |
| 1097 | } |
| 1098 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1099 | pldm_msgbuf_extract_p(buf, data_transfer_handle); |
| 1100 | rc = pldm_msgbuf_extract_p(buf, event_id_to_acknowledge); |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1101 | if (rc) { |
| 1102 | return rc; |
| 1103 | } |
| 1104 | |
Thu Nguyen | 387b10f | 2024-09-24 11:33:16 +0000 | [diff] [blame] | 1105 | rc = pldm_platform_poll_for_platform_event_message_validate( |
| 1106 | *transfer_operation_flag, *event_id_to_acknowledge); |
| 1107 | if (rc < 0) { |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1108 | return PLDM_ERROR_INVALID_DATA; |
| 1109 | } |
| 1110 | |
| 1111 | return pldm_msgbuf_destroy(buf); |
| 1112 | } |
| 1113 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1114 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1115 | int encode_platform_event_message_resp(uint8_t instance_id, |
| 1116 | uint8_t completion_code, |
| 1117 | uint8_t platform_event_status, |
| 1118 | struct pldm_msg *msg) |
| 1119 | { |
| 1120 | if (msg == NULL) { |
| 1121 | return PLDM_ERROR_INVALID_DATA; |
| 1122 | } |
| 1123 | |
| 1124 | if (platform_event_status > PLDM_EVENT_LOGGING_REJECTED) { |
| 1125 | return PLDM_ERROR_INVALID_DATA; |
| 1126 | } |
| 1127 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1128 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1129 | header.msg_type = PLDM_RESPONSE; |
| 1130 | header.instance = instance_id; |
| 1131 | header.pldm_type = PLDM_PLATFORM; |
| 1132 | header.command = PLDM_PLATFORM_EVENT_MESSAGE; |
| 1133 | |
| 1134 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1135 | if (rc != PLDM_SUCCESS) { |
| 1136 | return rc; |
| 1137 | } |
| 1138 | |
| 1139 | struct pldm_platform_event_message_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1140 | (struct pldm_platform_event_message_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1141 | response->completion_code = completion_code; |
| 1142 | response->platform_event_status = platform_event_status; |
| 1143 | |
| 1144 | return PLDM_SUCCESS; |
| 1145 | } |
| 1146 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1147 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1148 | int encode_poll_for_platform_event_message_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1149 | uint8_t instance_id, uint8_t completion_code, uint8_t tid, |
| 1150 | uint16_t event_id, uint32_t next_data_transfer_handle, |
| 1151 | uint8_t transfer_flag, uint8_t event_class, uint32_t event_data_size, |
| 1152 | uint8_t *event_data, uint32_t checksum, struct pldm_msg *msg, |
| 1153 | size_t payload_length) |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1154 | { |
| 1155 | struct pldm_msgbuf _buf; |
| 1156 | struct pldm_msgbuf *buf = &_buf; |
| 1157 | int rc; |
| 1158 | |
| 1159 | if (!msg) { |
| 1160 | return PLDM_ERROR_INVALID_DATA; |
| 1161 | } |
| 1162 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1163 | struct pldm_header_info header = { 0 }; |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1164 | header.msg_type = PLDM_RESPONSE; |
| 1165 | header.instance = instance_id; |
| 1166 | header.pldm_type = PLDM_PLATFORM; |
| 1167 | header.command = PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE; |
| 1168 | |
| 1169 | rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1170 | if (rc != PLDM_SUCCESS) { |
| 1171 | return rc; |
| 1172 | } |
| 1173 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1174 | rc = pldm_msgbuf_init_cc( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1175 | buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES, |
| 1176 | msg->payload, payload_length); |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1177 | if (rc) { |
| 1178 | return rc; |
| 1179 | } |
| 1180 | |
| 1181 | pldm_msgbuf_insert(buf, completion_code); |
| 1182 | pldm_msgbuf_insert(buf, tid); |
| 1183 | pldm_msgbuf_insert(buf, event_id); |
| 1184 | |
| 1185 | if (event_id == 0xffff || event_id == 0x0000) { |
| 1186 | if (PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES != |
| 1187 | payload_length) { |
| 1188 | return PLDM_ERROR_INVALID_LENGTH; |
| 1189 | } |
| 1190 | return pldm_msgbuf_destroy(buf); |
| 1191 | } |
| 1192 | |
| 1193 | if ((event_data == NULL) && (event_data_size > 0)) { |
| 1194 | return PLDM_ERROR_INVALID_DATA; |
| 1195 | } |
| 1196 | |
| 1197 | pldm_msgbuf_insert(buf, next_data_transfer_handle); |
| 1198 | pldm_msgbuf_insert(buf, transfer_flag); |
| 1199 | pldm_msgbuf_insert(buf, event_class); |
| 1200 | pldm_msgbuf_insert(buf, event_data_size); |
| 1201 | |
| 1202 | if ((event_data_size > 0) && event_data) { |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 1203 | rc = pldm_msgbuf_insert_array(buf, event_data_size, event_data, |
| 1204 | event_data_size); |
| 1205 | if (rc) { |
| 1206 | return rc; |
| 1207 | } |
Thu Nguyen | 8eb20f2 | 2022-11-16 22:34:55 +0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | if (transfer_flag == PLDM_END || transfer_flag == PLDM_START_AND_END) { |
| 1211 | pldm_msgbuf_insert(buf, checksum); |
| 1212 | } |
| 1213 | |
| 1214 | return pldm_msgbuf_destroy(buf); |
| 1215 | } |
| 1216 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1217 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1218 | int encode_platform_event_message_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1219 | uint8_t instance_id, uint8_t format_version, uint8_t tid, |
| 1220 | uint8_t event_class, const uint8_t *event_data, |
| 1221 | 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] | 1222 | |
| 1223 | { |
| 1224 | if (format_version != 1) { |
| 1225 | return PLDM_ERROR_INVALID_DATA; |
| 1226 | } |
| 1227 | |
| 1228 | if (msg == NULL || event_data == NULL) { |
| 1229 | return PLDM_ERROR_INVALID_DATA; |
| 1230 | } |
| 1231 | |
| 1232 | if (event_data_length == 0) { |
| 1233 | return PLDM_ERROR_INVALID_DATA; |
| 1234 | } |
| 1235 | |
| 1236 | if (payload_length != |
| 1237 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_length) { |
| 1238 | return PLDM_ERROR_INVALID_LENGTH; |
| 1239 | } |
| 1240 | |
John Chung | b43a778 | 2024-09-26 22:04:27 +0800 | [diff] [blame] | 1241 | if (event_class > PLDM_CPER_EVENT && |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1242 | !(event_class >= 0xf0 && event_class <= 0xfe)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1243 | return PLDM_ERROR_INVALID_DATA; |
| 1244 | } |
| 1245 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1246 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1247 | header.msg_type = PLDM_REQUEST; |
| 1248 | header.instance = instance_id; |
| 1249 | header.pldm_type = PLDM_PLATFORM; |
| 1250 | header.command = PLDM_PLATFORM_EVENT_MESSAGE; |
| 1251 | |
| 1252 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1253 | if (rc != PLDM_SUCCESS) { |
| 1254 | return rc; |
| 1255 | } |
| 1256 | |
| 1257 | struct pldm_platform_event_message_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1258 | (struct pldm_platform_event_message_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1259 | request->format_version = format_version; |
| 1260 | request->tid = tid; |
| 1261 | request->event_class = event_class; |
| 1262 | memcpy(request->event_data, event_data, event_data_length); |
| 1263 | |
| 1264 | return PLDM_SUCCESS; |
| 1265 | } |
| 1266 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1267 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1268 | int decode_platform_event_message_resp(const struct pldm_msg *msg, |
| 1269 | size_t payload_length, |
| 1270 | uint8_t *completion_code, |
| 1271 | uint8_t *platform_event_status) |
| 1272 | { |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1273 | struct pldm_msgbuf _buf; |
| 1274 | struct pldm_msgbuf *buf = &_buf; |
| 1275 | int rc; |
| 1276 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1277 | if (msg == NULL || completion_code == NULL || |
| 1278 | platform_event_status == NULL) { |
| 1279 | return PLDM_ERROR_INVALID_DATA; |
| 1280 | } |
| 1281 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1282 | rc = pldm_msgbuf_init_cc(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, |
| 1283 | msg->payload, payload_length); |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1284 | if (rc) { |
| 1285 | return rc; |
| 1286 | } |
| 1287 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1288 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1289 | if (rc) { |
| 1290 | return rc; |
| 1291 | } |
| 1292 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1293 | if (PLDM_SUCCESS != *completion_code) { |
| 1294 | return PLDM_SUCCESS; |
| 1295 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1296 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1297 | rc = pldm_msgbuf_extract_p(buf, platform_event_status); |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1298 | if (rc) { |
| 1299 | return rc; |
| 1300 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1301 | |
| 1302 | if (*platform_event_status > PLDM_EVENT_LOGGING_REJECTED) { |
| 1303 | return PLDM_ERROR_INVALID_DATA; |
| 1304 | } |
| 1305 | |
Andrew Jeffery | e501177 | 2023-04-13 12:06:22 +0930 | [diff] [blame] | 1306 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1307 | } |
| 1308 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1309 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1310 | int encode_event_message_buffer_size_req(uint8_t instance_id, |
| 1311 | uint16_t event_receiver_max_buffer_size, |
| 1312 | struct pldm_msg *msg) |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1313 | { |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1314 | struct pldm_header_info header = { 0 }; |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1315 | header.msg_type = PLDM_REQUEST; |
| 1316 | header.instance = instance_id; |
| 1317 | header.pldm_type = PLDM_PLATFORM; |
| 1318 | header.command = PLDM_EVENT_MESSAGE_BUFFER_SIZE; |
| 1319 | |
| 1320 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1321 | if (rc != PLDM_SUCCESS) { |
| 1322 | return rc; |
| 1323 | } |
| 1324 | |
| 1325 | struct pldm_event_message_buffer_size_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1326 | (struct pldm_event_message_buffer_size_req *)msg->payload; |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1327 | request->event_receiver_max_buffer_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1328 | event_receiver_max_buffer_size; |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1329 | |
| 1330 | return PLDM_SUCCESS; |
| 1331 | } |
| 1332 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1333 | LIBPLDM_ABI_STABLE |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1334 | int decode_event_message_buffer_size_resp(const struct pldm_msg *msg, |
| 1335 | size_t payload_length, |
| 1336 | uint8_t *completion_code, |
| 1337 | uint16_t *terminus_max_buffer_size) |
| 1338 | { |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1339 | struct pldm_msgbuf _buf; |
| 1340 | struct pldm_msgbuf *buf = &_buf; |
| 1341 | int rc; |
| 1342 | |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1343 | if (msg == NULL || completion_code == NULL || |
| 1344 | terminus_max_buffer_size == NULL) { |
| 1345 | return PLDM_ERROR_INVALID_DATA; |
| 1346 | } |
| 1347 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1348 | rc = pldm_msgbuf_init_cc(buf, PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES, |
| 1349 | msg->payload, payload_length); |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1350 | if (rc) { |
| 1351 | return rc; |
| 1352 | } |
| 1353 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1354 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1355 | if (rc) { |
| 1356 | return rc; |
| 1357 | } |
| 1358 | |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1359 | if (PLDM_SUCCESS != *completion_code) { |
| 1360 | return PLDM_SUCCESS; |
| 1361 | } |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1362 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1363 | pldm_msgbuf_extract_p(buf, terminus_max_buffer_size); |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1364 | |
Andrew Jeffery | 1112690 | 2023-04-13 12:12:10 +0930 | [diff] [blame] | 1365 | return pldm_msgbuf_destroy_consumed(buf); |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 1366 | } |
| 1367 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1368 | LIBPLDM_ABI_STABLE |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1369 | int encode_event_message_supported_req(uint8_t instance_id, |
| 1370 | uint8_t format_version, |
| 1371 | struct pldm_msg *msg) |
| 1372 | { |
| 1373 | if (format_version != 1) { |
| 1374 | return PLDM_ERROR_INVALID_DATA; |
| 1375 | } |
| 1376 | |
| 1377 | if (msg == NULL) { |
| 1378 | return PLDM_ERROR_INVALID_DATA; |
| 1379 | } |
| 1380 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1381 | struct pldm_header_info header = { 0 }; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1382 | header.msg_type = PLDM_REQUEST; |
| 1383 | header.instance = instance_id; |
| 1384 | header.pldm_type = PLDM_PLATFORM; |
| 1385 | header.command = PLDM_EVENT_MESSAGE_SUPPORTED; |
| 1386 | |
| 1387 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1388 | if (rc != PLDM_SUCCESS) { |
| 1389 | return rc; |
| 1390 | } |
| 1391 | |
| 1392 | struct pldm_event_message_supported_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1393 | (struct pldm_event_message_supported_req *)msg->payload; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1394 | request->format_version = format_version; |
| 1395 | |
| 1396 | return PLDM_SUCCESS; |
| 1397 | } |
| 1398 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1399 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1400 | int decode_event_message_supported_resp(const struct pldm_msg *msg, |
| 1401 | size_t payload_length, |
| 1402 | uint8_t *completion_code, |
| 1403 | uint8_t *synchrony_config, |
| 1404 | bitfield8_t *synchrony_config_support, |
| 1405 | uint8_t *number_event_class_returned, |
| 1406 | uint8_t *event_class, |
| 1407 | uint8_t event_class_count) |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1408 | { |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1409 | struct pldm_msgbuf _buf; |
| 1410 | struct pldm_msgbuf *buf = &_buf; |
| 1411 | int i; |
| 1412 | int rc; |
| 1413 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1414 | if (msg == NULL || completion_code == NULL || |
| 1415 | synchrony_config == NULL || synchrony_config_support == NULL || |
| 1416 | number_event_class_returned == NULL || event_class == NULL) { |
| 1417 | return PLDM_ERROR_INVALID_DATA; |
| 1418 | } |
| 1419 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1420 | rc = pldm_msgbuf_init_cc(buf, |
| 1421 | PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES, |
| 1422 | msg->payload, payload_length); |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1423 | if (rc) { |
| 1424 | return rc; |
| 1425 | } |
| 1426 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1427 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1428 | if (rc) { |
| 1429 | return rc; |
| 1430 | } |
| 1431 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1432 | if (PLDM_SUCCESS != *completion_code) { |
| 1433 | return PLDM_SUCCESS; |
| 1434 | } |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1435 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1436 | rc = pldm_msgbuf_extract_p(buf, synchrony_config); |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1437 | if (rc) { |
| 1438 | return rc; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1441 | if (*synchrony_config > PLDM_MESSAGE_TYPE_ASYNCHRONOUS_WITH_HEARTBEAT) { |
| 1442 | return PLDM_ERROR_INVALID_DATA; |
| 1443 | } |
| 1444 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1445 | pldm_msgbuf_extract_p(buf, &synchrony_config_support->byte); |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1446 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1447 | rc = pldm_msgbuf_extract_p(buf, number_event_class_returned); |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1448 | if (rc) { |
| 1449 | return rc; |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1452 | if (*number_event_class_returned == 0) { |
| 1453 | return pldm_msgbuf_destroy(buf); |
| 1454 | } |
| 1455 | |
| 1456 | if (event_class_count < *number_event_class_returned) { |
| 1457 | return PLDM_ERROR_INVALID_LENGTH; |
| 1458 | } |
| 1459 | |
| 1460 | for (i = 0; i < *number_event_class_returned; i++) { |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1461 | pldm_msgbuf_extract(buf, event_class[i]); |
Andrew Jeffery | 2d00ff8 | 2023-04-13 12:34:27 +0930 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | return pldm_msgbuf_destroy_consumed(buf); |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1465 | } |
| 1466 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1467 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1468 | int decode_sensor_event_data(const uint8_t *event_data, |
| 1469 | size_t event_data_length, uint16_t *sensor_id, |
| 1470 | uint8_t *sensor_event_class_type, |
| 1471 | size_t *event_class_data_offset) |
| 1472 | { |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1473 | struct pldm_msgbuf _buf; |
| 1474 | struct pldm_msgbuf *buf = &_buf; |
| 1475 | int rc; |
| 1476 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 1477 | if (event_data == NULL || sensor_id == NULL || |
| 1478 | sensor_event_class_type == NULL || |
| 1479 | event_class_data_offset == NULL) { |
| 1480 | return PLDM_ERROR_INVALID_DATA; |
| 1481 | } |
| 1482 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1483 | rc = pldm_msgbuf_init_cc(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH, |
| 1484 | event_data, event_data_length); |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1485 | if (rc) { |
| 1486 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | size_t event_class_data_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1490 | event_data_length - PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1491 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1492 | pldm_msgbuf_extract_p(buf, sensor_id); |
| 1493 | rc = pldm_msgbuf_extract_p(buf, sensor_event_class_type); |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1494 | if (rc) { |
| 1495 | return rc; |
| 1496 | } |
| 1497 | |
| 1498 | if (*sensor_event_class_type == PLDM_SENSOR_OP_STATE) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1499 | if (event_class_data_length != |
| 1500 | PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH) { |
| 1501 | return PLDM_ERROR_INVALID_LENGTH; |
| 1502 | } |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1503 | } else if (*sensor_event_class_type == PLDM_STATE_SENSOR_STATE) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1504 | if (event_class_data_length != |
| 1505 | PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH) { |
| 1506 | return PLDM_ERROR_INVALID_LENGTH; |
| 1507 | } |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1508 | } else if (*sensor_event_class_type == PLDM_NUMERIC_SENSOR_STATE) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1509 | if (event_class_data_length < |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1510 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1511 | event_class_data_length > |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1512 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1513 | return PLDM_ERROR_INVALID_LENGTH; |
| 1514 | } |
| 1515 | } else { |
| 1516 | return PLDM_ERROR_INVALID_DATA; |
| 1517 | } |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1518 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1519 | *event_class_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1520 | sizeof(*sensor_id) + sizeof(*sensor_event_class_type); |
Andrew Jeffery | 4fd4595 | 2023-04-13 13:01:45 +0930 | [diff] [blame] | 1521 | |
| 1522 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1523 | } |
| 1524 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1525 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1526 | int decode_sensor_op_data(const uint8_t *sensor_data, size_t sensor_data_length, |
| 1527 | uint8_t *present_op_state, uint8_t *previous_op_state) |
| 1528 | { |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1529 | struct pldm_msgbuf _buf; |
| 1530 | struct pldm_msgbuf *buf = &_buf; |
| 1531 | int rc; |
| 1532 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 1533 | if (sensor_data == NULL || present_op_state == NULL || |
| 1534 | previous_op_state == NULL) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1535 | return PLDM_ERROR_INVALID_DATA; |
| 1536 | } |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1537 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1538 | rc = pldm_msgbuf_init_cc(buf, |
| 1539 | PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH, |
| 1540 | sensor_data, sensor_data_length); |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1541 | if (rc) { |
| 1542 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1543 | } |
| 1544 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1545 | pldm_msgbuf_extract_p(buf, present_op_state); |
| 1546 | pldm_msgbuf_extract_p(buf, previous_op_state); |
Andrew Jeffery | 4888ee5 | 2023-04-13 13:14:05 +0930 | [diff] [blame] | 1547 | |
| 1548 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1549 | } |
| 1550 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1551 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1552 | int decode_state_sensor_data(const uint8_t *sensor_data, |
| 1553 | size_t sensor_data_length, uint8_t *sensor_offset, |
| 1554 | uint8_t *event_state, |
| 1555 | uint8_t *previous_event_state) |
| 1556 | { |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1557 | struct pldm_msgbuf _buf; |
| 1558 | struct pldm_msgbuf *buf = &_buf; |
| 1559 | int rc; |
| 1560 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 1561 | if (sensor_data == NULL || sensor_offset == NULL || |
| 1562 | event_state == NULL || previous_event_state == NULL) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1563 | return PLDM_ERROR_INVALID_DATA; |
| 1564 | } |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1565 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1566 | rc = pldm_msgbuf_init_cc( |
| 1567 | buf, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH, |
| 1568 | sensor_data, sensor_data_length); |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1569 | if (rc) { |
| 1570 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1571 | } |
| 1572 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1573 | pldm_msgbuf_extract_p(buf, sensor_offset); |
| 1574 | pldm_msgbuf_extract_p(buf, event_state); |
| 1575 | pldm_msgbuf_extract_p(buf, previous_event_state); |
Andrew Jeffery | 422790b | 2023-04-13 15:03:47 +0930 | [diff] [blame] | 1576 | |
| 1577 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1578 | } |
| 1579 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1580 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1581 | int decode_numeric_sensor_data(const uint8_t *sensor_data, |
| 1582 | size_t sensor_data_length, uint8_t *event_state, |
| 1583 | uint8_t *previous_event_state, |
| 1584 | uint8_t *sensor_data_size, |
| 1585 | uint32_t *present_reading) |
| 1586 | { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1587 | struct pldm_msgbuf _buf; |
| 1588 | struct pldm_msgbuf *buf = &_buf; |
| 1589 | int rc; |
| 1590 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 1591 | if (sensor_data == NULL || sensor_data_size == NULL || |
| 1592 | event_state == NULL || previous_event_state == NULL || |
| 1593 | present_reading == NULL) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1594 | return PLDM_ERROR_INVALID_DATA; |
| 1595 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1596 | |
| 1597 | if (sensor_data_length > |
| 1598 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1599 | return PLDM_ERROR_INVALID_LENGTH; |
| 1600 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1601 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1602 | rc = pldm_msgbuf_init_cc( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1603 | buf, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH, |
| 1604 | sensor_data, sensor_data_length); |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1605 | if (rc) { |
| 1606 | return rc; |
| 1607 | } |
| 1608 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1609 | pldm_msgbuf_extract_p(buf, event_state); |
| 1610 | pldm_msgbuf_extract_p(buf, previous_event_state); |
| 1611 | rc = pldm_msgbuf_extract_p(buf, sensor_data_size); |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1612 | if (rc) { |
| 1613 | return rc; |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * The implementation below is bonkers, but it's because the function |
| 1618 | * prototype is bonkers. The `present_reading` argument should have been |
| 1619 | * a tagged union. |
| 1620 | */ |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1621 | switch (*sensor_data_size) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1622 | case PLDM_SENSOR_DATA_SIZE_UINT8: { |
| 1623 | uint8_t val; |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1624 | if (!pldm_msgbuf_extract(buf, val)) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1625 | *present_reading = (uint32_t)val; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1626 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1627 | break; |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1628 | } |
| 1629 | case PLDM_SENSOR_DATA_SIZE_SINT8: { |
| 1630 | int8_t val; |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1631 | if (!pldm_msgbuf_extract(buf, val)) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1632 | *present_reading = (uint32_t)(int32_t)val; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1633 | } |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1634 | break; |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1635 | } |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1636 | case PLDM_SENSOR_DATA_SIZE_UINT16: { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1637 | uint16_t val; |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1638 | if (!pldm_msgbuf_extract(buf, val)) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1639 | *present_reading = (uint32_t)val; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1640 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1641 | break; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1642 | } |
| 1643 | case PLDM_SENSOR_DATA_SIZE_SINT16: { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1644 | int16_t val; |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1645 | if (!pldm_msgbuf_extract(buf, val)) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1646 | *present_reading = (uint32_t)(int32_t)val; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1647 | } |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1648 | break; |
| 1649 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1650 | case PLDM_SENSOR_DATA_SIZE_UINT32: { |
| 1651 | uint32_t val; |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1652 | if (!pldm_msgbuf_extract(buf, val)) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1653 | *present_reading = (uint32_t)val; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1654 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1655 | break; |
| 1656 | } |
| 1657 | case PLDM_SENSOR_DATA_SIZE_SINT32: { |
| 1658 | int32_t val; |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1659 | if (!pldm_msgbuf_extract(buf, val)) { |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1660 | *present_reading = (uint32_t)val; |
| 1661 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1662 | break; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1663 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1664 | default: |
| 1665 | return PLDM_ERROR_INVALID_DATA; |
| 1666 | } |
Andrew Jeffery | 155317e | 2023-04-13 18:36:51 +0930 | [diff] [blame] | 1667 | |
| 1668 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1669 | } |
| 1670 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1671 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1672 | int decode_numeric_sensor_pdr_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1673 | const void *pdr_data, size_t pdr_data_length, |
| 1674 | struct pldm_numeric_sensor_value_pdr *pdr_value) |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1675 | { |
| 1676 | struct pldm_msgbuf _buf; |
| 1677 | struct pldm_msgbuf *buf = &_buf; |
| 1678 | int rc; |
| 1679 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1680 | rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH, |
| 1681 | pdr_data, pdr_data_length); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1682 | if (rc) { |
| 1683 | return rc; |
| 1684 | } |
| 1685 | |
| 1686 | rc = pldm_msgbuf_extract_value_pdr_hdr(buf, &pdr_value->hdr); |
| 1687 | if (rc) { |
| 1688 | return rc; |
| 1689 | } |
| 1690 | |
| 1691 | rc = pldm_platform_pdr_hdr_validate( |
Thu Nguyen | 51230a0 | 2023-11-10 16:22:25 +0700 | [diff] [blame] | 1692 | &pdr_value->hdr, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH, |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1693 | pdr_data_length); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1694 | if (rc) { |
| 1695 | return rc; |
| 1696 | } |
| 1697 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1698 | pldm_msgbuf_extract(buf, pdr_value->terminus_handle); |
| 1699 | pldm_msgbuf_extract(buf, pdr_value->sensor_id); |
| 1700 | pldm_msgbuf_extract(buf, pdr_value->entity_type); |
| 1701 | pldm_msgbuf_extract(buf, pdr_value->entity_instance_num); |
| 1702 | pldm_msgbuf_extract(buf, pdr_value->container_id); |
| 1703 | pldm_msgbuf_extract(buf, pdr_value->sensor_init); |
| 1704 | pldm_msgbuf_extract(buf, pdr_value->sensor_auxiliary_names_pdr); |
| 1705 | pldm_msgbuf_extract(buf, pdr_value->base_unit); |
| 1706 | pldm_msgbuf_extract(buf, pdr_value->unit_modifier); |
| 1707 | pldm_msgbuf_extract(buf, pdr_value->rate_unit); |
| 1708 | pldm_msgbuf_extract(buf, pdr_value->base_oem_unit_handle); |
| 1709 | pldm_msgbuf_extract(buf, pdr_value->aux_unit); |
| 1710 | pldm_msgbuf_extract(buf, pdr_value->aux_unit_modifier); |
| 1711 | pldm_msgbuf_extract(buf, pdr_value->aux_rate_unit); |
| 1712 | pldm_msgbuf_extract(buf, pdr_value->rel); |
| 1713 | pldm_msgbuf_extract(buf, pdr_value->aux_oem_unit_handle); |
| 1714 | pldm_msgbuf_extract(buf, pdr_value->is_linear); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1715 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1716 | rc = pldm_msgbuf_extract(buf, pdr_value->sensor_data_size); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1717 | if (rc) { |
| 1718 | return rc; |
| 1719 | } |
| 1720 | if (pdr_value->sensor_data_size > PLDM_SENSOR_DATA_SIZE_MAX) { |
| 1721 | return PLDM_ERROR_INVALID_DATA; |
| 1722 | } |
| 1723 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1724 | pldm_msgbuf_extract(buf, pdr_value->resolution); |
| 1725 | pldm_msgbuf_extract(buf, pdr_value->offset); |
| 1726 | pldm_msgbuf_extract(buf, pdr_value->accuracy); |
| 1727 | pldm_msgbuf_extract(buf, pdr_value->plus_tolerance); |
| 1728 | pldm_msgbuf_extract(buf, pdr_value->minus_tolerance); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1729 | pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size, |
| 1730 | &pdr_value->hysteresis); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1731 | pldm_msgbuf_extract(buf, pdr_value->supported_thresholds.byte); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1732 | pldm_msgbuf_extract( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1733 | buf, pdr_value->threshold_and_hysteresis_volatility.byte); |
| 1734 | pldm_msgbuf_extract(buf, pdr_value->state_transition_interval); |
| 1735 | pldm_msgbuf_extract(buf, pdr_value->update_interval); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1736 | pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size, |
| 1737 | &pdr_value->max_readable); |
| 1738 | pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size, |
| 1739 | &pdr_value->min_readable); |
| 1740 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1741 | rc = pldm_msgbuf_extract(buf, pdr_value->range_field_format); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1742 | if (rc) { |
| 1743 | return rc; |
| 1744 | } |
| 1745 | if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) { |
| 1746 | return PLDM_ERROR_INVALID_DATA; |
| 1747 | } |
| 1748 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1749 | pldm_msgbuf_extract(buf, pdr_value->range_field_support.byte); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1750 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1751 | buf, pdr_value->range_field_format, pdr_value->nominal_value); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1752 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1753 | buf, pdr_value->range_field_format, pdr_value->normal_max); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1754 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1755 | buf, pdr_value->range_field_format, pdr_value->normal_min); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1756 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1757 | buf, pdr_value->range_field_format, pdr_value->warning_high); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1758 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1759 | buf, pdr_value->range_field_format, pdr_value->warning_low); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1760 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1761 | buf, pdr_value->range_field_format, pdr_value->critical_high); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1762 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1763 | buf, pdr_value->range_field_format, pdr_value->critical_low); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1764 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1765 | buf, pdr_value->range_field_format, pdr_value->fatal_high); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1766 | pldm_msgbuf_extract_range_field_format( |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1767 | buf, pdr_value->range_field_format, pdr_value->fatal_low); |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1768 | |
| 1769 | return pldm_msgbuf_destroy(buf); |
| 1770 | } |
| 1771 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1772 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1773 | int encode_get_numeric_effecter_value_req(uint8_t instance_id, |
| 1774 | uint16_t effecter_id, |
| 1775 | struct pldm_msg *msg) |
| 1776 | { |
| 1777 | if (msg == NULL) { |
| 1778 | return PLDM_ERROR_INVALID_DATA; |
| 1779 | } |
| 1780 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1781 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1782 | header.msg_type = PLDM_REQUEST; |
| 1783 | header.instance = instance_id; |
| 1784 | header.pldm_type = PLDM_PLATFORM; |
| 1785 | header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE; |
| 1786 | |
| 1787 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1788 | if (rc != PLDM_SUCCESS) { |
| 1789 | return rc; |
| 1790 | } |
| 1791 | |
| 1792 | struct pldm_get_numeric_effecter_value_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1793 | (struct pldm_get_numeric_effecter_value_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1794 | request->effecter_id = htole16(effecter_id); |
| 1795 | |
| 1796 | return PLDM_SUCCESS; |
| 1797 | } |
| 1798 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1799 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1800 | int encode_get_numeric_effecter_value_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1801 | uint8_t instance_id, uint8_t completion_code, |
| 1802 | uint8_t effecter_data_size, uint8_t effecter_oper_state, |
| 1803 | const uint8_t *pending_value, const uint8_t *present_value, |
| 1804 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1805 | { |
| 1806 | if (msg == NULL || pending_value == NULL || present_value == NULL) { |
| 1807 | return PLDM_ERROR_INVALID_DATA; |
| 1808 | } |
| 1809 | |
| 1810 | if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1811 | return PLDM_ERROR_INVALID_DATA; |
| 1812 | } |
| 1813 | |
| 1814 | if (effecter_oper_state > EFFECTER_OPER_STATE_INTEST) { |
| 1815 | return PLDM_ERROR_INVALID_DATA; |
| 1816 | } |
| 1817 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1818 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1819 | header.msg_type = PLDM_RESPONSE; |
| 1820 | header.instance = instance_id; |
| 1821 | header.pldm_type = PLDM_PLATFORM; |
| 1822 | header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE; |
| 1823 | |
| 1824 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1825 | if (rc != PLDM_SUCCESS) { |
| 1826 | return rc; |
| 1827 | } |
| 1828 | |
| 1829 | struct pldm_get_numeric_effecter_value_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1830 | (struct pldm_get_numeric_effecter_value_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1831 | |
| 1832 | response->completion_code = completion_code; |
| 1833 | response->effecter_data_size = effecter_data_size; |
| 1834 | response->effecter_oper_state = effecter_oper_state; |
| 1835 | |
| 1836 | if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 1837 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 1838 | if (payload_length != |
| 1839 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES) { |
| 1840 | return PLDM_ERROR_INVALID_LENGTH; |
| 1841 | } |
| 1842 | response->pending_and_present_values[0] = *pending_value; |
| 1843 | response->pending_and_present_values[1] = *present_value; |
| 1844 | |
| 1845 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1846 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 1847 | if (payload_length != |
| 1848 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) { |
| 1849 | return PLDM_ERROR_INVALID_LENGTH; |
| 1850 | } |
| 1851 | uint16_t val_pending = *(uint16_t *)pending_value; |
| 1852 | val_pending = htole16(val_pending); |
| 1853 | memcpy(response->pending_and_present_values, &val_pending, |
| 1854 | sizeof(uint16_t)); |
| 1855 | uint16_t val_present = *(uint16_t *)present_value; |
| 1856 | val_present = htole16(val_present); |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1857 | memcpy((response->pending_and_present_values + |
| 1858 | sizeof(uint16_t)), |
| 1859 | &val_present, sizeof(uint16_t)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1860 | |
| 1861 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1862 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1863 | if (payload_length != |
| 1864 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) { |
| 1865 | return PLDM_ERROR_INVALID_LENGTH; |
| 1866 | } |
| 1867 | uint32_t val_pending = *(uint32_t *)pending_value; |
| 1868 | val_pending = htole32(val_pending); |
| 1869 | memcpy(response->pending_and_present_values, &val_pending, |
| 1870 | sizeof(uint32_t)); |
| 1871 | uint32_t val_present = *(uint32_t *)present_value; |
| 1872 | val_present = htole32(val_present); |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1873 | memcpy((response->pending_and_present_values + |
| 1874 | sizeof(uint32_t)), |
| 1875 | &val_present, sizeof(uint32_t)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1876 | } |
| 1877 | return PLDM_SUCCESS; |
| 1878 | } |
| 1879 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1880 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1881 | int decode_get_numeric_effecter_value_req(const struct pldm_msg *msg, |
| 1882 | size_t payload_length, |
| 1883 | uint16_t *effecter_id) |
| 1884 | { |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1885 | struct pldm_msgbuf _buf; |
| 1886 | struct pldm_msgbuf *buf = &_buf; |
| 1887 | int rc; |
| 1888 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1889 | if (msg == NULL || effecter_id == NULL) { |
| 1890 | return PLDM_ERROR_INVALID_DATA; |
| 1891 | } |
| 1892 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1893 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES, |
| 1894 | msg->payload, payload_length); |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1895 | if (rc) { |
| 1896 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1897 | } |
| 1898 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1899 | pldm_msgbuf_extract_p(buf, effecter_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1900 | |
Andrew Jeffery | dd26582 | 2023-04-13 22:42:44 +0930 | [diff] [blame] | 1901 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1902 | } |
| 1903 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1904 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1905 | int decode_get_numeric_effecter_value_resp(const struct pldm_msg *msg, |
| 1906 | size_t payload_length, |
| 1907 | uint8_t *completion_code, |
| 1908 | uint8_t *effecter_data_size, |
| 1909 | uint8_t *effecter_oper_state, |
| 1910 | uint8_t *pending_value, |
| 1911 | uint8_t *present_value) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1912 | { |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1913 | struct pldm_msgbuf _buf; |
| 1914 | struct pldm_msgbuf *buf = &_buf; |
| 1915 | int rc; |
| 1916 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1917 | if (msg == NULL || effecter_data_size == NULL || |
| 1918 | effecter_oper_state == NULL || pending_value == NULL || |
| 1919 | present_value == NULL) { |
| 1920 | return PLDM_ERROR_INVALID_DATA; |
| 1921 | } |
| 1922 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 1923 | rc = pldm_msgbuf_init_cc(buf, |
| 1924 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES, |
| 1925 | msg->payload, payload_length); |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1926 | if (rc) { |
| 1927 | return rc; |
| 1928 | } |
| 1929 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1930 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1931 | if (rc) { |
| 1932 | return rc; |
| 1933 | } |
| 1934 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1935 | if (PLDM_SUCCESS != *completion_code) { |
| 1936 | return PLDM_SUCCESS; |
| 1937 | } |
| 1938 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1939 | rc = pldm_msgbuf_extract_p(buf, effecter_data_size); |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1940 | if (rc) { |
| 1941 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1942 | } |
| 1943 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1944 | if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1945 | return PLDM_ERROR_INVALID_DATA; |
| 1946 | } |
| 1947 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 1948 | rc = pldm_msgbuf_extract_p(buf, effecter_oper_state); |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1949 | if (rc) { |
| 1950 | return rc; |
| 1951 | } |
| 1952 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1953 | if (*effecter_oper_state > EFFECTER_OPER_STATE_INTEST) { |
| 1954 | return PLDM_ERROR_INVALID_DATA; |
| 1955 | } |
| 1956 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1957 | pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size, |
| 1958 | pending_value); |
| 1959 | pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size, |
| 1960 | present_value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1961 | |
Andrew Jeffery | 99c03f3 | 2023-04-13 22:45:30 +0930 | [diff] [blame] | 1962 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1963 | } |
| 1964 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1965 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1966 | int encode_pldm_pdr_repository_chg_event_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1967 | uint8_t event_data_format, uint8_t number_of_change_records, |
| 1968 | const uint8_t *event_data_operations, |
| 1969 | const uint8_t *numbers_of_change_entries, |
| 1970 | const uint32_t *const *change_entries, |
| 1971 | struct pldm_pdr_repository_chg_event_data *event_data, |
| 1972 | size_t *actual_change_records_size, size_t max_change_records_size) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1973 | { |
| 1974 | if (event_data_operations == NULL || |
| 1975 | numbers_of_change_entries == NULL || change_entries == NULL) { |
| 1976 | return PLDM_ERROR_INVALID_DATA; |
| 1977 | } |
| 1978 | |
| 1979 | size_t expected_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1980 | sizeof(event_data_format) + sizeof(number_of_change_records); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1981 | |
| 1982 | expected_size += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1983 | sizeof(*event_data_operations) * number_of_change_records; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1984 | expected_size += |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1985 | sizeof(*numbers_of_change_entries) * number_of_change_records; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1986 | |
| 1987 | for (uint8_t i = 0; i < number_of_change_records; ++i) { |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1988 | expected_size += sizeof(*change_entries[0]) * |
| 1989 | numbers_of_change_entries[i]; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | *actual_change_records_size = expected_size; |
| 1993 | |
| 1994 | if (event_data == NULL) { |
| 1995 | return PLDM_SUCCESS; |
| 1996 | } |
| 1997 | |
| 1998 | if (max_change_records_size < expected_size) { |
| 1999 | return PLDM_ERROR_INVALID_LENGTH; |
| 2000 | } |
| 2001 | |
| 2002 | event_data->event_data_format = event_data_format; |
| 2003 | event_data->number_of_change_records = number_of_change_records; |
| 2004 | |
| 2005 | struct pldm_pdr_repository_change_record_data *record_data = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2006 | (struct pldm_pdr_repository_change_record_data *) |
| 2007 | event_data->change_records; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2008 | |
| 2009 | for (uint8_t i = 0; i < number_of_change_records; ++i) { |
| 2010 | record_data->event_data_operation = event_data_operations[i]; |
| 2011 | record_data->number_of_change_entries = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2012 | numbers_of_change_entries[i]; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2013 | |
| 2014 | for (uint8_t j = 0; j < record_data->number_of_change_entries; |
| 2015 | ++j) { |
| 2016 | record_data->change_entry[j] = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2017 | htole32(change_entries[i][j]); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2018 | } |
| 2019 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2020 | record_data = |
| 2021 | (struct pldm_pdr_repository_change_record_data |
| 2022 | *)(record_data->change_entry + |
| 2023 | record_data->number_of_change_entries); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | return PLDM_SUCCESS; |
| 2027 | } |
| 2028 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2029 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2030 | int decode_pldm_pdr_repository_chg_event_data(const uint8_t *event_data, |
| 2031 | size_t event_data_size, |
| 2032 | uint8_t *event_data_format, |
| 2033 | uint8_t *number_of_change_records, |
| 2034 | size_t *change_record_data_offset) |
| 2035 | { |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 2036 | struct pldm_msgbuf _buf; |
| 2037 | struct pldm_msgbuf *buf = &_buf; |
| 2038 | int rc; |
| 2039 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2040 | if (event_data == NULL || event_data_format == NULL || |
| 2041 | number_of_change_records == NULL || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2042 | change_record_data_offset == NULL) { |
| 2043 | return PLDM_ERROR_INVALID_DATA; |
| 2044 | } |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 2045 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2046 | rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH, |
| 2047 | event_data, event_data_size); |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 2048 | if (rc) { |
| 2049 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2050 | } |
| 2051 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2052 | pldm_msgbuf_extract_p(buf, event_data_format); |
| 2053 | pldm_msgbuf_extract_p(buf, number_of_change_records); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2054 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2055 | *change_record_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2056 | sizeof(*event_data_format) + sizeof(*number_of_change_records); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2057 | |
Andrew Jeffery | 2fe7012 | 2023-04-13 23:21:31 +0930 | [diff] [blame] | 2058 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2059 | } |
| 2060 | |
Thu Nguyen | f874b38 | 2024-07-24 11:22:34 +0000 | [diff] [blame] | 2061 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2062 | int decode_pldm_message_poll_event_data( |
| 2063 | const void *event_data, size_t event_data_length, |
| 2064 | struct pldm_message_poll_event *poll_event) |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2065 | { |
| 2066 | struct pldm_msgbuf _buf; |
| 2067 | struct pldm_msgbuf *buf = &_buf; |
| 2068 | int rc; |
| 2069 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2070 | if (!event_data || !poll_event) { |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2071 | return -EINVAL; |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2074 | rc = pldm_msgbuf_init_errno(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data, |
| 2075 | event_data_length); |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2076 | if (rc) { |
| 2077 | return rc; |
| 2078 | } |
| 2079 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2080 | pldm_msgbuf_extract(buf, poll_event->format_version); |
| 2081 | rc = pldm_msgbuf_extract(buf, poll_event->event_id); |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2082 | if (rc) { |
| 2083 | return rc; |
| 2084 | } |
| 2085 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2086 | if (poll_event->event_id == 0x0000 || poll_event->event_id == 0xffff) { |
| 2087 | return -EPROTO; |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2090 | pldm_msgbuf_extract(buf, poll_event->data_transfer_handle); |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2091 | |
| 2092 | return pldm_msgbuf_destroy_consumed(buf); |
| 2093 | } |
| 2094 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2095 | LIBPLDM_ABI_TESTING |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2096 | int encode_pldm_message_poll_event_data( |
| 2097 | const struct pldm_message_poll_event *poll_event, void *event_data, |
| 2098 | size_t event_data_length) |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2099 | { |
| 2100 | struct pldm_msgbuf _buf; |
| 2101 | struct pldm_msgbuf *buf = &_buf; |
| 2102 | int rc; |
| 2103 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2104 | if (poll_event == NULL || event_data == NULL) { |
| 2105 | return -EINVAL; |
| 2106 | } |
| 2107 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2108 | if (poll_event->event_id == 0x0000 || poll_event->event_id == 0xffff) { |
| 2109 | return -EPROTO; |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2112 | rc = pldm_msgbuf_init_errno(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data, |
| 2113 | event_data_length); |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2114 | if (rc) { |
| 2115 | return rc; |
| 2116 | } |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2117 | pldm_msgbuf_insert(buf, poll_event->format_version); |
| 2118 | pldm_msgbuf_insert(buf, poll_event->event_id); |
| 2119 | pldm_msgbuf_insert(buf, poll_event->data_transfer_handle); |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2120 | |
Thu Nguyen | 7739d12 | 2024-07-26 11:36:39 +0000 | [diff] [blame] | 2121 | return pldm_msgbuf_destroy_consumed(buf); |
Dung Cao | 7c25034 | 2022-11-16 22:40:37 +0700 | [diff] [blame] | 2122 | } |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2123 | |
| 2124 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2125 | int decode_pldm_pdr_repository_change_record_data( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2126 | const uint8_t *change_record_data, size_t change_record_data_size, |
| 2127 | uint8_t *event_data_operation, uint8_t *number_of_change_entries, |
| 2128 | size_t *change_entry_data_offset) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2129 | { |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 2130 | struct pldm_msgbuf _buf; |
| 2131 | struct pldm_msgbuf *buf = &_buf; |
| 2132 | int rc; |
| 2133 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2134 | if (change_record_data == NULL || event_data_operation == NULL || |
| 2135 | number_of_change_entries == NULL || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2136 | change_entry_data_offset == NULL) { |
| 2137 | return PLDM_ERROR_INVALID_DATA; |
| 2138 | } |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 2139 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2140 | rc = pldm_msgbuf_init_cc(buf, |
| 2141 | PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH, |
| 2142 | change_record_data, change_record_data_size); |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 2143 | if (rc) { |
| 2144 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2145 | } |
| 2146 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2147 | pldm_msgbuf_extract_p(buf, event_data_operation); |
| 2148 | pldm_msgbuf_extract_p(buf, number_of_change_entries); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2149 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2150 | *change_entry_data_offset = sizeof(*event_data_operation) + |
| 2151 | sizeof(*number_of_change_entries); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2152 | |
Andrew Jeffery | 61cab6f | 2023-04-13 23:28:48 +0930 | [diff] [blame] | 2153 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2154 | } |
| 2155 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2156 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2157 | int encode_get_sensor_reading_req(uint8_t instance_id, uint16_t sensor_id, |
| 2158 | uint8_t rearm_event_state, |
| 2159 | struct pldm_msg *msg) |
| 2160 | { |
| 2161 | if (msg == NULL) { |
| 2162 | return PLDM_ERROR_INVALID_DATA; |
| 2163 | } |
| 2164 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2165 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2166 | header.msg_type = PLDM_REQUEST; |
| 2167 | header.instance = instance_id; |
| 2168 | header.pldm_type = PLDM_PLATFORM; |
| 2169 | header.command = PLDM_GET_SENSOR_READING; |
| 2170 | |
| 2171 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2172 | if (rc != PLDM_SUCCESS) { |
| 2173 | return rc; |
| 2174 | } |
| 2175 | |
| 2176 | struct pldm_get_sensor_reading_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2177 | (struct pldm_get_sensor_reading_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2178 | |
| 2179 | request->sensor_id = htole16(sensor_id); |
| 2180 | request->rearm_event_state = rearm_event_state; |
| 2181 | |
| 2182 | return PLDM_SUCCESS; |
| 2183 | } |
| 2184 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2185 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2186 | int decode_get_sensor_reading_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2187 | const struct pldm_msg *msg, size_t payload_length, |
| 2188 | uint8_t *completion_code, uint8_t *sensor_data_size, |
| 2189 | uint8_t *sensor_operational_state, uint8_t *sensor_event_message_enable, |
| 2190 | uint8_t *present_state, uint8_t *previous_state, uint8_t *event_state, |
| 2191 | uint8_t *present_reading) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2192 | { |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2193 | struct pldm_msgbuf _buf; |
| 2194 | struct pldm_msgbuf *buf = &_buf; |
| 2195 | int rc; |
| 2196 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2197 | if (msg == NULL || completion_code == NULL || |
| 2198 | sensor_data_size == NULL || sensor_operational_state == NULL || |
| 2199 | sensor_event_message_enable == NULL || present_state == NULL || |
| 2200 | previous_state == NULL || event_state == NULL || |
| 2201 | present_reading == NULL) { |
| 2202 | return PLDM_ERROR_INVALID_DATA; |
| 2203 | } |
| 2204 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2205 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES, |
| 2206 | msg->payload, payload_length); |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2207 | if (rc) { |
| 2208 | return rc; |
| 2209 | } |
| 2210 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2211 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2212 | if (rc) { |
| 2213 | return rc; |
| 2214 | } |
| 2215 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2216 | if (PLDM_SUCCESS != *completion_code) { |
| 2217 | return PLDM_SUCCESS; |
| 2218 | } |
| 2219 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2220 | rc = pldm_msgbuf_extract_p(buf, sensor_data_size); |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2221 | if (rc) { |
| 2222 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2223 | } |
| 2224 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2225 | if (*sensor_data_size > PLDM_SENSOR_DATA_SIZE_SINT32) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2226 | return PLDM_ERROR_INVALID_DATA; |
| 2227 | } |
| 2228 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2229 | pldm_msgbuf_extract_p(buf, sensor_operational_state); |
| 2230 | pldm_msgbuf_extract_p(buf, sensor_event_message_enable); |
| 2231 | pldm_msgbuf_extract_p(buf, present_state); |
| 2232 | pldm_msgbuf_extract_p(buf, previous_state); |
| 2233 | pldm_msgbuf_extract_p(buf, event_state); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2234 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2235 | pldm_msgbuf_extract_sensor_value(buf, *sensor_data_size, |
| 2236 | present_reading); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2237 | |
Andrew Jeffery | 840b140 | 2023-04-13 23:54:44 +0930 | [diff] [blame] | 2238 | return pldm_msgbuf_destroy_consumed(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2239 | } |
| 2240 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2241 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2242 | int encode_get_sensor_reading_resp(uint8_t instance_id, uint8_t completion_code, |
| 2243 | uint8_t sensor_data_size, |
| 2244 | uint8_t sensor_operational_state, |
| 2245 | uint8_t sensor_event_message_enable, |
| 2246 | uint8_t present_state, |
| 2247 | uint8_t previous_state, uint8_t event_state, |
| 2248 | const uint8_t *present_reading, |
| 2249 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2250 | { |
| 2251 | if (msg == NULL || present_reading == NULL) { |
| 2252 | return PLDM_ERROR_INVALID_DATA; |
| 2253 | } |
| 2254 | |
| 2255 | if (sensor_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 2256 | return PLDM_ERROR_INVALID_DATA; |
| 2257 | } |
| 2258 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2259 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2260 | header.msg_type = PLDM_RESPONSE; |
| 2261 | header.instance = instance_id; |
| 2262 | header.pldm_type = PLDM_PLATFORM; |
| 2263 | header.command = PLDM_GET_SENSOR_READING; |
| 2264 | |
| 2265 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2266 | if (rc != PLDM_SUCCESS) { |
| 2267 | return rc; |
| 2268 | } |
| 2269 | |
| 2270 | struct pldm_get_sensor_reading_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2271 | (struct pldm_get_sensor_reading_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2272 | |
| 2273 | response->completion_code = completion_code; |
| 2274 | response->sensor_data_size = sensor_data_size; |
| 2275 | response->sensor_operational_state = sensor_operational_state; |
| 2276 | response->sensor_event_message_enable = sensor_event_message_enable; |
| 2277 | response->present_state = present_state; |
| 2278 | response->previous_state = previous_state; |
| 2279 | response->event_state = event_state; |
| 2280 | |
| 2281 | if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 2282 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 2283 | if (payload_length != PLDM_GET_SENSOR_READING_MIN_RESP_BYTES) { |
| 2284 | return PLDM_ERROR_INVALID_LENGTH; |
| 2285 | } |
| 2286 | response->present_reading[0] = *present_reading; |
| 2287 | |
| 2288 | } else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 2289 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 2290 | if (payload_length != |
| 2291 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1) { |
| 2292 | return PLDM_ERROR_INVALID_LENGTH; |
| 2293 | } |
| 2294 | uint16_t val = *(uint16_t *)present_reading; |
| 2295 | val = htole16(val); |
| 2296 | memcpy(response->present_reading, &val, 2); |
| 2297 | |
| 2298 | } else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 2299 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 2300 | if (payload_length != |
| 2301 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3) { |
| 2302 | return PLDM_ERROR_INVALID_LENGTH; |
| 2303 | } |
| 2304 | uint32_t val = *(uint32_t *)present_reading; |
| 2305 | val = htole32(val); |
| 2306 | memcpy(response->present_reading, &val, 4); |
| 2307 | } |
| 2308 | |
| 2309 | return PLDM_SUCCESS; |
| 2310 | } |
| 2311 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2312 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2313 | int decode_get_sensor_reading_req(const struct pldm_msg *msg, |
| 2314 | size_t payload_length, uint16_t *sensor_id, |
| 2315 | uint8_t *rearm_event_state) |
| 2316 | { |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2317 | struct pldm_msgbuf _buf; |
| 2318 | struct pldm_msgbuf *buf = &_buf; |
| 2319 | int rc; |
| 2320 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2321 | if (msg == NULL || sensor_id == NULL || rearm_event_state == NULL) { |
| 2322 | return PLDM_ERROR_INVALID_DATA; |
| 2323 | } |
| 2324 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2325 | rc = pldm_msgbuf_init_cc(buf, PLDM_GET_SENSOR_READING_REQ_BYTES, |
| 2326 | msg->payload, payload_length); |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2327 | if (rc) { |
| 2328 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2329 | } |
| 2330 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2331 | pldm_msgbuf_extract_p(buf, sensor_id); |
| 2332 | pldm_msgbuf_extract_p(buf, rearm_event_state); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2333 | |
Andrew Jeffery | 2d1d1bd | 2023-04-13 23:58:05 +0930 | [diff] [blame] | 2334 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2335 | } |
| 2336 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2337 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2338 | int encode_set_event_receiver_req(uint8_t instance_id, |
| 2339 | uint8_t event_message_global_enable, |
| 2340 | uint8_t transport_protocol_type, |
| 2341 | uint8_t event_receiver_address_info, |
| 2342 | uint16_t heartbeat_timer, |
| 2343 | struct pldm_msg *msg) |
| 2344 | { |
| 2345 | if (msg == NULL) { |
| 2346 | return PLDM_ERROR_INVALID_DATA; |
| 2347 | } |
| 2348 | |
| 2349 | if (transport_protocol_type != PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) { |
| 2350 | return PLDM_ERROR_INVALID_DATA; |
| 2351 | } |
| 2352 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2353 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2354 | header.msg_type = PLDM_REQUEST; |
| 2355 | header.instance = instance_id; |
| 2356 | header.pldm_type = PLDM_PLATFORM; |
| 2357 | header.command = PLDM_SET_EVENT_RECEIVER; |
| 2358 | |
| 2359 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2360 | if (rc != PLDM_SUCCESS) { |
| 2361 | return rc; |
| 2362 | } |
| 2363 | |
| 2364 | struct pldm_set_event_receiver_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2365 | (struct pldm_set_event_receiver_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2366 | request->event_message_global_enable = event_message_global_enable; |
| 2367 | |
| 2368 | request->transport_protocol_type = transport_protocol_type; |
| 2369 | request->event_receiver_address_info = event_receiver_address_info; |
| 2370 | |
| 2371 | if (event_message_global_enable == |
| 2372 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) { |
| 2373 | if (heartbeat_timer == 0) { |
| 2374 | return PLDM_ERROR_INVALID_DATA; |
| 2375 | } |
| 2376 | request->heartbeat_timer = htole16(heartbeat_timer); |
| 2377 | } |
| 2378 | |
| 2379 | return PLDM_SUCCESS; |
| 2380 | } |
| 2381 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2382 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2383 | int decode_set_event_receiver_resp(const struct pldm_msg *msg, |
| 2384 | size_t payload_length, |
| 2385 | uint8_t *completion_code) |
| 2386 | { |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2387 | struct pldm_msgbuf _buf; |
| 2388 | struct pldm_msgbuf *buf = &_buf; |
| 2389 | int rc; |
| 2390 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2391 | if (msg == NULL || completion_code == NULL) { |
| 2392 | return PLDM_ERROR_INVALID_DATA; |
| 2393 | } |
| 2394 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2395 | rc = pldm_msgbuf_init_cc(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES, |
| 2396 | msg->payload, payload_length); |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2397 | if (rc) { |
| 2398 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2399 | } |
| 2400 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2401 | pldm_msgbuf_extract_p(buf, completion_code); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2402 | |
Andrew Jeffery | 42dd4e5 | 2023-04-14 00:04:38 +0930 | [diff] [blame] | 2403 | return pldm_msgbuf_destroy(buf); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2404 | } |
| 2405 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2406 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2407 | int decode_set_event_receiver_req(const struct pldm_msg *msg, |
| 2408 | size_t payload_length, |
| 2409 | uint8_t *event_message_global_enable, |
| 2410 | uint8_t *transport_protocol_type, |
| 2411 | uint8_t *event_receiver_address_info, |
| 2412 | uint16_t *heartbeat_timer) |
| 2413 | |
| 2414 | { |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2415 | struct pldm_msgbuf _buf; |
| 2416 | struct pldm_msgbuf *buf = &_buf; |
| 2417 | int rc; |
| 2418 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2419 | if (msg == NULL || event_message_global_enable == NULL || |
| 2420 | transport_protocol_type == NULL || |
| 2421 | event_receiver_address_info == NULL || heartbeat_timer == NULL) { |
| 2422 | return PLDM_ERROR_INVALID_DATA; |
| 2423 | } |
| 2424 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2425 | rc = pldm_msgbuf_init_cc(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES, |
| 2426 | msg->payload, payload_length); |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2427 | if (rc) { |
| 2428 | return rc; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2429 | } |
| 2430 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2431 | pldm_msgbuf_extract_p(buf, event_message_global_enable); |
Gilbert Chen | 8c43abb | 2024-10-01 05:23:11 +0000 | [diff] [blame^] | 2432 | if (rc) { |
| 2433 | return rc; |
| 2434 | } |
| 2435 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2436 | pldm_msgbuf_extract_p(buf, transport_protocol_type); |
| 2437 | pldm_msgbuf_extract_p(buf, event_receiver_address_info); |
Gilbert Chen | 8c43abb | 2024-10-01 05:23:11 +0000 | [diff] [blame^] | 2438 | if ((*event_message_global_enable == |
| 2439 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE)) { |
| 2440 | pldm_msgbuf_extract_p(buf, heartbeat_timer); |
| 2441 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2442 | |
Andrew Jeffery | 9667f58 | 2023-04-14 00:39:21 +0930 | [diff] [blame] | 2443 | rc = pldm_msgbuf_destroy(buf); |
| 2444 | if (rc) { |
| 2445 | return rc; |
| 2446 | } |
Andrew Jeffery | 6ef2aa9 | 2023-04-14 00:21:27 +0930 | [diff] [blame] | 2447 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2448 | if ((*event_message_global_enable == |
| 2449 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) && |
| 2450 | (*heartbeat_timer == 0)) { |
| 2451 | return PLDM_ERROR_INVALID_DATA; |
| 2452 | } |
| 2453 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2454 | return PLDM_SUCCESS; |
| 2455 | } |
| 2456 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2457 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2458 | int encode_set_event_receiver_resp(uint8_t instance_id, uint8_t completion_code, |
| 2459 | struct pldm_msg *msg) |
| 2460 | |
| 2461 | { |
| 2462 | if (msg == NULL) { |
| 2463 | return PLDM_ERROR_INVALID_DATA; |
| 2464 | } |
| 2465 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2466 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2467 | header.instance = instance_id; |
| 2468 | header.msg_type = PLDM_RESPONSE; |
| 2469 | header.pldm_type = PLDM_PLATFORM; |
| 2470 | header.command = PLDM_SET_EVENT_RECEIVER; |
| 2471 | |
| 2472 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2473 | if (rc != PLDM_SUCCESS) { |
| 2474 | return rc; |
| 2475 | } |
| 2476 | |
| 2477 | msg->payload[0] = completion_code; |
| 2478 | |
| 2479 | return PLDM_SUCCESS; |
| 2480 | } |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2481 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2482 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2483 | int encode_poll_for_platform_event_message_req(uint8_t instance_id, |
| 2484 | uint8_t format_version, |
| 2485 | uint8_t transfer_operation_flag, |
| 2486 | uint32_t data_transfer_handle, |
| 2487 | uint16_t event_id_to_acknowledge, |
| 2488 | struct pldm_msg *msg, |
| 2489 | size_t payload_length) |
| 2490 | { |
| 2491 | struct pldm_msgbuf _buf; |
| 2492 | struct pldm_msgbuf *buf = &_buf; |
| 2493 | int rc; |
| 2494 | |
| 2495 | if (msg == NULL) { |
| 2496 | return PLDM_ERROR_INVALID_DATA; |
| 2497 | } |
| 2498 | |
Thu Nguyen | 387b10f | 2024-09-24 11:33:16 +0000 | [diff] [blame] | 2499 | rc = pldm_platform_poll_for_platform_event_message_validate( |
| 2500 | transfer_operation_flag, event_id_to_acknowledge); |
| 2501 | if (rc < 0) { |
| 2502 | return PLDM_ERROR_INVALID_DATA; |
| 2503 | } |
| 2504 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2505 | struct pldm_header_info header = { 0 }; |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2506 | header.msg_type = PLDM_REQUEST; |
| 2507 | header.instance = instance_id; |
| 2508 | header.pldm_type = PLDM_PLATFORM; |
| 2509 | header.command = PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE; |
| 2510 | |
| 2511 | rc = pack_pldm_header(&header, &(msg->hdr)); |
| 2512 | if (rc != PLDM_SUCCESS) { |
| 2513 | return rc; |
| 2514 | } |
| 2515 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2516 | rc = pldm_msgbuf_init_cc( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2517 | buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES, |
| 2518 | msg->payload, payload_length); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2519 | if (rc) { |
| 2520 | return rc; |
| 2521 | } |
| 2522 | |
| 2523 | pldm_msgbuf_insert(buf, format_version); |
| 2524 | pldm_msgbuf_insert(buf, transfer_operation_flag); |
| 2525 | pldm_msgbuf_insert(buf, data_transfer_handle); |
| 2526 | pldm_msgbuf_insert(buf, event_id_to_acknowledge); |
| 2527 | |
| 2528 | return pldm_msgbuf_destroy(buf); |
| 2529 | } |
| 2530 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 2531 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2532 | int decode_poll_for_platform_event_message_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2533 | const struct pldm_msg *msg, size_t payload_length, |
| 2534 | uint8_t *completion_code, uint8_t *tid, uint16_t *event_id, |
| 2535 | uint32_t *next_data_transfer_handle, uint8_t *transfer_flag, |
| 2536 | uint8_t *event_class, uint32_t *event_data_size, void **event_data, |
| 2537 | uint32_t *event_data_integrity_checksum) |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2538 | { |
| 2539 | struct pldm_msgbuf _buf; |
| 2540 | struct pldm_msgbuf *buf = &_buf; |
| 2541 | int rc; |
| 2542 | |
| 2543 | if (msg == NULL || completion_code == NULL || tid == NULL || |
| 2544 | event_id == NULL || next_data_transfer_handle == NULL || |
| 2545 | transfer_flag == NULL || event_class == NULL || |
| 2546 | event_data_size == NULL || event_data == NULL || |
| 2547 | event_data_integrity_checksum == NULL) { |
| 2548 | return PLDM_ERROR_INVALID_DATA; |
| 2549 | } |
| 2550 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2551 | rc = pldm_msgbuf_init_cc( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 2552 | buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES, |
| 2553 | msg->payload, payload_length); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2554 | if (rc) { |
| 2555 | return rc; |
| 2556 | } |
| 2557 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2558 | rc = pldm_msgbuf_extract_p(buf, completion_code); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2559 | if (rc) { |
| 2560 | return rc; |
| 2561 | } |
| 2562 | if (PLDM_SUCCESS != *completion_code) { |
| 2563 | return *completion_code; |
| 2564 | } |
| 2565 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2566 | pldm_msgbuf_extract_p(buf, tid); |
| 2567 | rc = pldm_msgbuf_extract_p(buf, event_id); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2568 | if (rc) { |
| 2569 | return rc; |
| 2570 | } |
| 2571 | if ((*event_id == 0) || (*event_id == 0xffff)) { |
| 2572 | return PLDM_SUCCESS; |
| 2573 | } |
| 2574 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2575 | pldm_msgbuf_extract_p(buf, next_data_transfer_handle); |
| 2576 | rc = pldm_msgbuf_extract_p(buf, transfer_flag); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2577 | if (rc) { |
| 2578 | return rc; |
| 2579 | } |
| 2580 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2581 | pldm_msgbuf_extract_p(buf, event_class); |
| 2582 | rc = pldm_msgbuf_extract_p(buf, event_data_size); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2583 | if (rc) { |
| 2584 | return rc; |
| 2585 | } |
| 2586 | if (*event_data_size > payload_length) { |
| 2587 | return PLDM_ERROR_INVALID_DATA; |
| 2588 | } |
| 2589 | |
| 2590 | if (*event_data_size > 0) { |
| 2591 | pldm_msgbuf_span_required(buf, *event_data_size, event_data); |
| 2592 | } |
| 2593 | |
| 2594 | if (*transfer_flag == PLDM_END || |
| 2595 | *transfer_flag == PLDM_START_AND_END) { |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 2596 | pldm_msgbuf_extract_p(buf, event_data_integrity_checksum); |
Thu Nguyen | 159a98b | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | return pldm_msgbuf_destroy_consumed(buf); |
| 2600 | } |
Thu Nguyen | d4878cd | 2023-11-09 10:18:33 +0700 | [diff] [blame] | 2601 | |
| 2602 | LIBPLDM_ABI_TESTING |
| 2603 | int decode_numeric_effecter_pdr_data( |
| 2604 | const void *pdr_data, size_t pdr_data_length, |
| 2605 | struct pldm_numeric_effecter_value_pdr *pdr_value) |
| 2606 | { |
| 2607 | struct pldm_msgbuf _buf; |
| 2608 | struct pldm_msgbuf *buf = &_buf; |
| 2609 | struct pldm_value_pdr_hdr hdr; |
| 2610 | int rc; |
| 2611 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2612 | if (!pdr_data || !pdr_value) { |
| 2613 | return PLDM_ERROR_INVALID_DATA; |
| 2614 | } |
| 2615 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 2616 | rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH, |
| 2617 | pdr_data, pdr_data_length); |
Thu Nguyen | d4878cd | 2023-11-09 10:18:33 +0700 | [diff] [blame] | 2618 | if (rc) { |
| 2619 | return rc; |
| 2620 | } |
| 2621 | |
| 2622 | rc = pldm_msgbuf_extract_value_pdr_hdr(buf, &hdr); |
| 2623 | if (rc) { |
| 2624 | return rc; |
| 2625 | } |
| 2626 | |
| 2627 | rc = pldm_platform_pdr_hdr_validate( |
| 2628 | &hdr, PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH, |
| 2629 | pdr_data_length); |
| 2630 | if (rc) { |
| 2631 | return rc; |
| 2632 | } |
| 2633 | |
| 2634 | memcpy(&pdr_value->hdr, &hdr, sizeof(hdr)); |
| 2635 | |
| 2636 | pldm_msgbuf_extract(buf, pdr_value->terminus_handle); |
| 2637 | pldm_msgbuf_extract(buf, pdr_value->effecter_id); |
| 2638 | pldm_msgbuf_extract(buf, pdr_value->entity_type); |
| 2639 | pldm_msgbuf_extract(buf, pdr_value->entity_instance); |
| 2640 | pldm_msgbuf_extract(buf, pdr_value->container_id); |
| 2641 | pldm_msgbuf_extract(buf, pdr_value->effecter_semantic_id); |
| 2642 | pldm_msgbuf_extract(buf, pdr_value->effecter_init); |
| 2643 | pldm_msgbuf_extract(buf, pdr_value->effecter_auxiliary_names); |
| 2644 | pldm_msgbuf_extract(buf, pdr_value->base_unit); |
| 2645 | pldm_msgbuf_extract(buf, pdr_value->unit_modifier); |
| 2646 | pldm_msgbuf_extract(buf, pdr_value->rate_unit); |
| 2647 | pldm_msgbuf_extract(buf, pdr_value->base_oem_unit_handle); |
| 2648 | pldm_msgbuf_extract(buf, pdr_value->aux_unit); |
| 2649 | pldm_msgbuf_extract(buf, pdr_value->aux_unit_modifier); |
| 2650 | pldm_msgbuf_extract(buf, pdr_value->aux_rate_unit); |
| 2651 | pldm_msgbuf_extract(buf, pdr_value->aux_oem_unit_handle); |
| 2652 | pldm_msgbuf_extract(buf, pdr_value->is_linear); |
| 2653 | |
| 2654 | rc = pldm_msgbuf_extract(buf, pdr_value->effecter_data_size); |
| 2655 | if (rc) { |
| 2656 | return rc; |
| 2657 | } |
| 2658 | if (pdr_value->effecter_data_size > PLDM_SENSOR_DATA_SIZE_MAX) { |
| 2659 | return PLDM_ERROR_INVALID_DATA; |
| 2660 | } |
| 2661 | |
| 2662 | pldm_msgbuf_extract(buf, pdr_value->resolution); |
| 2663 | pldm_msgbuf_extract(buf, pdr_value->offset); |
| 2664 | pldm_msgbuf_extract(buf, pdr_value->accuracy); |
| 2665 | pldm_msgbuf_extract(buf, pdr_value->plus_tolerance); |
| 2666 | pldm_msgbuf_extract(buf, pdr_value->minus_tolerance); |
| 2667 | pldm_msgbuf_extract(buf, pdr_value->state_transition_interval); |
| 2668 | pldm_msgbuf_extract(buf, pdr_value->transition_interval); |
| 2669 | pldm_msgbuf_extract_effecter_data(buf, pdr_value->effecter_data_size, |
| 2670 | pdr_value->max_settable); |
| 2671 | pldm_msgbuf_extract_effecter_data(buf, pdr_value->effecter_data_size, |
| 2672 | pdr_value->min_settable); |
| 2673 | |
| 2674 | rc = pldm_msgbuf_extract(buf, pdr_value->range_field_format); |
| 2675 | if (rc) { |
| 2676 | return rc; |
| 2677 | } |
| 2678 | if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) { |
| 2679 | return PLDM_ERROR_INVALID_DATA; |
| 2680 | } |
| 2681 | |
| 2682 | pldm_msgbuf_extract(buf, pdr_value->range_field_support.byte); |
| 2683 | pldm_msgbuf_extract_range_field_format( |
| 2684 | buf, pdr_value->range_field_format, pdr_value->nominal_value); |
| 2685 | pldm_msgbuf_extract_range_field_format( |
| 2686 | buf, pdr_value->range_field_format, pdr_value->normal_max); |
| 2687 | pldm_msgbuf_extract_range_field_format( |
| 2688 | buf, pdr_value->range_field_format, pdr_value->normal_min); |
| 2689 | pldm_msgbuf_extract_range_field_format( |
| 2690 | buf, pdr_value->range_field_format, pdr_value->rated_max); |
| 2691 | pldm_msgbuf_extract_range_field_format( |
| 2692 | buf, pdr_value->range_field_format, pdr_value->rated_min); |
| 2693 | |
| 2694 | return pldm_msgbuf_destroy_consumed(buf); |
| 2695 | } |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2696 | |
Tal Yacobi | de67ab6 | 2024-05-30 22:36:50 +0300 | [diff] [blame] | 2697 | LIBPLDM_ABI_STABLE |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2698 | int encode_get_state_effecter_states_req(uint8_t instance_id, |
| 2699 | uint16_t effecter_id, |
| 2700 | struct pldm_msg *msg, |
| 2701 | size_t payload_length) |
| 2702 | { |
| 2703 | struct pldm_msgbuf _buf; |
| 2704 | struct pldm_msgbuf *buf = &_buf; |
| 2705 | int rc; |
| 2706 | |
| 2707 | if (msg == NULL) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2708 | return -EINVAL; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | struct pldm_header_info header = { 0 }; |
| 2712 | header.msg_type = PLDM_REQUEST; |
| 2713 | header.instance = instance_id; |
| 2714 | header.pldm_type = PLDM_PLATFORM; |
| 2715 | header.command = PLDM_GET_STATE_EFFECTER_STATES; |
| 2716 | |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2717 | rc = pack_pldm_header_errno(&header, &msg->hdr); |
| 2718 | if (rc < 0) { |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2719 | return rc; |
| 2720 | } |
| 2721 | |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2722 | rc = pldm_msgbuf_init_errno(buf, |
| 2723 | PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES, |
| 2724 | msg->payload, payload_length); |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2725 | if (rc) { |
| 2726 | return rc; |
| 2727 | } |
| 2728 | |
| 2729 | pldm_msgbuf_insert(buf, effecter_id); |
| 2730 | |
| 2731 | return pldm_msgbuf_destroy_consumed(buf); |
| 2732 | } |
| 2733 | |
Tal Yacobi | de67ab6 | 2024-05-30 22:36:50 +0300 | [diff] [blame] | 2734 | LIBPLDM_ABI_STABLE |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2735 | int decode_get_state_effecter_states_req(const struct pldm_msg *msg, |
| 2736 | size_t payload_length, |
| 2737 | uint16_t *effecter_id) |
| 2738 | { |
| 2739 | struct pldm_msgbuf _buf; |
| 2740 | struct pldm_msgbuf *buf = &_buf; |
| 2741 | int rc; |
| 2742 | |
| 2743 | if (msg == NULL || effecter_id == NULL) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2744 | return -EINVAL; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2745 | } |
| 2746 | |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2747 | rc = pldm_msgbuf_init_errno( |
| 2748 | buf, PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES, |
| 2749 | msg->payload, payload_length); |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2750 | if (rc) { |
| 2751 | return rc; |
| 2752 | } |
| 2753 | |
| 2754 | pldm_msgbuf_extract_p(buf, effecter_id); |
| 2755 | |
| 2756 | return pldm_msgbuf_destroy_consumed(buf); |
| 2757 | } |
| 2758 | |
Tal Yacobi | de67ab6 | 2024-05-30 22:36:50 +0300 | [diff] [blame] | 2759 | LIBPLDM_ABI_STABLE |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2760 | int decode_get_state_effecter_states_resp( |
| 2761 | const struct pldm_msg *msg, size_t payload_length, |
| 2762 | struct pldm_get_state_effecter_states_resp *resp) |
| 2763 | { |
| 2764 | struct pldm_msgbuf _buf; |
| 2765 | struct pldm_msgbuf *buf = &_buf; |
| 2766 | get_effecter_state_field *field; |
| 2767 | int rc; |
| 2768 | int i; |
| 2769 | |
| 2770 | if (msg == NULL || resp == NULL) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2771 | return -EINVAL; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2772 | } |
| 2773 | |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2774 | rc = pldm_msgbuf_init_errno( |
| 2775 | buf, PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES, |
| 2776 | msg->payload, payload_length); |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2777 | if (rc) { |
| 2778 | return rc; |
| 2779 | } |
| 2780 | |
| 2781 | rc = pldm_msgbuf_extract(buf, resp->completion_code); |
| 2782 | if (rc) { |
| 2783 | return rc; |
| 2784 | } |
| 2785 | |
| 2786 | if (PLDM_SUCCESS != resp->completion_code) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2787 | return 0; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | rc = pldm_msgbuf_extract(buf, resp->comp_effecter_count); |
| 2791 | if (rc) { |
| 2792 | return rc; |
| 2793 | } |
| 2794 | |
| 2795 | uint8_t comp_effecter_count = resp->comp_effecter_count; |
| 2796 | |
| 2797 | if (comp_effecter_count < PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MIN || |
| 2798 | comp_effecter_count > PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MAX) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2799 | return -EBADMSG; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | for (i = 0, field = resp->field; i < comp_effecter_count; |
| 2803 | i++, field++) { |
| 2804 | pldm_msgbuf_extract(buf, field->effecter_op_state); |
| 2805 | pldm_msgbuf_extract(buf, field->pending_state); |
| 2806 | pldm_msgbuf_extract(buf, field->present_state); |
| 2807 | } |
| 2808 | |
| 2809 | return pldm_msgbuf_destroy_consumed(buf); |
| 2810 | } |
| 2811 | |
Tal Yacobi | de67ab6 | 2024-05-30 22:36:50 +0300 | [diff] [blame] | 2812 | LIBPLDM_ABI_STABLE |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2813 | int encode_get_state_effecter_states_resp( |
| 2814 | uint8_t instance_id, struct pldm_get_state_effecter_states_resp *resp, |
| 2815 | struct pldm_msg *msg, size_t payload_length) |
| 2816 | { |
| 2817 | struct pldm_msgbuf _buf; |
| 2818 | struct pldm_msgbuf *buf = &_buf; |
| 2819 | get_effecter_state_field *field; |
| 2820 | int rc; |
| 2821 | int i; |
| 2822 | |
| 2823 | if (msg == NULL || resp == NULL) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2824 | return -EINVAL; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | uint8_t comp_effecter_count = resp->comp_effecter_count; |
| 2828 | |
| 2829 | if (comp_effecter_count < PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MIN || |
| 2830 | comp_effecter_count > PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MAX) { |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2831 | return -EBADMSG; |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | struct pldm_header_info header = { 0 }; |
| 2835 | header.msg_type = PLDM_RESPONSE; |
| 2836 | header.instance = instance_id; |
| 2837 | header.pldm_type = PLDM_PLATFORM; |
| 2838 | header.command = PLDM_GET_STATE_EFFECTER_STATES; |
| 2839 | |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2840 | rc = pack_pldm_header_errno(&header, &msg->hdr); |
| 2841 | if (rc < 0) { |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2842 | return rc; |
| 2843 | } |
| 2844 | |
Tal Yacobi | f490a38 | 2024-05-31 09:57:36 +0300 | [diff] [blame] | 2845 | rc = pldm_msgbuf_init_errno( |
| 2846 | buf, PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES, |
| 2847 | msg->payload, payload_length); |
Tal Yacobi | a6fa555 | 2024-05-05 16:57:38 +0300 | [diff] [blame] | 2848 | if (rc) { |
| 2849 | return rc; |
| 2850 | } |
| 2851 | |
| 2852 | pldm_msgbuf_insert(buf, resp->completion_code); |
| 2853 | pldm_msgbuf_insert(buf, comp_effecter_count); |
| 2854 | |
| 2855 | for (i = 0, field = resp->field; i < comp_effecter_count; |
| 2856 | i++, field++) { |
| 2857 | pldm_msgbuf_insert(buf, field->effecter_op_state); |
| 2858 | pldm_msgbuf_insert(buf, field->pending_state); |
| 2859 | pldm_msgbuf_insert(buf, field->present_state); |
| 2860 | } |
| 2861 | |
| 2862 | return pldm_msgbuf_destroy_consumed(buf); |
| 2863 | } |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2864 | |
Thu Nguyen | 43cb4b5 | 2024-07-16 05:45:27 +0000 | [diff] [blame] | 2865 | LIBPLDM_ABI_STABLE |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2866 | int decode_entity_auxiliary_names_pdr( |
| 2867 | const void *data, size_t data_length, |
| 2868 | struct pldm_entity_auxiliary_names_pdr *pdr, size_t pdr_length) |
| 2869 | { |
| 2870 | struct pldm_msgbuf _buf; |
| 2871 | struct pldm_msgbuf *buf = &_buf; |
| 2872 | struct pldm_msgbuf _src; |
| 2873 | struct pldm_msgbuf *src = &_src; |
| 2874 | struct pldm_msgbuf _dst; |
| 2875 | struct pldm_msgbuf *dst = &_dst; |
| 2876 | size_t names_len = 0; |
| 2877 | void *names = NULL; |
| 2878 | int rc; |
| 2879 | int i; |
| 2880 | |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2881 | if (!data || !pdr) { |
| 2882 | return -EINVAL; |
| 2883 | } |
| 2884 | |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2885 | /* |
| 2886 | * Alignment of auxiliary_name_data is an invariant as we statically assert |
| 2887 | * its behaviour in the header. |
| 2888 | */ |
| 2889 | assert(!((uintptr_t)pdr->auxiliary_name_data & |
| 2890 | (alignof(pldm_utf16be) - 1))); |
| 2891 | |
| 2892 | /* Reject any lengths that are obviously invalid */ |
| 2893 | if (pdr_length < data_length || pdr_length < sizeof(*pdr)) { |
| 2894 | return -EINVAL; |
| 2895 | } |
| 2896 | |
| 2897 | rc = pldm_msgbuf_init_errno( |
| 2898 | buf, PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH, data, |
| 2899 | data_length); |
| 2900 | if (rc) { |
| 2901 | return rc; |
| 2902 | } |
| 2903 | |
| 2904 | rc = pldm_msgbuf_extract_value_pdr_hdr(buf, &pdr->hdr); |
| 2905 | if (rc) { |
| 2906 | return rc; |
| 2907 | } |
| 2908 | |
| 2909 | rc = pldm_platform_pdr_hdr_validate( |
| 2910 | &pdr->hdr, PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH, |
| 2911 | data_length); |
| 2912 | if (rc) { |
| 2913 | return rc; |
| 2914 | } |
| 2915 | |
| 2916 | pldm_msgbuf_extract(buf, pdr->container.entity_type); |
| 2917 | pldm_msgbuf_extract(buf, pdr->container.entity_instance_num); |
| 2918 | pldm_msgbuf_extract(buf, pdr->container.entity_container_id); |
| 2919 | pldm_msgbuf_extract(buf, pdr->shared_name_count); |
| 2920 | rc = pldm_msgbuf_extract(buf, pdr->name_string_count); |
| 2921 | if (rc < 0) { |
| 2922 | return rc; |
| 2923 | } |
| 2924 | |
| 2925 | rc = pldm_msgbuf_span_remaining(buf, &names, &names_len); |
| 2926 | if (rc < 0) { |
| 2927 | return rc; |
| 2928 | } |
Andrew Jeffery | 90bbe6c | 2024-09-01 13:02:02 +0300 | [diff] [blame] | 2929 | assert(names); |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2930 | |
| 2931 | pdr->auxiliary_name_data_size = pdr_length - sizeof(*pdr); |
| 2932 | |
| 2933 | rc = pldm_msgbuf_init_errno(dst, pdr->auxiliary_name_data_size, |
| 2934 | pdr->auxiliary_name_data, |
| 2935 | pdr->auxiliary_name_data_size); |
| 2936 | if (rc < 0) { |
| 2937 | return rc; |
| 2938 | } |
| 2939 | |
| 2940 | /* |
| 2941 | * Below we do two passes over the same region. This is to first pack the |
| 2942 | * UTF16-BE strings into auxiliary_name_data, followed by the ASCII strings, |
| 2943 | * to maintain appropriate alignment. |
| 2944 | */ |
| 2945 | |
| 2946 | /* Initialise for the first pass to extract the UTF16-BE name strings */ |
| 2947 | rc = pldm_msgbuf_init_errno(src, names_len, names, names_len); |
| 2948 | if (rc < 0) { |
| 2949 | return rc; |
| 2950 | } |
| 2951 | |
| 2952 | for (i = 0; i < pdr->name_string_count; i++) { |
| 2953 | pldm_msgbuf_span_string_ascii(src, NULL, NULL); |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 2954 | rc = pldm_msgbuf_copy_string_utf16(dst, src); |
| 2955 | if (rc) { |
| 2956 | return rc; |
| 2957 | } |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | rc = pldm_msgbuf_destroy_consumed(src); |
| 2961 | if (rc < 0) { |
| 2962 | return rc; |
| 2963 | } |
| 2964 | |
| 2965 | /* Reinitialise for the second pass to extract the ASCII tag strings */ |
| 2966 | rc = pldm_msgbuf_init_errno(src, names_len, names, names_len); |
| 2967 | if (rc < 0) { |
| 2968 | return rc; |
| 2969 | } |
| 2970 | |
| 2971 | for (i = 0; i < pdr->name_string_count; i++) { |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 2972 | rc = pldm_msgbuf_copy_string_ascii(dst, src); |
| 2973 | if (rc) { |
| 2974 | return rc; |
| 2975 | } |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2976 | pldm_msgbuf_span_string_utf16(src, NULL, NULL); |
| 2977 | } |
| 2978 | |
| 2979 | if ((rc = pldm_msgbuf_destroy(dst)) || |
| 2980 | (rc = pldm_msgbuf_destroy(src)) || |
| 2981 | (rc = pldm_msgbuf_destroy(buf))) { |
| 2982 | return rc; |
| 2983 | } |
| 2984 | |
| 2985 | return 0; |
| 2986 | } |
| 2987 | |
Thu Nguyen | 43cb4b5 | 2024-07-16 05:45:27 +0000 | [diff] [blame] | 2988 | LIBPLDM_ABI_STABLE |
Thu Nguyen | dacfa35 | 2024-06-22 09:53:15 +0000 | [diff] [blame] | 2989 | int decode_pldm_entity_auxiliary_names_pdr_index( |
| 2990 | struct pldm_entity_auxiliary_names_pdr *pdr) |
| 2991 | { |
| 2992 | struct pldm_msgbuf _buf; |
| 2993 | struct pldm_msgbuf *buf = &_buf; |
| 2994 | int rc; |
| 2995 | int i; |
| 2996 | |
| 2997 | if (!pdr) { |
| 2998 | return -EINVAL; |
| 2999 | } |
| 3000 | |
| 3001 | if (pdr->name_string_count == 0 && pdr->names) { |
| 3002 | return -EINVAL; |
| 3003 | } |
| 3004 | |
| 3005 | if (pdr->name_string_count > 0 && !pdr->names) { |
| 3006 | return -EINVAL; |
| 3007 | } |
| 3008 | |
| 3009 | if (pdr->name_string_count == 0) { |
| 3010 | return 0; |
| 3011 | } |
| 3012 | |
| 3013 | /* |
| 3014 | * Minimum size is one NUL for each member of each entry |
| 3015 | * |
| 3016 | * Note that the definition of nameLanguageTag in DSP0248 v1.2.2 |
| 3017 | * states the following: |
| 3018 | * |
| 3019 | * > A null-terminated ISO646 ASCII string ... |
| 3020 | * > |
| 3021 | * > special value: null string = 0x0000 = unspecified. |
| 3022 | * |
| 3023 | * Until proven otherwise we will assume the "0x0000" is a |
| 3024 | * misrepresentation of an ASCII NUL, and that ASCII NUL is |
| 3025 | * represented by a single byte. |
| 3026 | */ |
| 3027 | rc = pldm_msgbuf_init_errno( |
| 3028 | buf, pdr->name_string_count * (sizeof(char) + sizeof(char16_t)), |
| 3029 | pdr->auxiliary_name_data, pdr->auxiliary_name_data_size); |
| 3030 | if (rc) { |
| 3031 | return rc; |
| 3032 | } |
| 3033 | |
| 3034 | for (i = 0; i < pdr->name_string_count; i++) { |
| 3035 | void *loc = NULL; |
| 3036 | pldm_msgbuf_span_string_utf16(buf, &loc, NULL); |
| 3037 | pdr->names[i].name = loc; |
| 3038 | } |
| 3039 | |
| 3040 | for (i = 0; i < pdr->name_string_count; i++) { |
| 3041 | void *loc = NULL; |
| 3042 | pldm_msgbuf_span_string_ascii(buf, &loc, NULL); |
| 3043 | pdr->names[i].tag = loc; |
| 3044 | } |
| 3045 | |
| 3046 | return pldm_msgbuf_destroy_consumed(buf); |
| 3047 | } |
Thu Nguyen | a5d18dc | 2024-08-07 08:29:34 +0000 | [diff] [blame] | 3048 | |
Thu Nguyen | 3559aa1 | 2024-08-29 00:13:38 +0000 | [diff] [blame] | 3049 | LIBPLDM_ABI_STABLE |
Thu Nguyen | 0290303 | 2024-09-03 06:39:50 +0000 | [diff] [blame] | 3050 | int decode_pldm_platform_cper_event(const void *event_data, |
| 3051 | size_t event_data_length, |
| 3052 | struct pldm_platform_cper_event *cper_event, |
| 3053 | size_t cper_event_length) |
Thu Nguyen | a5d18dc | 2024-08-07 08:29:34 +0000 | [diff] [blame] | 3054 | { |
| 3055 | struct pldm_msgbuf _buf; |
| 3056 | struct pldm_msgbuf *buf = &_buf; |
| 3057 | int rc; |
| 3058 | |
| 3059 | if (!cper_event || !event_data) { |
| 3060 | return -EINVAL; |
| 3061 | } |
| 3062 | |
| 3063 | if (cper_event_length < sizeof(*cper_event)) { |
| 3064 | return -EINVAL; |
| 3065 | } |
| 3066 | |
| 3067 | rc = pldm_msgbuf_init_errno(buf, PLDM_PLATFORM_CPER_EVENT_MIN_LENGTH, |
| 3068 | event_data, event_data_length); |
| 3069 | if (rc) { |
| 3070 | return rc; |
| 3071 | } |
| 3072 | |
| 3073 | pldm_msgbuf_extract(buf, cper_event->format_version); |
| 3074 | rc = pldm_msgbuf_extract(buf, cper_event->format_type); |
| 3075 | if (rc) { |
| 3076 | return rc; |
| 3077 | } |
| 3078 | if (cper_event->format_type != PLDM_PLATFORM_CPER_EVENT_WITH_HEADER && |
| 3079 | cper_event->format_type != |
| 3080 | PLDM_PLATFORM_CPER_EVENT_WITHOUT_HEADER) { |
| 3081 | return -EPROTO; |
| 3082 | } |
| 3083 | |
| 3084 | rc = pldm_msgbuf_extract(buf, cper_event->event_data_length); |
| 3085 | if (rc) { |
| 3086 | return rc; |
| 3087 | } |
| 3088 | |
| 3089 | if (cper_event->event_data_length > |
| 3090 | (cper_event_length - sizeof(*cper_event))) { |
| 3091 | return -EOVERFLOW; |
| 3092 | } |
| 3093 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 3094 | rc = pldm_msgbuf_extract_array_uint8( |
| 3095 | buf, cper_event->event_data_length, cper_event->event_data, |
| 3096 | cper_event_length - sizeof(*cper_event)); |
| 3097 | if (rc) { |
| 3098 | return rc; |
| 3099 | } |
Thu Nguyen | a5d18dc | 2024-08-07 08:29:34 +0000 | [diff] [blame] | 3100 | |
| 3101 | return pldm_msgbuf_destroy_consumed(buf); |
| 3102 | } |
| 3103 | |
Thu Nguyen | 3559aa1 | 2024-08-29 00:13:38 +0000 | [diff] [blame] | 3104 | LIBPLDM_ABI_STABLE |
Thu Nguyen | a5d18dc | 2024-08-07 08:29:34 +0000 | [diff] [blame] | 3105 | uint8_t * |
| 3106 | pldm_platform_cper_event_event_data(struct pldm_platform_cper_event *event) |
| 3107 | { |
| 3108 | return event->event_data; |
| 3109 | } |