1 /** @file
2 Chassis manufacturer information boot time changes.
3 SMBIOS type 3.
4
5 Copyright (c) 2013-2015 Intel Corporation.
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15
16 **/
17
18
19 #include "CommonHeader.h"
20
21 #include "SmbiosMisc.h"
22
23 /**
24 This function makes boot time changes to the contents of the
25 MiscChassisManufacturer (Type 3).
26
27 @param RecordData Pointer to copy of RecordData from the Data Table.
28
29 @retval EFI_SUCCESS All parameters were valid.
30 @retval EFI_UNSUPPORTED Unexpected RecordType value.
31 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
32
33 **/
MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)34 MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
35 {
36 CHAR8 *OptionalStrStart;
37 UINTN ManuStrLen;
38 UINTN VerStrLen;
39 UINTN AssertTagStrLen;
40 UINTN SerialNumStrLen;
41 EFI_STATUS Status;
42 CHAR16 Manufacturer[SMBIOS_STRING_MAX_LENGTH];
43 CHAR16 Version[SMBIOS_STRING_MAX_LENGTH];
44 CHAR16 SerialNumber[SMBIOS_STRING_MAX_LENGTH];
45 CHAR16 AssertTag[SMBIOS_STRING_MAX_LENGTH];
46 EFI_STRING ManufacturerPtr;
47 EFI_STRING VersionPtr;
48 EFI_STRING SerialNumberPtr;
49 EFI_STRING AssertTagPtr;
50 STRING_REF TokenToGet;
51 STRING_REF TokenToUpdate;
52 EFI_SMBIOS_HANDLE SmbiosHandle;
53 SMBIOS_TABLE_TYPE3 *SmbiosRecord;
54 EFI_MISC_CHASSIS_MANUFACTURER *ForType3InputData;
55
56 ForType3InputData = (EFI_MISC_CHASSIS_MANUFACTURER *)RecordData;
57
58 //
59 // First check for invalid parameters.
60 //
61 if (RecordData == NULL) {
62 return EFI_INVALID_PARAMETER;
63 }
64
65 //
66 // Update strings from PCD
67 //
68 AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSChassisManufacturer), Manufacturer);
69 if (StrLen (Manufacturer) > 0) {
70 TokenToUpdate = STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER);
71 HiiSetString (mHiiHandle, TokenToUpdate, Manufacturer, NULL);
72 }
73 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER);
74 ManufacturerPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
75 ManuStrLen = StrLen(ManufacturerPtr);
76 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
77 return EFI_UNSUPPORTED;
78 }
79
80 AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSChassisVersion), Version);
81 if (StrLen (Version) > 0) {
82 TokenToUpdate = STRING_TOKEN (STR_MISC_CHASSIS_VERSION);
83 HiiSetString (mHiiHandle, TokenToUpdate, Version, NULL);
84 }
85 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_VERSION);
86 VersionPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
87 VerStrLen = StrLen(VersionPtr);
88 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
89 return EFI_UNSUPPORTED;
90 }
91
92 AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSChassisSerialNumber), SerialNumber);
93 if (StrLen (SerialNumber) > 0) {
94 TokenToUpdate = STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER);
95 HiiSetString (mHiiHandle, TokenToUpdate, SerialNumber, NULL);
96 }
97 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER);
98 SerialNumberPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
99 SerialNumStrLen = StrLen(SerialNumberPtr);
100 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
101 return EFI_UNSUPPORTED;
102 }
103
104 AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSChassisAssetTag), AssertTag);
105 if (StrLen (AssertTag) > 0) {
106 TokenToUpdate = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);
107 HiiSetString (mHiiHandle, TokenToUpdate, AssertTag, NULL);
108 }
109 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);
110 AssertTagPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
111 AssertTagStrLen = StrLen(AssertTagPtr);
112 if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
113 return EFI_UNSUPPORTED;
114 }
115
116 //
117 // Two zeros following the last string.
118 //
119 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
120 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
121
122 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE;
123 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3);
124 //
125 // Make handle chosen by smbios protocol.add automatically.
126 //
127 SmbiosRecord->Hdr.Handle = 0;
128 //
129 // Manu will be the 1st optional string following the formatted structure.
130 //
131 SmbiosRecord->Manufacturer = 1;
132 SmbiosRecord->Type = PcdGet8 (PcdSMBIOSChassisType);
133 //
134 // Version will be the 2nd optional string following the formatted structure.
135 //
136 SmbiosRecord->Version = 2;
137 //
138 // SerialNumber will be the 3rd optional string following the formatted structure.
139 //
140 SmbiosRecord->SerialNumber = 3;
141 //
142 // AssertTag will be the 4th optional string following the formatted structure.
143 //
144 SmbiosRecord->AssetTag = 4;
145 SmbiosRecord->BootupState = PcdGet8 (PcdSMBIOSChassisBootupState);
146 SmbiosRecord->PowerSupplyState = PcdGet8 (PcdSMBIOSChassisPowerSupplyState);
147 SmbiosRecord->ThermalState = (UINT8)ForType3InputData->ChassisThermalState;
148 SmbiosRecord->SecurityStatus = PcdGet8 (PcdSMBIOSChassisSecurityState);
149 *(UINT32 *)&SmbiosRecord->OemDefined = PcdGet32 (PcdSMBIOSChassisOemDefined);
150 SmbiosRecord->Height = PcdGet8 (PcdSMBIOSChassisHeight);
151 SmbiosRecord->NumberofPowerCords = PcdGet8 (PcdSMBIOSChassisNumberPowerCords);
152 SmbiosRecord->ContainedElementCount = PcdGet8 (PcdSMBIOSChassisElementCount);
153 SmbiosRecord->ContainedElementRecordLength = PcdGet8 (PcdSMBIOSChassisElementRecordLength);
154
155 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
156 UnicodeStrToAsciiStr(ManufacturerPtr, OptionalStrStart);
157 UnicodeStrToAsciiStr(VersionPtr, OptionalStrStart + ManuStrLen + 1);
158 UnicodeStrToAsciiStr(SerialNumberPtr, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);
159 UnicodeStrToAsciiStr(AssertTagPtr, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
160
161 //
162 // Now we have got the full smbios record, call smbios protocol to add this record.
163 //
164 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
165 Status = Smbios-> Add(
166 Smbios,
167 NULL,
168 &SmbiosHandle,
169 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
170 );
171
172 FreePool(SmbiosRecord);
173 return Status;
174 }
175