RedfishSmbiosHostInterface.c 4.0 KB

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