1/**@file
2
3Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution.  The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14  MiscSystemManufacturerFunction.c
15
16Abstract:
17
18  This driver parses the mMiscSubclassDataTable structure and reports
19  any generated data to the DataHub.
20
21**/
22
23#include "MiscSubclassDriver.h"
24
25/**
26  This function makes boot time changes to the contents of the
27  MiscSystemManufacturer (Type 1).
28
29  @param  RecordData                 Pointer to copy of RecordData from the Data Table.
30
31  @retval EFI_SUCCESS                All parameters were valid.
32  @retval EFI_UNSUPPORTED            Unexpected RecordType value.
33  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
34
35**/
36MISC_SMBIOS_TABLE_FUNCTION(MiscSystemManufacturer)
37{
38  CHAR8                             *OptionalStrStart;
39  UINTN                             ManuStrLen;
40  UINTN                             VerStrLen;
41  UINTN                             PdNameStrLen;
42  UINTN                             SerialNumStrLen;
43  EFI_STATUS                        Status;
44  EFI_STRING                        Manufacturer;
45  EFI_STRING                        ProductName;
46  EFI_STRING                        Version;
47  EFI_STRING                        SerialNumber;
48  STRING_REF                        TokenToGet;
49  EFI_SMBIOS_HANDLE                 SmbiosHandle;
50  SMBIOS_TABLE_TYPE1                *SmbiosRecord;
51  EFI_MISC_SYSTEM_MANUFACTURER      *ForType1InputData;
52
53  ForType1InputData = (EFI_MISC_SYSTEM_MANUFACTURER *)RecordData;
54
55  //
56  // First check for invalid parameters.
57  //
58  if (RecordData == NULL) {
59    return EFI_INVALID_PARAMETER;
60  }
61
62  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER);
63  Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
64  ManuStrLen = StrLen(Manufacturer);
65  if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
66    return EFI_UNSUPPORTED;
67  }
68
69  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
70  ProductName = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
71  PdNameStrLen = StrLen(ProductName);
72  if (PdNameStrLen > SMBIOS_STRING_MAX_LENGTH) {
73    return EFI_UNSUPPORTED;
74  }
75
76  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
77  Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
78  VerStrLen = StrLen(Version);
79  if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
80    return EFI_UNSUPPORTED;
81  }
82
83  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER);
84  SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
85  SerialNumStrLen = StrLen(SerialNumber);
86  if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
87    return EFI_UNSUPPORTED;
88  }
89  //
90  // Two zeros following the last string.
91  //
92  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + 1);
93  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + 1);
94
95  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_INFORMATION;
96  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1);
97  //
98  // Make handle chosen by smbios protocol.add automatically.
99  //
100  SmbiosRecord->Hdr.Handle = 0;
101  //
102  // Manu will be the 1st optional string following the formatted structure.
103  //
104  SmbiosRecord->Manufacturer = 1;
105  //
106  // ProductName will be the 2nd optional string following the formatted structure.
107  //
108  SmbiosRecord->ProductName = 2;
109  //
110  // Version will be the 3rd optional string following the formatted structure.
111  //
112  SmbiosRecord->Version = 3;
113  //
114  // Version will be the 4th optional string following the formatted structure.
115  //
116  SmbiosRecord->SerialNumber = 4;
117  CopyMem ((UINT8 *) (&SmbiosRecord->Uuid),&ForType1InputData->SystemUuid,16);
118  SmbiosRecord->WakeUpType = (UINT8)ForType1InputData->SystemWakeupType;
119
120  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
121  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
122  UnicodeStrToAsciiStr(ProductName, OptionalStrStart + ManuStrLen + 1);
123  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1);
124  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1);
125
126  //
127  // Now we have got the full smbios record, call smbios protocol to add this record.
128  //
129  Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);
130
131  FreePool(SmbiosRecord);
132  return Status;
133}
134
135/* eof - MiscSystemManufacturerFunction.c */
136