3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 MiscBaseBoardManufacturerFunction.c
21 BaseBoard manufacturer information boot time changes.
27 #include "CommonHeader.h"
28 #include "MiscSubclassDriver.h"
29 #include <Library/NetLib.h>
30 #include "Library/DebugLib.h"
31 #include <Uefi/UefiBaseType.h>
35 This function makes boot time changes to the contents of the
36 MiscBaseBoardManufacturer (Type 2).
38 @param RecordData Pointer to copy of RecordData from the Data Table.
40 @retval EFI_SUCCESS All parameters were valid.
41 @retval EFI_UNSUPPORTED Unexpected RecordType value.
42 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
45 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer
)
47 CHAR8
*OptionalStrStart
;
51 UINTN AssertTagStrLen
;
52 UINTN SerialNumStrLen
;
55 EFI_STRING Manufacturer
;
58 EFI_STRING SerialNumber
;
61 STRING_REF TokenToGet
;
62 EFI_SMBIOS_HANDLE SmbiosHandle
;
63 SMBIOS_TABLE_TYPE2
*SmbiosRecord
;
64 EFI_MISC_BASE_BOARD_MANUFACTURER
*ForType2InputData
;
70 ForType2InputData
= (EFI_MISC_BASE_BOARD_MANUFACTURER
*)RecordData
;
73 // First check for invalid parameters.
75 if (RecordData
== NULL
) {
76 return EFI_INVALID_PARAMETER
;
79 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER
);
80 Manufacturer
= SmbiosMiscGetString (TokenToGet
);
81 ManuStrLen
= StrLen(Manufacturer
);
82 if (ManuStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
83 return EFI_UNSUPPORTED
;
86 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME1
);
87 Product
= SmbiosMiscGetString (TokenToGet
);
88 ProductStrLen
= StrLen(Product
);
89 if (ProductStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
90 return EFI_UNSUPPORTED
;
92 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION
);
93 Version
= SmbiosMiscGetString (TokenToGet
);
94 VerStrLen
= StrLen(Version
);
95 if (VerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
96 return EFI_UNSUPPORTED
;
100 //Get handle infomation
104 Status
= gBS
->LocateHandle (
106 &gEfiSimpleNetworkProtocolGuid
,
112 if (Status
== EFI_BUFFER_TOO_SMALL
) {
113 Handles
= AllocateZeroPool(BufferSize
);
114 if (Handles
== NULL
) {
115 return (EFI_OUT_OF_RESOURCES
);
117 Status
= gBS
->LocateHandle(
119 &gEfiSimpleNetworkProtocolGuid
,
129 Status
= NetLibGetMacString (
134 if (EFI_ERROR (Status
)) {
137 SerialNumber
= MacStr
;
138 SerialNumStrLen
= StrLen(SerialNumber
);
139 if (SerialNumStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
140 return EFI_UNSUPPORTED
;
142 DEBUG ((EFI_D_ERROR
, "MAC Address: %S\n", MacStr
));
144 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG
);
145 AssertTag
= SmbiosMiscGetString (TokenToGet
);
146 AssertTagStrLen
= StrLen(AssertTag
);
147 if (AssertTagStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
148 return EFI_UNSUPPORTED
;
151 TokenToGet
= STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION
);
152 Chassis
= SmbiosMiscGetString (TokenToGet
);
153 ChassisStrLen
= StrLen(Chassis
);
154 if (ChassisStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
155 return EFI_UNSUPPORTED
;
160 // Two zeros following the last string.
162 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE2
) + ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1 + ChassisStrLen
+1 + 1);
163 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE2
) + ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1 + ChassisStrLen
+1 + 1);
165 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION
;
166 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE2
);
169 // Make handle chosen by smbios protocol.add automatically.
171 SmbiosRecord
->Hdr
.Handle
= 0;
174 // Manu will be the 1st optional string following the formatted structure.
176 SmbiosRecord
->Manufacturer
= 1;
179 // ProductName will be the 2st optional string following the formatted structure.
181 SmbiosRecord
->ProductName
= 2;
184 // Version will be the 3rd optional string following the formatted structure.
186 SmbiosRecord
->Version
= 3;
189 // SerialNumber will be the 4th optional string following the formatted structure.
191 SmbiosRecord
->SerialNumber
= 4;
194 // AssertTag will be the 5th optional string following the formatted structure.
196 SmbiosRecord
->AssetTag
= 5;
199 // LocationInChassis will be the 6th optional string following the formatted structure.
201 SmbiosRecord
->LocationInChassis
= 6;
202 SmbiosRecord
->FeatureFlag
= (*(BASE_BOARD_FEATURE_FLAGS
*)&(ForType2InputData
->BaseBoardFeatureFlags
));
203 SmbiosRecord
->ChassisHandle
= 0;
204 SmbiosRecord
->BoardType
= (UINT8
)ForType2InputData
->BaseBoardType
;
205 SmbiosRecord
->NumberOfContainedObjectHandles
= 0;
207 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
210 // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
212 UnicodeStrToAsciiStr(Manufacturer
, OptionalStrStart
);
213 UnicodeStrToAsciiStr(Product
, OptionalStrStart
+ ManuStrLen
+ 1);
214 UnicodeStrToAsciiStr(Version
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1);
215 UnicodeStrToAsciiStr(SerialNumber
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1);
216 UnicodeStrToAsciiStr(AssertTag
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1);
217 UnicodeStrToAsciiStr(Chassis
, OptionalStrStart
+ ManuStrLen
+ 1 + ProductStrLen
+ 1 + VerStrLen
+ 1 + SerialNumStrLen
+ 1 + AssertTagStrLen
+ 1);
220 // Now we have got the full smbios record, call smbios protocol to add this record.
222 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
223 Status
= Smbios
-> Add(
227 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
230 FreePool(SmbiosRecord
);