/**
 * 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_uint64(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_uint64(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, "persistenceInfo", 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_uint64(section_descriptor->SectionOffset));
    json_object_object_add(section_descriptor_ir, "sectionLength", json_object_new_uint64(section_descriptor->SectionLength));

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

    //Validation bits.
    json_object* validation_bits = bitfield_to_ir(section_descriptor->SecValidMask, 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
    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_uint64(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;
}