]> git.proxmox.com Git - mirror_edk2.git/blob - RedfishPkg/RedfishDiscoverDxe/RedfishSmbiosHostInterface.c
MdePkg/Register: Add register definition header files for RISC-V
[mirror_edk2.git] / RedfishPkg / RedfishDiscoverDxe / RedfishSmbiosHostInterface.c
1 /** @file
2 RedfishSmbiosHostInterface.c
3
4 Discover Redfish SMBIOS Host Interface.
5
6 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include "RedfishDiscoverInternal.h"
13
14 SMBIOS_TABLE_TYPE42 *mType42Record;
15
16 /**
17 The function gets information reported in Redfish Host Interface.
18
19 It simply frees the packet.
20
21 @param[in] Smbios SMBIOS protocol.
22 @param[out] DeviceDescriptor Pointer to REDFISH_INTERFACE_DATA.
23 @param[out] ProtocolData Pointer to REDFISH_OVER_IP_PROTOCOL_DATA.
24
25 @retval EFI_SUCCESS Get host interface succesfully.
26 @retval Otherwise Fail to tet host interface.
27
28 **/
29 EFI_STATUS
30 RedfishGetHostInterfaceProtocolData (
31 IN EFI_SMBIOS_PROTOCOL *Smbios,
32 OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
33 OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData
34 )
35 {
36 EFI_STATUS Status;
37 EFI_SMBIOS_HANDLE SmbiosHandle;
38 EFI_SMBIOS_TABLE_HEADER *Record;
39 UINT16 Offset;
40 UINT8 *RecordTmp;
41 UINT8 ProtocolLength;
42 UINT8 SpecificDataLen;
43
44 if ((Smbios == NULL) || (ProtocolData == NULL)) {
45 return EFI_INVALID_PARAMETER;
46 }
47
48 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
49 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
50 while (!EFI_ERROR (Status) && SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED) {
51 if (Record->Type == SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE) {
52 //
53 // Check Interface Type, should be Network Host Interface = 40h
54 //
55 mType42Record = (SMBIOS_TABLE_TYPE42 *)Record;
56 if (mType42Record->InterfaceType == MCHostInterfaceTypeNetworkHostInterface) {
57 ASSERT (Record->Length >= 9);
58 Offset = 5;
59 RecordTmp = (UINT8 *)Record + Offset;
60 //
61 // Get interface specific data length.
62 //
63 SpecificDataLen = *RecordTmp;
64 Offset += 1;
65 RecordTmp = (UINT8 *)Record + Offset;
66
67 //
68 // Check Device Type, PCI/PCIe and USB Network Interface v2 is supported.
69 //
70 if ((*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) || (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2)) {
71 if (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
72 ASSERT (SpecificDataLen == sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
73 } else {
74 ASSERT (SpecificDataLen > sizeof (REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) + 1);
75 }
76
77 *DeviceDescriptor = (REDFISH_INTERFACE_DATA *)RecordTmp;
78 Offset = Offset + SpecificDataLen;
79 RecordTmp = (UINT8 *)Record + Offset;
80 //
81 // Check Protocol count. if > 1, only use the first protocol.
82 //
83 ASSERT (*RecordTmp == 1);
84 Offset += 1;
85 RecordTmp = (UINT8 *)Record + Offset;
86 //
87 // Check protocol identifier.
88 //
89 if (*RecordTmp == MCHostInterfaceProtocolTypeRedfishOverIP) {
90 Offset += 1;
91 RecordTmp = (UINT8 *)Record + Offset;
92 ProtocolLength = *RecordTmp;
93
94 Offset += 1;
95 RecordTmp = (UINT8 *)Record + Offset;
96
97 //
98 // This SMBIOS record is invalid, if the length of protocol specific data for
99 // Redfish Over IP protocol is wrong.
100 //
101 if ((*(RecordTmp + 90) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1) != ProtocolLength) {
102 return EFI_SECURITY_VIOLATION;
103 }
104
105 Offset += ProtocolLength;
106 //
107 // This SMBIOS record is invalid, if the length is smaller than the offset.
108 //
109 if (Offset > mType42Record->Hdr.Length) {
110 return EFI_SECURITY_VIOLATION;
111 }
112
113 *ProtocolData = (REDFISH_OVER_IP_PROTOCOL_DATA *)RecordTmp;
114 return EFI_SUCCESS;
115 }
116 }
117 }
118 }
119
120 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
121 }
122
123 *ProtocolData = NULL;
124 return EFI_NOT_FOUND;
125 }