1 | /** @file
|
---|
2 | RedfishSmbiosHostInterface.c
|
---|
3 |
|
---|
4 | Discover Redfish SMBIOS Host Interface.
|
---|
5 |
|
---|
6 | (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
|
---|
7 | Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
---|
8 |
|
---|
9 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
10 |
|
---|
11 | **/
|
---|
12 |
|
---|
13 | #include "RedfishDiscoverInternal.h"
|
---|
14 |
|
---|
15 | SMBIOS_TABLE_TYPE42 *mType42Record;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | The function gets information reported in Redfish Host Interface.
|
---|
19 |
|
---|
20 | It simply frees the packet.
|
---|
21 |
|
---|
22 | @param[in] Smbios SMBIOS protocol.
|
---|
23 | @param[out] DeviceDescriptor Pointer to REDFISH_INTERFACE_DATA.
|
---|
24 | @param[out] ProtocolData Pointer to REDFISH_OVER_IP_PROTOCOL_DATA.
|
---|
25 |
|
---|
26 | @retval EFI_SUCCESS Get host interface successfully.
|
---|
27 | @retval Otherwise Fail to tet host interface.
|
---|
28 |
|
---|
29 | **/
|
---|
30 | EFI_STATUS
|
---|
31 | RedfishGetHostInterfaceProtocolData (
|
---|
32 | IN EFI_SMBIOS_PROTOCOL *Smbios,
|
---|
33 | OUT REDFISH_INTERFACE_DATA **DeviceDescriptor,
|
---|
34 | OUT REDFISH_OVER_IP_PROTOCOL_DATA **ProtocolData
|
---|
35 | )
|
---|
36 | {
|
---|
37 | EFI_STATUS Status;
|
---|
38 | EFI_SMBIOS_HANDLE SmbiosHandle;
|
---|
39 | EFI_SMBIOS_TABLE_HEADER *Record;
|
---|
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 | }
|
---|