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