| /** |
| * Describes functions for converting firmware CPER sections from binary and JSON format |
| * into an intermediate format. |
| * |
| * Author: Lawrence.Tang@arm.com |
| **/ |
| #include <stdio.h> |
| #include <json.h> |
| #include <libcper/Cper.h> |
| #include <libcper/cper-utils.h> |
| #include <libcper/sections/cper-section-firmware.h> |
| |
| //Converts a single firmware CPER section into JSON IR. |
| json_object *cper_section_firmware_to_ir(void *section) |
| { |
| EFI_FIRMWARE_ERROR_DATA *firmware_error = |
| (EFI_FIRMWARE_ERROR_DATA *)section; |
| json_object *section_ir = json_object_new_object(); |
| |
| //Record type. |
| json_object *record_type = integer_to_readable_pair( |
| firmware_error->ErrorType, 3, FIRMWARE_ERROR_RECORD_TYPES_KEYS, |
| FIRMWARE_ERROR_RECORD_TYPES_VALUES, "Unknown (Reserved)"); |
| json_object_object_add(section_ir, "errorRecordType", record_type); |
| |
| //Revision, record identifier. |
| json_object_object_add(section_ir, "revision", |
| json_object_new_int(firmware_error->Revision)); |
| json_object_object_add( |
| section_ir, "recordID", |
| json_object_new_uint64(firmware_error->RecordId)); |
| |
| //Record GUID. |
| char record_id_guid[GUID_STRING_LENGTH]; |
| guid_to_string(record_id_guid, &firmware_error->RecordIdGuid); |
| json_object_object_add(section_ir, "recordIDGUID", |
| json_object_new_string(record_id_guid)); |
| |
| return section_ir; |
| } |
| |
| //Converts a single firmware CPER-JSON section into CPER binary, outputting to the given stream. |
| void ir_section_firmware_to_cper(json_object *section, FILE *out) |
| { |
| EFI_FIRMWARE_ERROR_DATA *section_cper = |
| (EFI_FIRMWARE_ERROR_DATA *)calloc( |
| 1, sizeof(EFI_FIRMWARE_ERROR_DATA)); |
| |
| //Record fields. |
| section_cper->ErrorType = readable_pair_to_integer( |
| json_object_object_get(section, "errorRecordType")); |
| section_cper->Revision = json_object_get_int( |
| json_object_object_get(section, "revision")); |
| section_cper->RecordId = json_object_get_uint64( |
| json_object_object_get(section, "recordID")); |
| string_to_guid(§ion_cper->RecordIdGuid, |
| json_object_get_string(json_object_object_get( |
| section, "recordIDGUID"))); |
| |
| //Write to stream, free resources. |
| fwrite(section_cper, sizeof(EFI_FIRMWARE_ERROR_DATA), 1, out); |
| fflush(out); |
| free(section_cper); |
| } |