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