/**
 * 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).\n");
        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).\n");
        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.\n", 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];
        timestamp_to_string(timestamp_string, &header->TimeStamp);
        
        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)
            || guid_equal(&section_descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
        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)
{
    //Save our current position in the stream.
    long position = ftell(handle);

    //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.\n", 
            descriptor->SectionLength,
            descriptor->SectionOffset);
        free(section);
        return NULL;
    }

    //Seek back to our original position.
    fseek(handle, position, SEEK_SET);

    //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;
}