]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBaseBoardManufacturerFunction.c
Hash2 driver to [Components.IA32, Components.X64, Components.IPF] section.
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmBiosMiscDxe / MiscBaseBoardManufacturerFunction.c
CommitLineData
3cbfba02
DW
1/*++
2
3Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
4
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.
9
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.
12
13
14
15Module Name:
16
17 MiscBaseBoardManufacturerFunction.c
18
19Abstract:
20
21 BaseBoard manufacturer information boot time changes.
22 SMBIOS type 2.
23
24--*/
25
26
27#include "CommonHeader.h"
28#include "MiscSubclassDriver.h"
29#include <Library/NetLib.h>
30#include "Library/DebugLib.h"
31#include <Uefi/UefiBaseType.h>
32
33
34/**
35 This function makes boot time changes to the contents of the
36 MiscBaseBoardManufacturer (Type 2).
37
38 @param RecordData Pointer to copy of RecordData from the Data Table.
39
40 @retval EFI_SUCCESS All parameters were valid.
41 @retval EFI_UNSUPPORTED Unexpected RecordType value.
42 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
43
44**/
45MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
46{
47 CHAR8 *OptionalStrStart;
48 UINTN ManuStrLen;
49 UINTN ProductStrLen;
50 UINTN VerStrLen;
51 UINTN AssertTagStrLen;
52 UINTN SerialNumStrLen;
53 UINTN ChassisStrLen;
54 EFI_STATUS Status;
55 EFI_STRING Manufacturer;
56 EFI_STRING Product;
57 EFI_STRING Version;
58 EFI_STRING SerialNumber;
59 EFI_STRING AssertTag;
60 EFI_STRING Chassis;
61 STRING_REF TokenToGet;
62 EFI_SMBIOS_HANDLE SmbiosHandle;
63 SMBIOS_TABLE_TYPE2 *SmbiosRecord;
64 EFI_MISC_BASE_BOARD_MANUFACTURER *ForType2InputData;
65
66 CHAR16 *MacStr;
67 EFI_HANDLE *Handles;
68 UINTN BufferSize;
69
70 ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;
71
72 //
73 // First check for invalid parameters.
74 //
75 if (RecordData == NULL) {
76 return EFI_INVALID_PARAMETER;
77 }
78
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;
84 }
85
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;
91 }
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;
97 }
98
99 //
100 //Get handle infomation
101 //
102 BufferSize = 0;
103 Handles = NULL;
104 Status = gBS->LocateHandle (
105 ByProtocol,
106 &gEfiSimpleNetworkProtocolGuid,
107 NULL,
108 &BufferSize,
109 Handles
110 );
111
112 if (Status == EFI_BUFFER_TOO_SMALL) {
113 Handles = AllocateZeroPool(BufferSize);
114 if (Handles == NULL) {
115 return (EFI_OUT_OF_RESOURCES);
116 }
117 Status = gBS->LocateHandle(
118 ByProtocol,
119 &gEfiSimpleNetworkProtocolGuid,
120 NULL,
121 &BufferSize,
122 Handles
123 );
124 }
125
126 //
127 //Get the MAC string
128 //
129 Status = NetLibGetMacString (
130 *Handles,
131 NULL,
132 &MacStr
133 );
134 if (EFI_ERROR (Status)) {
135 return Status;
136 }
137 SerialNumber = MacStr;
138 SerialNumStrLen = StrLen(SerialNumber);
139 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
140 return EFI_UNSUPPORTED;
141 }
142 DEBUG ((EFI_D_ERROR, "MAC Address: %S\n", MacStr));
143
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;
149 }
150
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;
156 }
157
158
159 //
160 // Two zeros following the last string.
161 //
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);
164
165 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
166 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);
167
168 //
169 // Make handle chosen by smbios protocol.add automatically.
170 //
171 SmbiosRecord->Hdr.Handle = 0;
172
173 //
174 // Manu will be the 1st optional string following the formatted structure.
175 //
176 SmbiosRecord->Manufacturer = 1;
177
178 //
179 // ProductName will be the 2st optional string following the formatted structure.
180 //
181 SmbiosRecord->ProductName = 2;
182
183 //
184 // Version will be the 3rd optional string following the formatted structure.
185 //
186 SmbiosRecord->Version = 3;
187
188 //
189 // SerialNumber will be the 4th optional string following the formatted structure.
190 //
191 SmbiosRecord->SerialNumber = 4;
192
193 //
194 // AssertTag will be the 5th optional string following the formatted structure.
195 //
196 SmbiosRecord->AssetTag = 5;
197
198 //
199 // LocationInChassis will be the 6th optional string following the formatted structure.
200 //
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;
206
207 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
208
209 //
210 // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
211 //
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);
218
219 //
220 // Now we have got the full smbios record, call smbios protocol to add this record.
221 //
222 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
223 Status = Smbios-> Add(
224 Smbios,
225 NULL,
226 &SmbiosHandle,
227 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
228 );
229
230 FreePool(SmbiosRecord);
231 return Status;
232}