Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1 | #include "bios.h" |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 2 | #include "base.h" |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 3 | #include "utils.h" |
| 4 | #include <endian.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 5 | #include <string.h> |
| 6 | |
| 7 | int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg) |
| 8 | { |
| 9 | if (msg == NULL) { |
| 10 | return PLDM_ERROR_INVALID_DATA; |
| 11 | } |
| 12 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 13 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 14 | header.msg_type = PLDM_REQUEST; |
| 15 | header.instance = instance_id; |
| 16 | header.pldm_type = PLDM_BIOS; |
| 17 | header.command = PLDM_GET_DATE_TIME; |
| 18 | return pack_pldm_header(&header, &(msg->hdr)); |
| 19 | } |
| 20 | |
| 21 | int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code, |
| 22 | uint8_t seconds, uint8_t minutes, uint8_t hours, |
| 23 | uint8_t day, uint8_t month, uint16_t year, |
| 24 | struct pldm_msg *msg) |
| 25 | { |
| 26 | if (msg == NULL) { |
| 27 | return PLDM_ERROR_INVALID_DATA; |
| 28 | } |
| 29 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 30 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 31 | header.msg_type = PLDM_RESPONSE; |
| 32 | header.instance = instance_id; |
| 33 | header.pldm_type = PLDM_BIOS; |
| 34 | header.command = PLDM_GET_DATE_TIME; |
| 35 | |
| 36 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 37 | if (rc != PLDM_SUCCESS) { |
| 38 | return rc; |
| 39 | } |
| 40 | |
| 41 | struct pldm_get_date_time_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 42 | (struct pldm_get_date_time_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 43 | response->completion_code = completion_code; |
| 44 | if (response->completion_code == PLDM_SUCCESS) { |
| 45 | response->completion_code = completion_code; |
| 46 | response->seconds = seconds; |
| 47 | response->minutes = minutes; |
| 48 | response->hours = hours; |
| 49 | response->day = day; |
| 50 | response->month = month; |
| 51 | response->year = htole16(year); |
| 52 | } |
| 53 | return PLDM_SUCCESS; |
| 54 | } |
| 55 | |
| 56 | int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length, |
| 57 | uint8_t *completion_code, uint8_t *seconds, |
| 58 | uint8_t *minutes, uint8_t *hours, uint8_t *day, |
| 59 | uint8_t *month, uint16_t *year) |
| 60 | { |
| 61 | if (msg == NULL || seconds == NULL || minutes == NULL || |
| 62 | hours == NULL || day == NULL || month == NULL || year == NULL || |
| 63 | completion_code == NULL) { |
| 64 | return PLDM_ERROR_INVALID_DATA; |
| 65 | } |
| 66 | |
| 67 | *completion_code = msg->payload[0]; |
| 68 | if (PLDM_SUCCESS != *completion_code) { |
| 69 | return PLDM_SUCCESS; |
| 70 | } |
| 71 | |
| 72 | if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) { |
| 73 | return PLDM_ERROR_INVALID_LENGTH; |
| 74 | } |
| 75 | |
| 76 | struct pldm_get_date_time_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 77 | (struct pldm_get_date_time_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 78 | |
| 79 | *seconds = response->seconds; |
| 80 | *minutes = response->minutes; |
| 81 | *hours = response->hours; |
| 82 | *day = response->day; |
| 83 | *month = response->month; |
| 84 | *year = le16toh(response->year); |
| 85 | |
| 86 | return PLDM_SUCCESS; |
| 87 | } |
| 88 | |
| 89 | int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds, |
| 90 | uint8_t minutes, uint8_t hours, uint8_t day, |
| 91 | uint8_t month, uint16_t year, struct pldm_msg *msg, |
| 92 | size_t payload_length) |
| 93 | { |
| 94 | if (msg == NULL) { |
| 95 | return PLDM_ERROR_INVALID_DATA; |
| 96 | } |
| 97 | if (payload_length != sizeof(struct pldm_set_date_time_req)) { |
| 98 | return PLDM_ERROR_INVALID_LENGTH; |
| 99 | } |
| 100 | |
| 101 | if (!is_time_legal(seconds, minutes, hours, day, month, year)) { |
| 102 | return PLDM_ERROR_INVALID_DATA; |
| 103 | } |
| 104 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 105 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 106 | header.instance = instance_id; |
| 107 | header.msg_type = PLDM_REQUEST; |
| 108 | header.pldm_type = PLDM_BIOS; |
| 109 | header.command = PLDM_SET_DATE_TIME; |
| 110 | |
| 111 | uint8_t rc = pack_pldm_header(&header, &msg->hdr); |
| 112 | if (rc != PLDM_SUCCESS) { |
| 113 | return rc; |
| 114 | } |
| 115 | |
| 116 | struct pldm_set_date_time_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 117 | (struct pldm_set_date_time_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 118 | request->seconds = dec2bcd8(seconds); |
| 119 | request->minutes = dec2bcd8(minutes); |
| 120 | request->hours = dec2bcd8(hours); |
| 121 | request->day = dec2bcd8(day); |
| 122 | request->month = dec2bcd8(month); |
| 123 | request->year = htole16(dec2bcd16(year)); |
| 124 | |
| 125 | return PLDM_SUCCESS; |
| 126 | } |
| 127 | |
| 128 | int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length, |
| 129 | uint8_t *seconds, uint8_t *minutes, uint8_t *hours, |
| 130 | uint8_t *day, uint8_t *month, uint16_t *year) |
| 131 | { |
| 132 | if (msg == NULL || seconds == NULL || minutes == NULL || |
| 133 | hours == NULL || day == NULL || month == NULL || year == NULL) { |
| 134 | return PLDM_ERROR_INVALID_DATA; |
| 135 | } |
| 136 | if (payload_length != sizeof(struct pldm_set_date_time_req)) { |
| 137 | return PLDM_ERROR_INVALID_LENGTH; |
| 138 | } |
| 139 | |
| 140 | const struct pldm_set_date_time_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 141 | (struct pldm_set_date_time_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 142 | |
| 143 | *seconds = bcd2dec8(request->seconds); |
| 144 | *minutes = bcd2dec8(request->minutes); |
| 145 | *hours = bcd2dec8(request->hours); |
| 146 | *day = bcd2dec8(request->day); |
| 147 | *month = bcd2dec8(request->month); |
| 148 | *year = bcd2dec16(le16toh(request->year)); |
| 149 | |
| 150 | if (!is_time_legal(*seconds, *minutes, *hours, *day, *month, *year)) { |
| 151 | return PLDM_ERROR_INVALID_DATA; |
| 152 | } |
| 153 | |
| 154 | return PLDM_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code, |
| 158 | struct pldm_msg *msg, size_t payload_length) |
| 159 | { |
| 160 | if (msg == NULL) { |
| 161 | return PLDM_ERROR_INVALID_DATA; |
| 162 | } |
| 163 | if (payload_length != sizeof(struct pldm_only_cc_resp)) { |
| 164 | return PLDM_ERROR_INVALID_LENGTH; |
| 165 | } |
| 166 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 167 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 168 | header.instance = instance_id; |
| 169 | header.msg_type = PLDM_RESPONSE; |
| 170 | header.pldm_type = PLDM_BIOS; |
| 171 | header.command = PLDM_SET_DATE_TIME; |
| 172 | |
| 173 | uint8_t rc = pack_pldm_header(&header, &msg->hdr); |
| 174 | if (rc != PLDM_SUCCESS) { |
| 175 | return rc; |
| 176 | } |
| 177 | |
| 178 | struct pldm_only_cc_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 179 | (struct pldm_only_cc_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 180 | response->completion_code = completion_code; |
| 181 | |
| 182 | return PLDM_SUCCESS; |
| 183 | } |
| 184 | |
| 185 | int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length, |
| 186 | uint8_t *completion_code) |
| 187 | { |
| 188 | if (msg == NULL || completion_code == NULL) { |
| 189 | return PLDM_ERROR_INVALID_DATA; |
| 190 | } |
| 191 | |
| 192 | *completion_code = msg->payload[0]; |
| 193 | if (PLDM_SUCCESS != *completion_code) { |
| 194 | return PLDM_SUCCESS; |
| 195 | } |
| 196 | |
| 197 | if (payload_length != sizeof(struct pldm_only_cc_resp)) { |
| 198 | return PLDM_ERROR_INVALID_LENGTH; |
| 199 | } |
| 200 | |
| 201 | return PLDM_SUCCESS; |
| 202 | } |
| 203 | |
| 204 | int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 205 | uint32_t next_transfer_handle, |
| 206 | uint8_t transfer_flag, uint8_t *table_data, |
| 207 | size_t payload_length, struct pldm_msg *msg) |
| 208 | { |
| 209 | if (msg == NULL) { |
| 210 | return PLDM_ERROR_INVALID_DATA; |
| 211 | } |
| 212 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 213 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 214 | header.msg_type = PLDM_RESPONSE; |
| 215 | header.instance = instance_id; |
| 216 | header.pldm_type = PLDM_BIOS; |
| 217 | header.command = PLDM_GET_BIOS_TABLE; |
| 218 | |
| 219 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 220 | if (rc != PLDM_SUCCESS) { |
| 221 | return rc; |
| 222 | } |
| 223 | |
| 224 | struct pldm_get_bios_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 225 | (struct pldm_get_bios_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 226 | response->completion_code = completion_code; |
| 227 | if (response->completion_code == PLDM_SUCCESS) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 228 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 229 | response->transfer_flag = transfer_flag; |
| 230 | if (table_data != NULL && |
| 231 | payload_length > (sizeof(struct pldm_msg_hdr) + |
| 232 | PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) { |
| 233 | memcpy(response->table_data, table_data, |
| 234 | payload_length - |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 235 | (sizeof(struct pldm_msg_hdr) + |
| 236 | PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | return PLDM_SUCCESS; |
| 240 | } |
| 241 | |
| 242 | int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle, |
| 243 | uint8_t transfer_op_flag, uint8_t table_type, |
| 244 | struct pldm_msg *msg) |
| 245 | { |
| 246 | if (msg == NULL) { |
| 247 | return PLDM_ERROR_INVALID_DATA; |
| 248 | } |
| 249 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 250 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 251 | header.msg_type = PLDM_REQUEST; |
| 252 | header.instance = instance_id; |
| 253 | header.pldm_type = PLDM_BIOS; |
| 254 | header.command = PLDM_GET_BIOS_TABLE; |
| 255 | |
| 256 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 257 | if (rc != PLDM_SUCCESS) { |
| 258 | return rc; |
| 259 | } |
| 260 | |
| 261 | struct pldm_get_bios_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 262 | (struct pldm_get_bios_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 263 | |
| 264 | request->transfer_handle = htole32(transfer_handle); |
| 265 | request->transfer_op_flag = transfer_op_flag; |
| 266 | request->table_type = table_type; |
| 267 | return PLDM_SUCCESS; |
| 268 | } |
| 269 | |
| 270 | int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length, |
| 271 | uint32_t *transfer_handle, |
| 272 | uint8_t *transfer_op_flag, uint8_t *table_type) |
| 273 | { |
| 274 | if (msg == NULL || transfer_op_flag == NULL || table_type == NULL || |
| 275 | transfer_handle == NULL) { |
| 276 | return PLDM_ERROR_INVALID_DATA; |
| 277 | } |
| 278 | |
| 279 | if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) { |
| 280 | return PLDM_ERROR_INVALID_LENGTH; |
| 281 | } |
| 282 | |
| 283 | struct pldm_get_bios_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 284 | (struct pldm_get_bios_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 285 | *transfer_handle = le32toh(request->transfer_handle); |
| 286 | *transfer_op_flag = request->transfer_op_flag; |
| 287 | *table_type = request->table_type; |
| 288 | |
| 289 | return PLDM_SUCCESS; |
| 290 | } |
| 291 | |
| 292 | int decode_get_bios_table_resp(const struct pldm_msg *msg, |
| 293 | size_t payload_length, uint8_t *completion_code, |
| 294 | uint32_t *next_transfer_handle, |
| 295 | uint8_t *transfer_flag, |
| 296 | size_t *bios_table_offset) |
| 297 | |
| 298 | { |
| 299 | if (msg == NULL || transfer_flag == NULL || |
| 300 | next_transfer_handle == NULL || completion_code == NULL) { |
| 301 | return PLDM_ERROR_INVALID_DATA; |
| 302 | } |
| 303 | if (payload_length <= PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES) { |
| 304 | return PLDM_ERROR_INVALID_LENGTH; |
| 305 | } |
| 306 | |
| 307 | struct pldm_get_bios_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 308 | (struct pldm_get_bios_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 309 | |
| 310 | *completion_code = response->completion_code; |
| 311 | |
| 312 | if (PLDM_SUCCESS != *completion_code) { |
| 313 | return PLDM_SUCCESS; |
| 314 | } |
| 315 | |
| 316 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 317 | *transfer_flag = response->transfer_flag; |
| 318 | |
| 319 | *bios_table_offset = sizeof(*completion_code) + |
| 320 | sizeof(*next_transfer_handle) + |
| 321 | sizeof(*transfer_flag); |
| 322 | |
| 323 | return PLDM_SUCCESS; |
| 324 | } |
| 325 | |
| 326 | int encode_get_bios_attribute_current_value_by_handle_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 327 | uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag, |
| 328 | uint16_t attribute_handle, struct pldm_msg *msg) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 329 | { |
| 330 | if (msg == NULL) { |
| 331 | return PLDM_ERROR_INVALID_DATA; |
| 332 | } |
| 333 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 334 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 335 | header.msg_type = PLDM_REQUEST; |
| 336 | header.instance = instance_id; |
| 337 | header.pldm_type = PLDM_BIOS; |
| 338 | header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE; |
| 339 | |
| 340 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 341 | if (rc != PLDM_SUCCESS) { |
| 342 | return rc; |
| 343 | } |
| 344 | |
| 345 | struct pldm_get_bios_attribute_current_value_by_handle_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 346 | (struct pldm_get_bios_attribute_current_value_by_handle_req *) |
| 347 | msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 348 | |
| 349 | request->transfer_handle = htole32(transfer_handle); |
| 350 | request->transfer_op_flag = transfer_op_flag; |
| 351 | request->attribute_handle = htole16(attribute_handle); |
| 352 | return PLDM_SUCCESS; |
| 353 | } |
| 354 | |
| 355 | int decode_get_bios_attribute_current_value_by_handle_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 356 | const struct pldm_msg *msg, size_t payload_length, |
| 357 | uint8_t *completion_code, uint32_t *next_transfer_handle, |
| 358 | uint8_t *transfer_flag, struct variable_field *attribute_data) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 359 | { |
| 360 | if (msg == NULL || transfer_flag == NULL || |
| 361 | next_transfer_handle == NULL || completion_code == NULL) { |
| 362 | return PLDM_ERROR_INVALID_DATA; |
| 363 | } |
| 364 | |
| 365 | struct pldm_get_bios_attribute_current_value_by_handle_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 366 | (struct pldm_get_bios_attribute_current_value_by_handle_resp *) |
| 367 | msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 368 | |
| 369 | *completion_code = response->completion_code; |
| 370 | |
| 371 | if (PLDM_SUCCESS != *completion_code) { |
| 372 | return PLDM_SUCCESS; |
| 373 | } |
| 374 | |
| 375 | if (payload_length <= |
| 376 | PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) { |
| 377 | return PLDM_ERROR_INVALID_LENGTH; |
| 378 | } |
| 379 | |
| 380 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 381 | *transfer_flag = response->transfer_flag; |
| 382 | |
| 383 | attribute_data->ptr = response->attribute_data; |
| 384 | attribute_data->length = payload_length - sizeof(*response) + 1; |
| 385 | |
| 386 | return PLDM_SUCCESS; |
| 387 | } |
| 388 | |
| 389 | int decode_get_bios_attribute_current_value_by_handle_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 390 | const struct pldm_msg *msg, size_t payload_length, |
| 391 | uint32_t *transfer_handle, uint8_t *transfer_op_flag, |
| 392 | uint16_t *attribute_handle) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 393 | { |
| 394 | if (msg == NULL || transfer_handle == NULL || |
| 395 | transfer_op_flag == NULL || attribute_handle == NULL) { |
| 396 | return PLDM_ERROR_INVALID_DATA; |
| 397 | } |
| 398 | |
| 399 | if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) { |
| 400 | return PLDM_ERROR_INVALID_LENGTH; |
| 401 | } |
| 402 | |
| 403 | struct pldm_get_bios_attribute_current_value_by_handle_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 404 | (struct pldm_get_bios_attribute_current_value_by_handle_req *) |
| 405 | msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 406 | *transfer_handle = le32toh(request->transfer_handle); |
| 407 | *transfer_op_flag = request->transfer_op_flag; |
| 408 | *attribute_handle = le16toh(request->attribute_handle); |
| 409 | |
| 410 | return PLDM_SUCCESS; |
| 411 | } |
| 412 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 413 | int encode_get_bios_current_value_by_handle_resp(uint8_t instance_id, |
| 414 | uint8_t completion_code, |
| 415 | uint32_t next_transfer_handle, |
| 416 | uint8_t transfer_flag, |
| 417 | const uint8_t *attribute_data, |
| 418 | size_t attribute_length, |
| 419 | struct pldm_msg *msg) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 420 | { |
| 421 | if (msg == NULL || attribute_data == NULL) { |
| 422 | return PLDM_ERROR_INVALID_DATA; |
| 423 | } |
| 424 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 425 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 426 | header.msg_type = PLDM_RESPONSE; |
| 427 | header.instance = instance_id; |
| 428 | header.pldm_type = PLDM_BIOS; |
| 429 | header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE; |
| 430 | |
| 431 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 432 | if (rc != PLDM_SUCCESS) { |
| 433 | return rc; |
| 434 | } |
| 435 | |
| 436 | struct pldm_get_bios_attribute_current_value_by_handle_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 437 | (struct pldm_get_bios_attribute_current_value_by_handle_resp *) |
| 438 | msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 439 | response->completion_code = completion_code; |
| 440 | if (response->completion_code == PLDM_SUCCESS) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 441 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 442 | response->transfer_flag = transfer_flag; |
| 443 | if (attribute_data != NULL) { |
| 444 | memcpy(response->attribute_data, attribute_data, |
| 445 | attribute_length); |
| 446 | } |
| 447 | } |
| 448 | return PLDM_SUCCESS; |
| 449 | } |
| 450 | int encode_set_bios_attribute_current_value_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 451 | uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag, |
| 452 | const uint8_t *attribute_data, size_t attribute_length, |
| 453 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 454 | { |
| 455 | if (msg == NULL || attribute_data == NULL) { |
| 456 | return PLDM_ERROR_INVALID_DATA; |
| 457 | } |
| 458 | if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length != |
Andrew Jeffery | 9145a41 | 2023-04-05 20:24:50 +0930 | [diff] [blame] | 459 | payload_length) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 460 | return PLDM_ERROR_INVALID_LENGTH; |
| 461 | } |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 462 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 463 | header.instance = instance_id; |
| 464 | header.msg_type = PLDM_REQUEST; |
| 465 | header.pldm_type = PLDM_BIOS; |
| 466 | header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE; |
| 467 | |
| 468 | uint8_t rc = pack_pldm_header(&header, &msg->hdr); |
| 469 | if (rc != PLDM_SUCCESS) { |
| 470 | return rc; |
| 471 | } |
| 472 | |
| 473 | struct pldm_set_bios_attribute_current_value_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 474 | (struct pldm_set_bios_attribute_current_value_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 475 | request->transfer_handle = htole32(transfer_handle); |
| 476 | request->transfer_flag = transfer_flag; |
| 477 | memcpy(request->attribute_data, attribute_data, attribute_length); |
| 478 | |
| 479 | return PLDM_SUCCESS; |
| 480 | } |
| 481 | |
| 482 | int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg, |
| 483 | size_t payload_length, |
| 484 | uint8_t *completion_code, |
| 485 | uint32_t *next_transfer_handle) |
| 486 | { |
| 487 | if (msg == NULL || completion_code == NULL || |
| 488 | next_transfer_handle == NULL) { |
| 489 | return PLDM_ERROR_INVALID_DATA; |
| 490 | } |
| 491 | |
| 492 | *completion_code = msg->payload[0]; |
| 493 | if (PLDM_SUCCESS != *completion_code) { |
| 494 | return PLDM_SUCCESS; |
| 495 | } |
| 496 | |
| 497 | if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) { |
| 498 | return PLDM_ERROR_INVALID_LENGTH; |
| 499 | } |
| 500 | |
| 501 | struct pldm_set_bios_attribute_current_value_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 502 | (struct pldm_set_bios_attribute_current_value_resp *) |
| 503 | msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 504 | |
| 505 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 506 | |
| 507 | return PLDM_SUCCESS; |
| 508 | } |
| 509 | |
| 510 | int decode_set_bios_attribute_current_value_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 511 | const struct pldm_msg *msg, size_t payload_length, |
| 512 | uint32_t *transfer_handle, uint8_t *transfer_flag, |
| 513 | struct variable_field *attribute) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 514 | { |
| 515 | if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL || |
| 516 | attribute == NULL) { |
| 517 | return PLDM_ERROR_INVALID_DATA; |
| 518 | } |
| 519 | if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) { |
| 520 | return PLDM_ERROR_INVALID_LENGTH; |
| 521 | } |
| 522 | |
| 523 | struct pldm_set_bios_attribute_current_value_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 524 | (struct pldm_set_bios_attribute_current_value_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 525 | *transfer_handle = le32toh(request->transfer_handle); |
| 526 | *transfer_flag = request->transfer_flag; |
| 527 | attribute->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 528 | payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 529 | attribute->ptr = request->attribute_data; |
| 530 | return PLDM_SUCCESS; |
| 531 | } |
| 532 | |
| 533 | int encode_set_bios_attribute_current_value_resp(uint8_t instance_id, |
| 534 | uint8_t completion_code, |
| 535 | uint32_t next_transfer_handle, |
| 536 | struct pldm_msg *msg) |
| 537 | { |
| 538 | if (msg == NULL) { |
| 539 | return PLDM_ERROR_INVALID_DATA; |
| 540 | } |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 541 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 542 | header.instance = instance_id; |
| 543 | header.msg_type = PLDM_RESPONSE; |
| 544 | header.pldm_type = PLDM_BIOS; |
| 545 | header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE; |
| 546 | |
| 547 | uint8_t rc = pack_pldm_header(&header, &msg->hdr); |
| 548 | if (rc != PLDM_SUCCESS) { |
| 549 | return rc; |
| 550 | } |
| 551 | |
| 552 | struct pldm_set_bios_attribute_current_value_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 553 | (struct pldm_set_bios_attribute_current_value_resp *) |
| 554 | msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 555 | response->completion_code = completion_code; |
| 556 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 557 | |
| 558 | return PLDM_SUCCESS; |
| 559 | } |
| 560 | |
| 561 | int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle, |
| 562 | uint8_t transfer_flag, uint8_t table_type, |
| 563 | const uint8_t *table_data, size_t table_length, |
| 564 | struct pldm_msg *msg, size_t payload_length) |
| 565 | { |
| 566 | if (msg == NULL || table_data == NULL) { |
| 567 | return PLDM_ERROR_INVALID_DATA; |
| 568 | } |
| 569 | |
| 570 | if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length != |
| 571 | payload_length) { |
| 572 | return PLDM_ERROR_INVALID_LENGTH; |
| 573 | } |
| 574 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 575 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 576 | header.instance = instance_id; |
| 577 | header.msg_type = PLDM_REQUEST; |
| 578 | header.pldm_type = PLDM_BIOS; |
| 579 | header.command = PLDM_SET_BIOS_TABLE; |
| 580 | |
| 581 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 582 | if (rc != PLDM_SUCCESS) { |
| 583 | return rc; |
| 584 | } |
| 585 | |
| 586 | struct pldm_set_bios_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 587 | (struct pldm_set_bios_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 588 | request->transfer_handle = htole32(transfer_handle); |
| 589 | request->transfer_flag = transfer_flag; |
| 590 | request->table_type = table_type; |
| 591 | memcpy(request->table_data, table_data, table_length); |
| 592 | |
| 593 | return PLDM_SUCCESS; |
| 594 | } |
| 595 | |
| 596 | int decode_set_bios_table_resp(const struct pldm_msg *msg, |
| 597 | size_t payload_length, uint8_t *completion_code, |
| 598 | uint32_t *next_transfer_handle) |
| 599 | { |
| 600 | if (msg == NULL || completion_code == NULL || |
| 601 | next_transfer_handle == NULL) { |
| 602 | return PLDM_ERROR_INVALID_DATA; |
| 603 | } |
| 604 | |
| 605 | *completion_code = msg->payload[0]; |
| 606 | if (PLDM_SUCCESS != *completion_code) { |
| 607 | return PLDM_SUCCESS; |
| 608 | } |
| 609 | |
| 610 | if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) { |
| 611 | return PLDM_ERROR_INVALID_LENGTH; |
| 612 | } |
| 613 | |
| 614 | struct pldm_set_bios_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 615 | (struct pldm_set_bios_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 616 | |
| 617 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 618 | |
| 619 | return PLDM_SUCCESS; |
| 620 | } |
| 621 | |
| 622 | int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 623 | uint32_t next_transfer_handle, |
| 624 | struct pldm_msg *msg) |
| 625 | { |
| 626 | if (msg == NULL) { |
| 627 | return PLDM_ERROR_INVALID_DATA; |
| 628 | } |
| 629 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 630 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 631 | header.instance = instance_id; |
| 632 | header.msg_type = PLDM_RESPONSE; |
| 633 | header.pldm_type = PLDM_BIOS; |
| 634 | header.command = PLDM_SET_BIOS_TABLE; |
| 635 | |
| 636 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 637 | if (rc != PLDM_SUCCESS) { |
| 638 | return rc; |
| 639 | } |
| 640 | |
| 641 | struct pldm_set_bios_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 642 | (struct pldm_set_bios_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 643 | response->completion_code = completion_code; |
| 644 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 645 | |
| 646 | return PLDM_SUCCESS; |
| 647 | } |
| 648 | |
| 649 | int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length, |
| 650 | uint32_t *transfer_handle, uint8_t *transfer_flag, |
| 651 | uint8_t *table_type, struct variable_field *table) |
| 652 | { |
| 653 | if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL || |
| 654 | table_type == NULL || table == NULL) { |
| 655 | return PLDM_ERROR_INVALID_DATA; |
| 656 | } |
| 657 | |
| 658 | if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) { |
| 659 | return PLDM_ERROR_INVALID_LENGTH; |
| 660 | } |
| 661 | |
| 662 | struct pldm_set_bios_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 663 | (struct pldm_set_bios_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 664 | *transfer_handle = le32toh(request->transfer_handle); |
| 665 | *transfer_flag = request->transfer_flag; |
| 666 | *table_type = request->table_type; |
| 667 | table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES; |
| 668 | table->ptr = request->table_data; |
| 669 | |
| 670 | return PLDM_SUCCESS; |
| 671 | } |