Home | History | Annotate | Download | only in MiscSubClassPlatformDxe
      1 /** @file
      2   BaseBoard manufacturer information boot time changes.
      3   SMBIOS type 2.
      4 
      5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions of the BSD License
      8 which accompanies this distribution.  The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #include "MiscSubclassDriver.h"
     17 /**
     18   This function makes boot time changes to the contents of the
     19   MiscBaseBoardManufacturer (Type 2).
     20 
     21   @param  RecordData                 Pointer to copy of RecordData from the Data Table.
     22 
     23   @retval EFI_SUCCESS                All parameters were valid.
     24   @retval EFI_UNSUPPORTED            Unexpected RecordType value.
     25   @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
     26 
     27 **/
     28 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
     29 {
     30   CHAR8                           *OptionalStrStart;
     31   UINTN                           ManuStrLen;
     32   UINTN                           ProductStrLen;
     33   UINTN                           VerStrLen;
     34   UINTN                           AssertTagStrLen;
     35   UINTN                           SerialNumStrLen;
     36   UINTN                           ChassisStrLen;
     37   EFI_STATUS                      Status;
     38   EFI_STRING                      Manufacturer;
     39   EFI_STRING                      Product;
     40   EFI_STRING                      Version;
     41   EFI_STRING                      SerialNumber;
     42   EFI_STRING                      AssertTag;
     43   EFI_STRING                      Chassis;
     44   STRING_REF                      TokenToGet;
     45   EFI_SMBIOS_HANDLE               SmbiosHandle;
     46   SMBIOS_TABLE_TYPE2              *SmbiosRecord;
     47   EFI_MISC_BASE_BOARD_MANUFACTURER   *ForType2InputData;
     48 
     49   ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;
     50 
     51   //
     52   // First check for invalid parameters.
     53   //
     54   if (RecordData == NULL) {
     55     return EFI_INVALID_PARAMETER;
     56   }
     57 
     58   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
     59   Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
     60   ManuStrLen = StrLen(Manufacturer);
     61   if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
     62     return EFI_UNSUPPORTED;
     63   }
     64 
     65   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);
     66   Product = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
     67   ProductStrLen = StrLen(Product);
     68   if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {
     69     return EFI_UNSUPPORTED;
     70   }
     71 
     72   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
     73   Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
     74   VerStrLen = StrLen(Version);
     75   if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
     76     return EFI_UNSUPPORTED;
     77   }
     78 
     79   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER);
     80   SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
     81   SerialNumStrLen = StrLen(SerialNumber);
     82   if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
     83     return EFI_UNSUPPORTED;
     84   }
     85 
     86   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);
     87   AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
     88   AssertTagStrLen = StrLen(AssertTag);
     89   if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
     90     return EFI_UNSUPPORTED;
     91   }
     92 
     93   TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);
     94   Chassis = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
     95   ChassisStrLen = StrLen(Chassis);
     96   if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {
     97     return EFI_UNSUPPORTED;
     98   }
     99 
    100 
    101   //
    102   // Two zeros following the last string.
    103   //
    104   SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);
    105   ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);
    106 
    107   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
    108   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);
    109   //
    110   // Make handle chosen by smbios protocol.add automatically.
    111   //
    112   SmbiosRecord->Hdr.Handle = 0;
    113   //
    114   // Manu will be the 1st optional string following the formatted structure.
    115   //
    116   SmbiosRecord->Manufacturer = 1;
    117   //
    118   // ProductName will be the 2st optional string following the formatted structure.
    119   //
    120   SmbiosRecord->ProductName  = 2;
    121   //
    122   // Version will be the 3rd optional string following the formatted structure.
    123   //
    124   SmbiosRecord->Version = 3;
    125   //
    126   // SerialNumber will be the 4th optional string following the formatted structure.
    127   //
    128   SmbiosRecord->SerialNumber = 4;
    129   //
    130   // AssertTag will be the 5th optional string following the formatted structure.
    131   //
    132   SmbiosRecord->AssetTag = 5;
    133 
    134   //
    135   // LocationInChassis will be the 6th optional string following the formatted structure.
    136   //
    137   SmbiosRecord->LocationInChassis = 6;
    138   SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));
    139   SmbiosRecord->ChassisHandle  = 0;
    140   SmbiosRecord->BoardType      = (UINT8)ForType2InputData->BaseBoardType;
    141   SmbiosRecord->NumberOfContainedObjectHandles = 0;
    142 
    143   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
    144   //
    145   // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
    146   //
    147   OptionalStrStart -= 2;
    148   UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
    149   UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);
    150   UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);
    151   UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);
    152   UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
    153   UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1);
    154   //
    155   // Now we have got the full smbios record, call smbios protocol to add this record.
    156   //
    157   Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);
    158 
    159   FreePool(SmbiosRecord);
    160   return Status;
    161 }
    162