TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishSmbiosHostInterface.c
Go to the documentation of this file.
1
14
15SMBIOS_TABLE_TYPE42 *mType42Record;
16
32 IN EFI_SMBIOS_PROTOCOL *Smbios,
33 OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
35 )
36{
37 EFI_STATUS Status;
38 EFI_SMBIOS_HANDLE SmbiosHandle;
40 UINT16 Offset;
41 UINT8 *RecordTmp;
42 UINT8 ProtocolLength;
43 UINT8 SpecificDataLen;
44
45 if ((Smbios == NULL) || (ProtocolData == NULL)) {
46 return EFI_INVALID_PARAMETER;
47 }
48
49 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
50 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
51 while (!EFI_ERROR (Status) && SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED) {
52 if (Record->Type == SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE) {
53 //
54 // Check Interface Type, should be Network Host Interface = 40h
55 //
56 mType42Record = (SMBIOS_TABLE_TYPE42 *)Record;
57 if (mType42Record->InterfaceType == MCHostInterfaceTypeNetworkHostInterface) {
58 ASSERT (Record->Length >= 9);
59 Offset = REDFISH_HI_ITERFACE_SPECIFIC_DATA_LENGTH_OFFSET;
60 RecordTmp = (UINT8 *)Record + Offset;
61 //
62 // Get interface specific data length.
63 //
64 SpecificDataLen = *RecordTmp;
65 Offset += 1;
66 RecordTmp = (UINT8 *)Record + Offset;
67
68 //
69 // Check Device Type, PCI/PCIe and USB Network Interface v2 is supported.
70 //
71 if ((*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) || (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2)) {
72 if (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
73 // According to Redfish Host Interface specification, add additional one byte for Device Type field.
74 if (SpecificDataLen != sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1) {
75 ASSERT (SpecificDataLen == sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
76 return EFI_VOLUME_CORRUPTED;
77 }
78 } else {
79 // According to Redfish Host Interface specification, add additional one byte for Device Type field.
80 if (SpecificDataLen != sizeof (USB_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1) {
81 ASSERT (SpecificDataLen == sizeof (USB_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
82 return EFI_VOLUME_CORRUPTED;
83 }
84 }
85
86 *DeviceDescriptor = (REDFISH_INTERFACE_DATA *)RecordTmp;
87 Offset = Offset + SpecificDataLen;
88 RecordTmp = (UINT8 *)Record + Offset;
89 //
90 // Check Protocol count. if > 1, only use the first protocol.
91 //
92 ASSERT (*RecordTmp == 1);
93 Offset += 1;
94 RecordTmp = (UINT8 *)Record + Offset;
95 //
96 // Check protocol identifier.
97 //
98 if (*RecordTmp == MCHostInterfaceProtocolTypeRedfishOverIP) {
99 Offset += 1;
100 RecordTmp = (UINT8 *)Record + Offset;
101 ProtocolLength = *RecordTmp;
102
103 Offset += 1;
104 RecordTmp = (UINT8 *)Record + Offset;
105
106 //
107 // This SMBIOS record is invalid, if the length of protocol specific data for
108 // Redfish Over IP protocol is wrong.
109 //
110 if ((*(RecordTmp + REDFISH_HI_PROTOCOL_HOSTNAME_LENGTH_OFFSET) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1) != ProtocolLength) {
111 DEBUG ((
112 DEBUG_ERROR,
113 "%a: Length of protocol specific data is not match: %d != ProtocolLength(%d).\n",
114 __func__,
115 *(RecordTmp + REDFISH_HI_PROTOCOL_HOSTNAME_LENGTH_OFFSET) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1,
116 ProtocolLength
117 ));
118 return EFI_SECURITY_VIOLATION;
119 }
120
121 Offset += ProtocolLength;
122 //
123 // This SMBIOS record is invalid, if the length is smaller than the offset.
124 //
125 if (Offset > mType42Record->Hdr.Length) {
126 DEBUG ((
127 DEBUG_ERROR,
128 "%a: Offset (%d) > mType42Record->Hdr.Length (%d).\n",
129 __func__,
130 Offset,
131 mType42Record->Hdr.Length
132 ));
133 return EFI_SECURITY_VIOLATION;
134 }
135
136 *ProtocolData = (REDFISH_OVER_IP_PROTOCOL_DATA *)RecordTmp;
137 return EFI_SUCCESS;
138 }
139 }
140 }
141 }
142
143 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
144 }
145
146 *ProtocolData = NULL;
147 return EFI_NOT_FOUND;
148}
#define SMBIOS_HANDLE_PI_RESERVED
Definition: SmBios.h:29
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS RedfishGetHostInterfaceProtocolData(IN EFI_SMBIOS_PROTOCOL *Smbios, OUT REDFISH_INTERFACE_DATA **DeviceDescriptor, OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Device descriptor data formated based on Device Type.
UINT8 InterfaceType
The enumeration value from MC_HOST_INTERFACE_TYPE.
Definition: SmBios.h:2753