RedfishSmbiosHostInterface.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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, PCI/PCIe and USB Network Interface v2 is supported.
  55. //
  56. if ((*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) || (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2)) {
  57. if (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
  58. ASSERT (SpecificDataLen == sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
  59. } else {
  60. ASSERT (SpecificDataLen > sizeof (REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) + 1);
  61. }
  62. *DeviceDescriptor = (REDFISH_INTERFACE_DATA *)RecordTmp;
  63. Offset = Offset + SpecificDataLen;
  64. RecordTmp = (UINT8 *)Record + Offset;
  65. //
  66. // Check Protocol count. if > 1, only use the first protocol.
  67. //
  68. ASSERT (*RecordTmp == 1);
  69. Offset += 1;
  70. RecordTmp = (UINT8 *)Record + Offset;
  71. //
  72. // Check protocol identifier.
  73. //
  74. if (*RecordTmp == MCHostInterfaceProtocolTypeRedfishOverIP) {
  75. Offset += 1;
  76. RecordTmp = (UINT8 *)Record + Offset;
  77. ProtocolLength = *RecordTmp;
  78. Offset += 1;
  79. RecordTmp = (UINT8 *)Record + Offset;
  80. //
  81. // This SMBIOS record is invalid, if the length of protocol specific data for
  82. // Redfish Over IP protocol is wrong.
  83. //
  84. if ((*(RecordTmp + 90) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1) != ProtocolLength) {
  85. return EFI_SECURITY_VIOLATION;
  86. }
  87. Offset += ProtocolLength;
  88. //
  89. // This SMBIOS record is invalid, if the length is smaller than the offset.
  90. //
  91. if (Offset > mType42Record->Hdr.Length) {
  92. return EFI_SECURITY_VIOLATION;
  93. }
  94. *ProtocolData = (REDFISH_OVER_IP_PROTOCOL_DATA *)RecordTmp;
  95. return EFI_SUCCESS;
  96. }
  97. }
  98. }
  99. }
  100. Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
  101. }
  102. *ProtocolData = NULL;
  103. return EFI_NOT_FOUND;
  104. }