/**
 * Describes high level functions for converting an entire CPER log, and functions for parsing 
 * CPER headers and section descriptions into an intermediate JSON format.
 * 
 * Author: Lawrence.Tang@arm.com
 **/

#include <stdio.h>
#include "json.h"
#include "b64.h"
#include "edk/Cper.h"
#include "cper-parse.h"
#include "cper-utils.h"
#include "sections/cper-section-generic.h"
#include "sections/cper-section-ia32x64.h"
#include "sections/cper-section-arm.h"
#include "sections/cper-section-memory.h"
#include "sections/cper-section-pcie.h"
#include "sections/cper-section-pci-bus.h"
#include "sections/cper-section-pci-dev.h"
#include "sections/cper-section-firmware.h"
#include "sections/cper-section-dmar-generic.h"
#include "sections/cper-section-dmar-vtd.h"
#include "sections/cper-section-dmar-iommu.h"
#include "sections/cper-section-ccix-per.h"
#include "sections/cper-section-cxl-protocol.h"
#include "sections/cper-section-ipf.h"
#include "sections/cper-section-cxl-component.h"

//Private pre-definitions.
json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header);
json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor);
json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);

//Reads a CPER log file at the given file location, and returns an intermediate
//JSON representation of this CPER record.
json_object* cper_to_ir(FILE* cper_file) 
{
    //Ensure this is really a CPER log.
    EFI_COMMON_ERROR_RECORD_HEADER header;
    fseek(cper_file, 0, SEEK_SET);
    if (fread(&header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, cper_file) != 1)
    {
        printf("Invalid CPER file: Invalid length (log too short).");
        return NULL;
    }

    //Check if the header contains the magic bytes ("CPER").
    if (header.SignatureStart != EFI_ERROR_RECORD_SIGNATURE_START) {
        printf("Invalid CPER file: Invalid header (incorrect signature).");
        return NULL;
    }

    //Create the header JSON object from the read bytes.
    json_object* header_ir = cper_header_to_ir(&header);

    //Read the appropriate number of section descriptors & sections, and convert them into IR format.
    json_object* section_descriptors_ir = json_object_new_array();
    json_object* sections_ir = json_object_new_array();
    for (int i=0; i<header.SectionCount; i++)
    {
        //Create the section descriptor.
        EFI_ERROR_SECTION_DESCRIPTOR section_descriptor;
        if (fread(&section_descriptor, sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, cper_file) != 1)
        {
            printf("Invalid number of section headers: Header states %d sections, could not read section %d.", header.SectionCount, i+1);
            return NULL;
        }
        json_object_array_add(section_descriptors_ir, cper_section_descriptor_to_ir(&section_descriptor));

        //Read the section itself.
        json_object_array_add(sections_ir, cper_section_to_ir(cper_file, &section_descriptor));
    }

    //Add the header, section descriptors, and sections to a parent object.
    json_object* parent = json_object_new_object();
    json_object_object_add(parent, "header", header_ir);
    json_object_object_add(parent, "sectionDescriptors", section_descriptors_ir);
    json_object_object_add(parent, "sections", sections_ir);

    return parent;
}

//Converts a parsed CPER record header into intermediate JSON object format.
json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header) 
{
    json_object* header_ir = json_object_new_object();

    //Revision/version information.
    json_object_object_add(header_ir, "revision", revision_to_ir(header->Revision));

    //Section count.
    json_object_object_add(header_ir, "sectionCount", json_object_new_int(header->SectionCount));

    //Error severity (with interpreted string version).
    json_object* error_severity = json_object_new_object();
    json_object_object_add(error_severity, "code", json_object_new_int(header->ErrorSeverity));
    json_object_object_add(error_severity, "name", json_object_new_string(severity_to_string(header->ErrorSeverity)));
    json_object_object_add(header_ir, "severity", error_severity);

    //The validation bits for each section.
    json_object* validation_bits = bitfield_to_ir(header->ValidationBits, 3, CPER_HEADER_VALID_BITFIELD_NAMES);
    json_object_object_add(header_ir, "validationBits", validation_bits);

    //Total length of the record (including headers) in bytes.
    json_object_object_add(header_ir, "recordLength", json_object_new_int(header->RecordLength));

    //If a timestamp exists according to validation bits, then add it.
    if (header->ValidationBits & 0b10)
    {
        char timestamp_string[TIMESTAMP_LENGTH];
        sprintf(timestamp_string, "%02d%02d-%02d-%02dT%02d:%02d:%02d.000", 
            header->TimeStamp.Century,
            header->TimeStamp.Year,
            header->TimeStamp.Month,
            header->TimeStamp.Day,
            header->TimeStamp.Hours,
            header->TimeStamp.Minutes,
            header->TimeStamp.Seconds);

        json_object_object_add(header_ir, "timestamp", json_object_new_string(timestamp_string));
        json_object_object_add(header_ir, "timestampIsPrecise", json_object_new_boolean(header->TimeStamp.Flag));
    }

    //If a platform ID exists according to the validation bits, then add it.
    if (header->ValidationBits & 0b1) 
    {
        char platform_string[GUID_STRING_LENGTH];
        guid_to_string(platform_string, &header->PlatformID);
        json_object_object_add(header_ir, "platformID", json_object_new_string(platform_string));
    }

    //If a partition ID exists according to the validation bits, then add it.
    if (header->ValidationBits & 0b100)
    {
        char partition_string[GUID_STRING_LENGTH];
        guid_to_string(partition_string, &header->PartitionID);
        json_object_object_add(header_ir, "partitionID", json_object_new_string(partition_string));
    }

    //Creator ID of the header.
    char creator_string[GUID_STRING_LENGTH];
    guid_to_string(creator_string, &header->CreatorID);
    json_object_object_add(header_ir, "creatorID", json_object_new_string(creator_string));

    //Notification type for the header. Some defined types are available.
    json_object* notification_type = json_object_new_object();
    char notification_type_string[GUID_STRING_LENGTH];
    guid_to_string(notification_type_string, &header->NotificationType);
    json_object_object_add(notification_type, "guid", json_object_new_string(notification_type_string));
    
    //Add the human readable notification type if possible.
    char* notification_type_readable = "Unknown";
    if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCmcGuid))
        notification_type_readable = "CMC";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid))
        notification_type_readable = "CPE";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid))
        notification_type_readable = "MCE";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid))
        notification_type_readable = "PCIe";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid))
        notification_type_readable = "INIT";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid))
        notification_type_readable = "NMI";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid))
        notification_type_readable = "Boot";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid))
        notification_type_readable = "DMAr";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid))
        notification_type_readable = "SEA";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid))
        notification_type_readable = "SEI";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid))
        notification_type_readable = "PEI";
    else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCxlGuid))
        notification_type_readable = "CXL Component";
    json_object_object_add(notification_type, "type", json_object_new_string(notification_type_readable));
    json_object_object_add(header_ir, "notificationType", notification_type);

    //The record ID for this record, unique on a given system.
    json_object_object_add(header_ir, "recordID", json_object_new_uint64(header->RecordID));

    //Flag for the record, and a human readable form.
    json_object* flags = integer_to_readable_pair(header->Flags,
        sizeof(CPER_HEADER_FLAG_TYPES_KEYS) / sizeof(int),
        CPER_HEADER_FLAG_TYPES_KEYS,
        CPER_HEADER_FLAG_TYPES_VALUES,
        "Unknown");
    json_object_object_add(header_ir, "flags", flags);

    //Persistence information. Outside the scope of specification, so just a uint32 here.
    json_object_object_add(header_ir, "persistenceInformation", json_object_new_uint64(header->PersistenceInfo));
    return header_ir;
}

//Converts the given EFI section descriptor into JSON IR format.
json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor)
{
    json_object* section_descriptor_ir = json_object_new_object();

    //The offset of the section from the base of the record header, length.
    json_object_object_add(section_descriptor_ir, "sectionOffset", json_object_new_int(section_descriptor->SectionOffset));
    json_object_object_add(section_descriptor_ir, "sectionLength", json_object_new_int(section_descriptor->SectionLength));

    //Revision.
    json_object_object_add(section_descriptor_ir, "revision", revision_to_ir(section_descriptor->Revision));

    //Validation bits.
    json_object* validation_bits = json_object_new_object();
    json_object_object_add(validation_bits, "fruID", json_object_new_boolean(section_descriptor->SecValidMask & 0b1));
    json_object_object_add(validation_bits, "fruString", json_object_new_boolean((section_descriptor->SecValidMask & 0b10) >> 1));
    json_object_object_add(section_descriptor_ir, "validationBits", validation_bits);

    //Flag bits.
    json_object* flags = bitfield_to_ir(section_descriptor->SectionFlags, 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
    json_object_object_add(section_descriptor_ir, "flags", flags);

    //Section type (GUID).
    json_object* section_type = json_object_new_object();
    char section_type_string[GUID_STRING_LENGTH];
    guid_to_string(section_type_string, &section_descriptor->SectionType);
    json_object_object_add(section_type, "data", json_object_new_string(section_type_string));

    //Readable section type, if possible.
    char* section_type_readable = "Unknown";
    if (guid_equal(&section_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
        section_type_readable = "Processor Generic";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
        section_type_readable = "IA32/X64";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
         section_type_readable = "IPF";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
        section_type_readable = "ARM";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
        section_type_readable = "Platform Memory";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiPcieErrorSectionGuid))
        section_type_readable = "PCIe";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
        section_type_readable = "Firmware Error Record Reference";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
        section_type_readable = "PCI/PCI-X Bus";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
        section_type_readable = "PCI Component/Device";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
        section_type_readable = "DMAr Generic";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
        section_type_readable = "Intel VT for Directed I/O specific DMAr section";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
        section_type_readable = "IOMMU specific DMAr section";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
        section_type_readable = "CCIX PER Log Error";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
        section_type_readable = "CXL Protocol Error";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid))
        section_type_readable = "CXL General Media Component Error";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid))
        section_type_readable = "CXL DRAM Component Error";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid))
        section_type_readable = "CXL Physical Switch Component Error";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid))
        section_type_readable = "CXL Virtual Switch Component Error";
    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
        section_type_readable = "CXL MLD Port Component Error";

    json_object_object_add(section_type, "type", json_object_new_string(section_type_readable));
    json_object_object_add(section_descriptor_ir, "sectionType", section_type);

    //If validation bits indicate it exists, add FRU ID.
    if (section_descriptor->SecValidMask & 0b1)
    {
        char fru_id_string[GUID_STRING_LENGTH];
        guid_to_string(fru_id_string, &section_descriptor->FruId);
        json_object_object_add(section_descriptor_ir, "fruID", json_object_new_string(fru_id_string));
    }

    //If validation bits indicate it exists, add FRU text.
    if ((section_descriptor->SecValidMask & 0b10) >> 1)
        json_object_object_add(section_descriptor_ir, "fruText", json_object_new_string(section_descriptor->FruString));

    //Section severity.
    json_object* section_severity = json_object_new_object();
    json_object_object_add(section_severity, "code", json_object_new_int(section_descriptor->Severity));
    json_object_object_add(section_severity, "name", json_object_new_string(severity_to_string(section_descriptor->Severity)));
    json_object_object_add(section_descriptor_ir, "severity", section_severity);

    return section_descriptor_ir;
}


//Converts the section described by a single given section descriptor.
json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
{
    //Read section as described by the section descriptor.
    fseek(handle, descriptor->SectionOffset, SEEK_SET);
    void* section = malloc(descriptor->SectionLength);
    if (fread(section, descriptor->SectionLength, 1, handle) != 1)
    {
        printf("Section read failed: Could not read %d bytes from global offset %d.", 
            descriptor->SectionLength,
            descriptor->SectionOffset);
        free(section);
        return NULL;
    }

    //Parse section to IR based on GUID.
    json_object* result = NULL;
    if (guid_equal(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
        result = cper_section_generic_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
        result = cper_section_ia32x64_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
        result = cper_section_ipf_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
        result = cper_section_arm_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
        result = cper_section_platform_memory_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
        result = cper_section_platform_memory2_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiPcieErrorSectionGuid))
        result = cper_section_pcie_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
        result = cper_section_firmware_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
        result = cper_section_pci_bus_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
        result = cper_section_pci_dev_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
        result = cper_section_dmar_generic_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
        result = cper_section_dmar_vtd_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
        result = cper_section_dmar_iommu_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
        result = cper_section_ccix_per_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
        result = cper_section_cxl_protocol_to_ir(section, descriptor);
    else if (guid_equal(&descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid)
          || guid_equal(&descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid)
          || guid_equal(&descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid)
          || guid_equal(&descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid)
          || guid_equal(&descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
    {
        result = cper_section_cxl_component_to_ir(section, descriptor);
    }
    else
    {
        //Failed read, unknown GUID.
        //Output the data as formatted base64.
        result = json_object_new_object();
        char* encoded = b64_encode((unsigned char*)section, descriptor->SectionLength);
        json_object_object_add(result, "data", json_object_new_string(encoded));
        free(encoded);
    }

    //Free section memory, return result.
    free(section);
    return result;
}