/**
 * 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 "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-firmware.h"

//Converts a single firmware CPER section into JSON IR.
json_object* cper_section_firmware_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
{
    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, "revision"));
    string_to_guid(&section_cper->RecordIdGuid, 
        json_object_get_string(json_object_object_get(section, "recordIDGUID")));

    //Write to stream, free resources.
    fwrite(&section_cper, sizeof(section_cper), 1, out);
    fflush(out);
    free(section_cper);
}