]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c
65f72fe0ad28955578a66fbd799b41f666917dc6
[mirror_edk2.git] / Nt32Pkg / MiscSubClassPlatformDxe / MiscChassisManufacturerFunction.c
1 /*++
2
3 Copyright (c) 2009, Intel Corporation. All rights reserved. <BR>
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
11
12
13 Module Name:
14
15 MiscChassisManufacturerFunction.c
16
17 Abstract:
18
19 Chassis manufacturer information boot time changes.
20 SMBIOS type 3.
21
22 --*/
23
24 #include "MiscSubclassDriver.h"
25
26 /**
27 This function makes boot time changes to the contents of the
28 MiscChassisManufacturer (Type 3).
29
30 @param RecordData Pointer to copy of RecordData from the Data Table.
31
32 @retval EFI_SUCCESS All parameters were valid.
33 @retval EFI_UNSUPPORTED Unexpected RecordType value.
34 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
35
36 **/
37 MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
38 {
39 CHAR8 *OptionalStrStart;
40 UINTN ManuStrLen;
41 UINTN VerStrLen;
42 UINTN AssertTagStrLen;
43 UINTN SerialNumStrLen;
44 EFI_STATUS Status;
45 EFI_STRING Manufacturer;
46 EFI_STRING Version;
47 EFI_STRING SerialNumber;
48 EFI_STRING AssertTag;
49 STRING_REF TokenToGet;
50 EFI_SMBIOS_HANDLE SmbiosHandle;
51 SMBIOS_TABLE_TYPE3 *SmbiosRecord;
52 EFI_MISC_CHASSIS_MANUFACTURER *ForType3InputData;
53
54 ForType3InputData = (EFI_MISC_CHASSIS_MANUFACTURER *)RecordData;
55
56 //
57 // First check for invalid parameters.
58 //
59 if (RecordData == NULL) {
60 return EFI_INVALID_PARAMETER;
61 }
62
63 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER);
64 Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
65 ManuStrLen = StrLen(Manufacturer);
66 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
67 return EFI_UNSUPPORTED;
68 }
69
70 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_VERSION);
71 Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
72 VerStrLen = StrLen(Version);
73 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
74 return EFI_UNSUPPORTED;
75 }
76
77 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER);
78 SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
79 SerialNumStrLen = StrLen(SerialNumber);
80 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
81 return EFI_UNSUPPORTED;
82 }
83
84 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);
85 AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
86 AssertTagStrLen = StrLen(AssertTag);
87 if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
88 return EFI_UNSUPPORTED;
89 }
90
91 //
92 // Two zeros following the last string.
93 //
94 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
95 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
96
97 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE;
98 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3);
99 //
100 // Make handle chosen by smbios protocol.add automatically.
101 //
102 SmbiosRecord->Hdr.Handle = 0;
103 //
104 // Manu will be the 1st optional string following the formatted structure.
105 //
106 SmbiosRecord->Manufacturer = 1;
107 SmbiosRecord->Type = (UINT8)ForType3InputData->ChassisType.ChassisType;
108 //
109 // Version will be the 2nd optional string following the formatted structure.
110 //
111 SmbiosRecord->Version = 2;
112 //
113 // SerialNumber will be the 3rd optional string following the formatted structure.
114 //
115 SmbiosRecord->SerialNumber = 3;
116 //
117 // AssertTag will be the 4th optional string following the formatted structure.
118 //
119 SmbiosRecord->AssetTag = 4;
120 SmbiosRecord->BootupState = (UINT8)ForType3InputData->ChassisBootupState;
121 SmbiosRecord->PowerSupplyState = (UINT8)ForType3InputData->ChassisPowerSupplyState;
122 SmbiosRecord->ThermalState = (UINT8)ForType3InputData->ChassisThermalState;
123 SmbiosRecord->SecurityStatus = (UINT8)ForType3InputData->ChassisSecurityState;
124 CopyMem (SmbiosRecord->OemDefined,(UINT8*)&ForType3InputData->ChassisOemDefined, 4);
125
126 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
127 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
128 UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1);
129 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);
130 UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
131
132 //
133 // Now we have got the full smbios record, call smbios protocol to add this record.
134 //
135 SmbiosHandle = 0;
136 Status = Smbios-> Add(
137 Smbios,
138 NULL,
139 &SmbiosHandle,
140 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
141 );
142
143 FreePool(SmbiosRecord);
144 return Status;
145 }