Make key types based on id

This commit separates out the libcper json output by section name.
Previously, each section was

i.e., for e.g., add "Nvidia" for the NVIDIA section
```
  "sections": [
    {
      "Nvidia":{
          "socket": 0
      }
    }
  ]
```
instead of
```
  "sections": [
    {
        "socket": 0
    }
  ]
```

This allows disambiguating between multiple fields with different types
and removes collisions between the field names.

Change-Id: I4e257f1e04fc5fbf2798955d3a5d93214c81f0fc
Signed-off-by: Karthik Rajagopalan <krajagopalan@nvidia.com>
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/cper-parse.c b/cper-parse.c
index 8c8722d..afedc9d 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -342,12 +342,20 @@
 
 	//Parse section to IR based on GUID.
 	json_object *result = NULL;
+
+	json_object *section_ir = NULL;
 	int section_converted = 0;
 	for (size_t i = 0; i < section_definitions_len; i++) {
 		if (guid_equal(section_definitions[i].Guid,
 			       &descriptor->SectionType) &&
 		    section_definitions[i].ToIR != NULL) {
-			result = section_definitions[i].ToIR(section);
+			section_ir = section_definitions[i].ToIR(section);
+
+			result = json_object_new_object();
+			json_object_object_add(result,
+					       section_definitions[i].ShortName,
+					       section_ir);
+
 			section_converted = 1;
 			break;
 		}
@@ -356,20 +364,23 @@
 	//Was it an unknown GUID/failed read?
 	if (!section_converted) {
 		//Output the data as formatted base64.
-		result = json_object_new_object();
-
 		int32_t encoded_len = 0;
 		char *encoded = base64_encode(
 			section, descriptor->SectionLength, &encoded_len);
 		if (encoded == NULL) {
 			printf("Failed to allocate encode output buffer. \n");
 		} else {
-			json_object_object_add(result, "data",
+			section_ir = json_object_new_object();
+			json_object_object_add(section_ir, "data",
 					       json_object_new_string_len(
 						       encoded, encoded_len));
 			free(encoded);
+
+			result = json_object_new_object();
+			json_object_object_add(result, "Unknown", section_ir);
 		}
 	}
+
 	//Free section memory, return result.
 	free(section);
 	return result;
diff --git a/ir-parse.c b/ir-parse.c
index 517de45..2aadc81 100644
--- a/ir-parse.c
+++ b/ir-parse.c
@@ -156,13 +156,17 @@
 void ir_section_to_cper(json_object *section,
 			EFI_ERROR_SECTION_DESCRIPTOR *descriptor, FILE *out)
 {
+	json_object *ir = NULL;
+
 	//Find the correct section type, and parse.
 	int section_converted = 0;
 	for (size_t i = 0; i < section_definitions_len; i++) {
 		if (guid_equal(section_definitions[i].Guid,
 			       &descriptor->SectionType) &&
 		    section_definitions[i].ToCPER != NULL) {
-			section_definitions[i].ToCPER(section, out);
+			ir = json_object_object_get(
+				section, section_definitions[i].ShortName);
+			section_definitions[i].ToCPER(ir, out);
 			section_converted = 1;
 			break;
 		}
@@ -170,7 +174,8 @@
 
 	//If unknown GUID, so read as a base64 unknown section.
 	if (!section_converted) {
-		json_object *encoded = json_object_object_get(section, "data");
+		ir = json_object_object_get(section, "Unknown");
+		json_object *encoded = json_object_object_get(ir, "data");
 
 		int32_t decoded_len = 0;
 
diff --git a/sections/cper-section.c b/sections/cper-section.c
index defecf6..63ce9f8 100644
--- a/sections/cper-section.c
+++ b/sections/cper-section.c
@@ -26,55 +26,59 @@
 //Definitions of all sections available to the CPER parser.
 CPER_SECTION_DEFINITION section_definitions[] = {
 	{ &gEfiProcessorGenericErrorSectionGuid, "Processor Generic",
-	  cper_section_generic_to_ir, ir_section_generic_to_cper },
-	{ &gEfiIa32X64ProcessorErrorSectionGuid, "IA32/X64",
+	  "GenericProcessor", cper_section_generic_to_ir,
+	  ir_section_generic_to_cper },
+	{ &gEfiIa32X64ProcessorErrorSectionGuid, "IA32/X64", "Ia32x64Processor",
 	  cper_section_ia32x64_to_ir, ir_section_ia32x64_to_cper },
-	{ &gEfiIpfProcessorErrorSectionGuid, "IPF", NULL, NULL },
-	{ &gEfiArmProcessorErrorSectionGuid, "ARM", cper_section_arm_to_ir,
-	  ir_section_arm_to_cper },
-	{ &gEfiPlatformMemoryErrorSectionGuid, "Platform Memory",
+	{ &gEfiIpfProcessorErrorSectionGuid, "IPF", "IPF", NULL, NULL },
+	{ &gEfiArmProcessorErrorSectionGuid, "ARM", "ArmProcessor",
+	  cper_section_arm_to_ir, ir_section_arm_to_cper },
+	{ &gEfiPlatformMemoryErrorSectionGuid, "Platform Memory", "Memory",
 	  cper_section_platform_memory_to_ir, ir_section_memory_to_cper },
-	{ &gEfiPlatformMemoryError2SectionGuid, "Platform Memory 2",
+	{ &gEfiPlatformMemoryError2SectionGuid, "Platform Memory 2", "Memory2",
 	  cper_section_platform_memory2_to_ir, ir_section_memory2_to_cper },
-	{ &gEfiPcieErrorSectionGuid, "PCIe", cper_section_pcie_to_ir,
+	{ &gEfiPcieErrorSectionGuid, "PCIe", "Pcie", cper_section_pcie_to_ir,
 	  ir_section_pcie_to_cper },
 	{ &gEfiFirmwareErrorSectionGuid, "Firmware Error Record Reference",
-	  cper_section_firmware_to_ir, ir_section_firmware_to_cper },
-	{ &gEfiPciBusErrorSectionGuid, "PCI/PCI-X Bus",
+	  "Firmware", cper_section_firmware_to_ir,
+	  ir_section_firmware_to_cper },
+	{ &gEfiPciBusErrorSectionGuid, "PCI/PCI-X Bus", "PciBus",
 	  cper_section_pci_bus_to_ir, ir_section_pci_bus_to_cper },
-	{ &gEfiPciDevErrorSectionGuid, "PCI Component/Device",
+	{ &gEfiPciDevErrorSectionGuid, "PCI Component/Device", "PciComponent",
 	  cper_section_pci_dev_to_ir, ir_section_pci_dev_to_cper },
-	{ &gEfiDMArGenericErrorSectionGuid, "DMAr Generic",
+	{ &gEfiDMArGenericErrorSectionGuid, "DMAr Generic", "GenericDmar",
 	  cper_section_dmar_generic_to_ir, ir_section_dmar_generic_to_cper },
 	{ &gEfiDirectedIoDMArErrorSectionGuid,
-	  "Intel VT for Directed I/O Specific DMAr",
+	  "Intel VT for Directed I/O Specific DMAr", "VtdDmar",
 	  cper_section_dmar_vtd_to_ir, ir_section_dmar_vtd_to_cper },
-	{ &gEfiIommuDMArErrorSectionGuid, "IOMMU Specific DMAr",
+	{ &gEfiIommuDMArErrorSectionGuid, "IOMMU Specific DMAr", "IommuDmar",
 	  cper_section_dmar_iommu_to_ir, ir_section_dmar_iommu_to_cper },
-	{ &gEfiCcixPerLogErrorSectionGuid, "CCIX PER Log Error",
+	{ &gEfiCcixPerLogErrorSectionGuid, "CCIX PER Log Error", "CcixPer",
 	  cper_section_ccix_per_to_ir, ir_section_ccix_per_to_cper },
-	{ &gEfiCxlProtocolErrorSectionGuid, "CXL Protocol Error",
+	{ &gEfiCxlProtocolErrorSectionGuid, "CXL Protocol Error", "CxlProtocol",
 	  cper_section_cxl_protocol_to_ir, ir_section_cxl_protocol_to_cper },
 	{ &gEfiCxlGeneralMediaErrorSectionGuid,
-	  "CXL General Media Component Error", cper_section_cxl_component_to_ir,
-	  ir_section_cxl_component_to_cper },
-	{ &gEfiCxlDramEventErrorSectionGuid, "CXL DRAM Component Error",
+	  "CXL General Media Component Error", "CxlComponent",
 	  cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
-	{ &gEfiCxlMemoryModuleErrorSectionGuid,
-	  "CXL Memory Module Component Error", cper_section_cxl_component_to_ir,
+	{ &gEfiCxlDramEventErrorSectionGuid, "CXL DRAM Component Error",
+	  "CxlComponent", cper_section_cxl_component_to_ir,
 	  ir_section_cxl_component_to_cper },
+	{ &gEfiCxlMemoryModuleErrorSectionGuid,
+	  "CXL Memory Module Component Error", "CxlComponent",
+	  cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
 	{ &gEfiCxlPhysicalSwitchErrorSectionGuid,
-	  "CXL Physical Switch Component Error",
+	  "CXL Physical Switch Component Error", "CxlComponent",
 	  cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
 	{ &gEfiCxlVirtualSwitchErrorSectionGuid,
-	  "CXL Virtual Switch Component Error",
+	  "CXL Virtual Switch Component Error", "CxlComponent",
 	  cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
 	{ &gEfiCxlMldPortErrorSectionGuid, "CXL MLD Port Component Error",
-	  cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
-	{ &gEfiNvidiaErrorSectionGuid, "NVIDIA", cper_section_nvidia_to_ir,
-	  ir_section_nvidia_to_cper },
-	{ &gEfiAmpereErrorSectionGuid, "Ampere", cper_section_ampere_to_ir,
-	  ir_section_ampere_to_cper },
+	  "CxlComponent", cper_section_cxl_component_to_ir,
+	  ir_section_cxl_component_to_cper },
+	{ &gEfiNvidiaErrorSectionGuid, "NVIDIA", "Nvidia",
+	  cper_section_nvidia_to_ir, ir_section_nvidia_to_cper },
+	{ &gEfiAmpereErrorSectionGuid, "Ampere", "Ampere",
+	  cper_section_ampere_to_ir, ir_section_ampere_to_cper },
 };
 const size_t section_definitions_len =
 	sizeof(section_definitions) / sizeof(CPER_SECTION_DEFINITION);
diff --git a/sections/cper-section.h b/sections/cper-section.h
index 71cf4b1..4ccc178 100644
--- a/sections/cper-section.h
+++ b/sections/cper-section.h
@@ -14,6 +14,7 @@
 typedef struct {
 	EFI_GUID *Guid;
 	const char *ReadableName;
+	const char *ShortName;
 	json_object *(*ToIR)(void *);
 	void (*ToCPER)(json_object *, FILE *);
 } CPER_SECTION_DEFINITION;
diff --git a/specification/json/cper-json-full-log.json b/specification/json/cper-json-full-log.json
index b4dd875..2b5931a 100644
--- a/specification/json/cper-json-full-log.json
+++ b/specification/json/cper-json-full-log.json
@@ -1,4 +1,6 @@
 {
+    "$id": "cper-json-full-log",
+    "$schema": "https://json-schema.org/draft/2020-12/schema",
     "type": "object",
     "required": ["header", "sectionDescriptors", "sections"],
     "additionalProperties": false,
@@ -18,24 +20,132 @@
             "items": {
                 "type": "object",
                 "oneOf": [
-                    { "$ref": "./sections/cper-generic-processor.json" },
-                    { "$ref": "./sections/cper-ia32x64-processor.json" },
-                    { "$ref": "./sections/cper-arm-processor.json" },
-                    { "$ref": "./sections/cper-memory.json" },
-                    { "$ref": "./sections/cper-memory2.json" },
-                    { "$ref": "./sections/cper-pcie.json" },
-                    { "$ref": "./sections/cper-pci-bus.json" },
-                    { "$ref": "./sections/cper-pci-component.json" },
-                    { "$ref": "./sections/cper-firmware.json" },
-                    { "$ref": "./sections/cper-generic-dmar.json" },
-                    { "$ref": "./sections/cper-vtd-dmar.json" },
-                    { "$ref": "./sections/cper-iommu-dmar.json" },
-                    { "$ref": "./sections/cper-ccix-per.json" },
-                    { "$ref": "./sections/cper-cxl-protocol.json" },
-                    { "$ref": "./sections/cper-cxl-component.json" },
-                    { "$ref": "./sections/cper-nvidia.json" },
-                    { "$ref": "./sections/cper-ampere.json" },
-                    { "$ref": "./sections/cper-unknown.json" }
+                    {
+                        "type": "object",
+                        "required": ["GenericProcessor"],
+                        "GenericProcessor": {
+                            "$ref": "./sections/cper-generic-processor.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Ia32x64Processor"],
+                        "Ia32x64Processor": {
+                            "$ref": "./sections/cper-ia32x64-processor.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["ArmProcessor"],
+                        "ArmProcessor": {
+                            "$ref": "./sections/cper-arm-processor.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Memory"],
+                        "Memory": {
+                            "$ref": "./sections/cper-memory.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Memory2"],
+                        "Memory2": {
+                            "$ref": "./sections/cper-memory2.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Pcie"],
+                        "Pcie": {
+                            "$ref": "./sections/cper-pcie.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["PciBus"],
+                        "PciBus": {
+                            "$ref": "./sections/cper-pci-bus.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["PciComponent"],
+                        "PciComponent": {
+                            "$ref": "./sections/cper-pci-component.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Firmware"],
+                        "Firmware": {
+                            "$ref": "./sections/cper-firmware.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["GenericDmar"],
+                        "GenericDmar": {
+                            "$ref": "./sections/cper-generic-dmar.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["VtdDmar"],
+                        "VtdDmar": {
+                            "$ref": "./sections/cper-vtd-dmar.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["IommuDmar"],
+                        "IommuDmar": {
+                            "$ref": "./sections/cper-iommu-dmar.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["CcixPer"],
+                        "CcixPer": {
+                            "$ref": "./sections/cper-ccix-per.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["CxlProtocol"],
+                        "CxlProtocol": {
+                            "$ref": "./sections/cper-cxl-protocol.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["CxlComponent"],
+                        "CxlComponent": {
+                            "$ref": "./sections/cper-cxl-component.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Nvidia"],
+                        "Nvidia": {
+                            "$ref": "./sections/cper-nvidia.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Ampere"],
+                        "Nvidia": {
+                            "$ref": "./sections/cper-ampere.json"
+                        }
+                    },
+                    {
+                        "type": "object",
+                        "required": ["Unknown"],
+                        "Unknown": {
+                            "$ref": "./sections/cper-unknown.json"
+                        }
+                    }
                 ]
             }
         }
diff --git a/specification/json/cper-json-section-log.json b/specification/json/cper-json-section-log.json
index 0909197..2cbe621 100644
--- a/specification/json/cper-json-section-log.json
+++ b/specification/json/cper-json-section-log.json
@@ -12,24 +12,132 @@
         "section": {
             "type": "object",
             "oneOf": [
-                { "$ref": "./sections/cper-generic-processor.json" },
-                { "$ref": "./sections/cper-ia32x64-processor.json" },
-                { "$ref": "./sections/cper-arm-processor.json" },
-                { "$ref": "./sections/cper-memory.json" },
-                { "$ref": "./sections/cper-memory2.json" },
-                { "$ref": "./sections/cper-pcie.json" },
-                { "$ref": "./sections/cper-pci-bus.json" },
-                { "$ref": "./sections/cper-pci-component.json" },
-                { "$ref": "./sections/cper-firmware.json" },
-                { "$ref": "./sections/cper-generic-dmar.json" },
-                { "$ref": "./sections/cper-vtd-dmar.json" },
-                { "$ref": "./sections/cper-iommu-dmar.json" },
-                { "$ref": "./sections/cper-ccix-per.json" },
-                { "$ref": "./sections/cper-cxl-protocol.json" },
-                { "$ref": "./sections/cper-cxl-component.json" },
-                { "$ref": "./sections/cper-nvidia.json" },
-                { "$ref": "./sections/cper-ampere.json" },
-                { "$ref": "./sections/cper-unknown.json" }
+                {
+                    "type": "object",
+                    "required": ["GenericProcessor"],
+                    "GenericProcessor": {
+                        "$ref": "./sections/cper-generic-processor.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Ia32x64Processor"],
+                    "Ia32x64Processor": {
+                        "$ref": "./sections/cper-ia32x64-processor.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["ArmProcessor"],
+                    "ArmProcessor": {
+                        "$ref": "./sections/cper-arm-processor.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Memory"],
+                    "Memory": {
+                        "$ref": "./sections/cper-memory.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Memory2"],
+                    "Memory2": {
+                        "$ref": "./sections/cper-memory2.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Pcie"],
+                    "Pcie": {
+                        "$ref": "./sections/cper-pcie.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["PciBus"],
+                    "PciBus": {
+                        "$ref": "./sections/cper-pci-bus.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["PciComponent"],
+                    "PciComponent": {
+                        "$ref": "./sections/cper-pci-component.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Firmware"],
+                    "Firmware": {
+                        "$ref": "./sections/cper-firmware.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["GenericDmar"],
+                    "GenericDmar": {
+                        "$ref": "./sections/cper-generic-dmar.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["VtdDmar"],
+                    "VtdDmar": {
+                        "$ref": "./sections/cper-vtd-dmar.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["IommuDmar"],
+                    "IommuDmar": {
+                        "$ref": "./sections/cper-iommu-dmar.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["CcixPer"],
+                    "CcixPer": {
+                        "$ref": "./sections/cper-ccix-per.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["CxlProtocol"],
+                    "CxlProtocol": {
+                        "$ref": "./sections/cper-cxl-protocol.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["CxlComponent"],
+                    "CxlComponent": {
+                        "$ref": "./sections/cper-cxl-component.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Nvidia"],
+                    "Nvidia": {
+                        "$ref": "./sections/cper-nvidia.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Ampere"],
+                    "Nvidia": {
+                        "$ref": "./sections/cper-ampere.json"
+                    }
+                },
+                {
+                    "type": "object",
+                    "required": ["Unknown"],
+                    "Unknown": {
+                        "$ref": "./sections/cper-unknown.json"
+                    }
+                }
             ]
         }
     }