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