MiscBaseBoardManufacturerFunction.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*++
  2. Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. MiscBaseBoardManufacturerFunction.c
  6. Abstract:
  7. BaseBoard manufacturer information boot time changes.
  8. SMBIOS type 2.
  9. --*/
  10. #include "CommonHeader.h"
  11. #include "MiscSubclassDriver.h"
  12. #include <Library/NetLib.h>
  13. #include "Library/DebugLib.h"
  14. #include <Uefi/UefiBaseType.h>
  15. #include <Guid/PlatformInfo.h>
  16. extern EFI_PLATFORM_INFO_HOB *mPlatformInfo;
  17. /**
  18. This function makes boot time changes to the contents of the
  19. MiscBaseBoardManufacturer (Type 2).
  20. @param RecordData Pointer to copy of RecordData from the Data Table.
  21. @retval EFI_SUCCESS All parameters were valid.
  22. @retval EFI_UNSUPPORTED Unexpected RecordType value.
  23. @retval EFI_INVALID_PARAMETER Invalid parameter was found.
  24. **/
  25. MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
  26. {
  27. CHAR8 *OptionalStrStart;
  28. UINTN OptionalStrSize;
  29. UINTN ManuStrLen;
  30. UINTN ProductStrLen;
  31. UINTN VerStrLen;
  32. UINTN AssertTagStrLen;
  33. UINTN SerialNumStrLen;
  34. UINTN ChassisStrLen;
  35. EFI_STATUS Status;
  36. EFI_STRING Manufacturer;
  37. EFI_STRING Product;
  38. EFI_STRING Version;
  39. EFI_STRING SerialNumber;
  40. EFI_STRING AssertTag;
  41. EFI_STRING Chassis;
  42. STRING_REF TokenToGet;
  43. EFI_SMBIOS_HANDLE SmbiosHandle;
  44. SMBIOS_TABLE_TYPE2 *SmbiosRecord;
  45. EFI_MISC_BASE_BOARD_MANUFACTURER *ForType2InputData;
  46. CHAR16 *MacStr;
  47. EFI_HANDLE *Handles;
  48. UINTN BufferSize;
  49. CHAR16 Buffer[40];
  50. ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;
  51. //
  52. // First check for invalid parameters.
  53. //
  54. if (RecordData == NULL || mPlatformInfo == NULL) {
  55. return EFI_INVALID_PARAMETER;
  56. }
  57. if (BOARD_ID_MINNOW2_TURBOT == mPlatformInfo->BoardId) {
  58. UnicodeSPrint (Buffer, sizeof (Buffer),L"ADI");
  59. HiiSetString(mHiiHandle,STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER), Buffer, NULL);
  60. }
  61. TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
  62. Manufacturer = SmbiosMiscGetString (TokenToGet);
  63. ManuStrLen = StrLen(Manufacturer);
  64. if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
  65. return EFI_UNSUPPORTED;
  66. }
  67. if (BOARD_ID_MINNOW2_TURBOT == mPlatformInfo->BoardId) {
  68. UnicodeSPrint (Buffer, sizeof (Buffer),L"MinnowBoard Turbot");
  69. HiiSetString(mHiiHandle,STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME1), Buffer, NULL);
  70. }
  71. TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME1);
  72. Product = SmbiosMiscGetString (TokenToGet);
  73. ProductStrLen = StrLen(Product);
  74. if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {
  75. return EFI_UNSUPPORTED;
  76. }
  77. TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
  78. Version = SmbiosMiscGetString (TokenToGet);
  79. VerStrLen = StrLen(Version);
  80. if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
  81. return EFI_UNSUPPORTED;
  82. }
  83. //
  84. //Get handle infomation
  85. //
  86. BufferSize = 0;
  87. Handles = NULL;
  88. Status = gBS->LocateHandle (
  89. ByProtocol,
  90. &gEfiSimpleNetworkProtocolGuid,
  91. NULL,
  92. &BufferSize,
  93. Handles
  94. );
  95. if (Status == EFI_BUFFER_TOO_SMALL) {
  96. Handles = AllocateZeroPool(BufferSize);
  97. if (Handles == NULL) {
  98. return (EFI_OUT_OF_RESOURCES);
  99. }
  100. Status = gBS->LocateHandle(
  101. ByProtocol,
  102. &gEfiSimpleNetworkProtocolGuid,
  103. NULL,
  104. &BufferSize,
  105. Handles
  106. );
  107. }
  108. //
  109. //Get the MAC string
  110. //
  111. if (Handles == NULL) {
  112. Status = EFI_NOT_FOUND;
  113. } else {
  114. Status = NetLibGetMacString (
  115. *Handles,
  116. NULL,
  117. &MacStr
  118. );
  119. }
  120. if (EFI_ERROR (Status)) {
  121. MacStr = L"000000000000";
  122. }
  123. SerialNumber = MacStr;
  124. SerialNumStrLen = StrLen(SerialNumber);
  125. if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
  126. return EFI_UNSUPPORTED;
  127. }
  128. DEBUG ((EFI_D_ERROR, "MAC Address: %S\n", MacStr));
  129. TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);
  130. AssertTag = SmbiosMiscGetString (TokenToGet);
  131. AssertTagStrLen = StrLen(AssertTag);
  132. if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
  133. return EFI_UNSUPPORTED;
  134. }
  135. TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);
  136. Chassis = SmbiosMiscGetString (TokenToGet);
  137. ChassisStrLen = StrLen(Chassis);
  138. if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {
  139. return EFI_UNSUPPORTED;
  140. }
  141. //
  142. // Two zeros following the last string.
  143. //
  144. OptionalStrSize = ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1;
  145. SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) + OptionalStrSize);
  146. ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) + OptionalStrSize);
  147. SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
  148. SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);
  149. //
  150. // Make handle chosen by smbios protocol.add automatically.
  151. //
  152. SmbiosRecord->Hdr.Handle = 0;
  153. //
  154. // Manu will be the 1st optional string following the formatted structure.
  155. //
  156. SmbiosRecord->Manufacturer = 1;
  157. //
  158. // ProductName will be the 2st optional string following the formatted structure.
  159. //
  160. SmbiosRecord->ProductName = 2;
  161. //
  162. // Version will be the 3rd optional string following the formatted structure.
  163. //
  164. SmbiosRecord->Version = 3;
  165. //
  166. // SerialNumber will be the 4th optional string following the formatted structure.
  167. //
  168. SmbiosRecord->SerialNumber = 4;
  169. //
  170. // AssertTag will be the 5th optional string following the formatted structure.
  171. //
  172. SmbiosRecord->AssetTag = 5;
  173. //
  174. // LocationInChassis will be the 6th optional string following the formatted structure.
  175. //
  176. SmbiosRecord->LocationInChassis = 6;
  177. SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));
  178. SmbiosRecord->ChassisHandle = 0;
  179. SmbiosRecord->BoardType = (UINT8)ForType2InputData->BaseBoardType;
  180. SmbiosRecord->NumberOfContainedObjectHandles = 0;
  181. OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
  182. //
  183. // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
  184. //
  185. UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, OptionalStrSize);
  186. OptionalStrStart += (ManuStrLen + 1);
  187. OptionalStrSize -= (ManuStrLen + 1);
  188. UnicodeStrToAsciiStrS (Product, OptionalStrStart, OptionalStrSize);
  189. OptionalStrStart += (ProductStrLen + 1);
  190. OptionalStrSize -= (ProductStrLen + 1);
  191. UnicodeStrToAsciiStrS (Version, OptionalStrStart, OptionalStrSize);
  192. OptionalStrStart += (VerStrLen + 1);
  193. OptionalStrSize -= (VerStrLen + 1);
  194. UnicodeStrToAsciiStrS (SerialNumber, OptionalStrStart, OptionalStrSize);
  195. OptionalStrStart += (SerialNumStrLen + 1);
  196. OptionalStrSize -= (SerialNumStrLen + 1);
  197. UnicodeStrToAsciiStrS (AssertTag, OptionalStrStart, OptionalStrSize);
  198. OptionalStrStart += (AssertTagStrLen + 1);
  199. OptionalStrSize -= (AssertTagStrLen + 1);
  200. UnicodeStrToAsciiStrS (Chassis, OptionalStrStart, OptionalStrSize);
  201. //
  202. // Now we have got the full smbios record, call smbios protocol to add this record.
  203. //
  204. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  205. Status = Smbios-> Add(
  206. Smbios,
  207. NULL,
  208. &SmbiosHandle,
  209. (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
  210. );
  211. FreePool(SmbiosRecord);
  212. return Status;
  213. }