123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- /*++
- Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
- Module Name:
- MiscNumberOfInstallableLanguagesFunction.c
- Abstract:
- This driver parses the mSmbiosMiscDataTable structure and reports
- any generated data.
- --*/
- #include "CommonHeader.h"
- #include "MiscSubclassDriver.h"
- /**
- Check whether the language is supported for given HII handle
- @param HiiHandle The HII package list handle.
- @param Offset The offest of current lanague in the supported languages.
- @param CurrentLang The language code.
- @retval TRUE Supported.
- @retval FALSE Not Supported.
- **/
- VOID
- EFIAPI
- CurrentLanguageMatch (
- IN EFI_HII_HANDLE HiiHandle,
- OUT UINT16 *Offset,
- OUT CHAR8 *CurrentLang
- )
- {
- CHAR8 *DefaultLang;
- CHAR8 *BestLanguage;
- CHAR8 *Languages;
- CHAR8 *MatchLang;
- CHAR8 *EndMatchLang;
- UINTN CompareLength;
- Languages = HiiGetSupportedLanguages (HiiHandle);
- if (Languages == NULL) {
- return;
- }
- GetEfiGlobalVariable2 (L"PlatformLang", &CurrentLang, NULL);
- DefaultLang = (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang);
- BestLanguage = GetBestLanguage (
- Languages,
- FALSE,
- (CurrentLang != NULL) ? CurrentLang : "",
- DefaultLang,
- NULL
- );
- if (BestLanguage != NULL) {
- //
- // Find the best matching RFC 4646 language, compute the offset.
- //
- CompareLength = AsciiStrLen (BestLanguage);
- for (MatchLang = Languages, (*Offset) = 0; *MatchLang != '\0'; (*Offset)++) {
- //
- // Seek to the end of current match language.
- //
- for (EndMatchLang = MatchLang; *EndMatchLang != '\0' && *EndMatchLang != ';'; EndMatchLang++);
- if ((EndMatchLang == MatchLang + CompareLength) && AsciiStrnCmp(MatchLang, BestLanguage, CompareLength) == 0) {
- //
- // Find the current best Language in the supported languages
- //
- break;
- }
- //
- // best language match be in the supported language.
- //
- ASSERT (*EndMatchLang == ';');
- MatchLang = EndMatchLang + 1;
- }
- FreePool (BestLanguage);
- }
- FreePool (Languages);
- if (CurrentLang != NULL) {
- FreePool (CurrentLang);
- }
- return ;
- }
- /**
- Get next language from language code list (with separator ';').
- @param LangCode Input: point to first language in the list. On
- Otput: point to next language in the list, or
- NULL if no more language in the list.
- @param Lang The first language in the list.
- **/
- VOID
- EFIAPI
- GetNextLanguage (
- IN OUT CHAR8 **LangCode,
- OUT CHAR8 *Lang
- )
- {
- UINTN Index;
- CHAR8 *StringPtr;
- ASSERT (LangCode != NULL);
- ASSERT (*LangCode != NULL);
- ASSERT (Lang != NULL);
- Index = 0;
- StringPtr = *LangCode;
- while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {
- Index++;
- }
- CopyMem (Lang, StringPtr, Index);
- Lang[Index] = 0;
- if (StringPtr[Index] == ';') {
- Index++;
- }
- *LangCode = StringPtr + Index;
- }
- /**
- This function returns the number of supported languages on HiiHandle.
- @param HiiHandle The HII package list handle.
- @retval The number of supported languages.
- **/
- UINT16
- EFIAPI
- GetSupportedLanguageNumber (
- IN EFI_HII_HANDLE HiiHandle
- )
- {
- CHAR8 *Lang;
- CHAR8 *Languages;
- CHAR8 *LanguageString;
- UINT16 LangNumber;
- Languages = HiiGetSupportedLanguages (HiiHandle);
- if (Languages == NULL) {
- return 0;
- }
- LangNumber = 0;
- Lang = AllocatePool (AsciiStrSize (Languages));
- if (Lang != NULL) {
- LanguageString = Languages;
- while (*LanguageString != 0) {
- GetNextLanguage (&LanguageString, Lang);
- LangNumber++;
- }
- FreePool (Lang);
- }
- FreePool (Languages);
- return LangNumber;
- }
- /**
- This function makes boot time changes to the contents of the
- MiscNumberOfInstallableLanguages (Type 13).
- @param RecordData Pointer to copy of RecordData from the Data Table.
- @retval EFI_SUCCESS All parameters were valid.
- @retval EFI_UNSUPPORTED Unexpected RecordType value.
- @retval EFI_INVALID_PARAMETER Invalid parameter was found.
- **/
- MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages)
- {
- UINTN LangStrLen;
- CHAR8 CurrentLang[SMBIOS_STRING_MAX_LENGTH + 1];
- CHAR8 *OptionalStrStart;
- UINT16 Offset;
- EFI_STATUS Status;
- EFI_SMBIOS_HANDLE SmbiosHandle;
- SMBIOS_TABLE_TYPE13 *SmbiosRecord;
- EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES *ForType13InputData;
- ForType13InputData = (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES *)RecordData;
- //
- // First check for invalid parameters.
- //
- if (RecordData == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- ForType13InputData->NumberOfInstallableLanguages = GetSupportedLanguageNumber (mHiiHandle);
- //
- // Try to check if current langcode matches with the langcodes in installed languages
- //
- ZeroMem(CurrentLang, SMBIOS_STRING_MAX_LENGTH + 1);
- CurrentLanguageMatch (mHiiHandle, &Offset, CurrentLang);
- LangStrLen = AsciiStrLen(CurrentLang);
- //
- // Two zeros following the last string.
- //
- SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);
- ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);
- SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION;
- SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE13);
- //
- // Make handle chosen by smbios protocol.add automatically.
- //
- SmbiosRecord->Hdr.Handle = 0;
- SmbiosRecord->InstallableLanguages = (UINT8)ForType13InputData->NumberOfInstallableLanguages;
- SmbiosRecord->Flags = (UINT8)ForType13InputData->LanguageFlags.AbbreviatedLanguageFormat;
- SmbiosRecord->CurrentLanguages = 1;
- OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
- AsciiStrCpyS(OptionalStrStart, LangStrLen + 1 + 1, CurrentLang);
- //
- // Now we have got the full smbios record, call smbios protocol to add this record.
- //
- SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
- Status = Smbios-> Add(
- Smbios,
- NULL,
- &SmbiosHandle,
- (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
- );
- FreePool(SmbiosRecord);
- return Status;
- }
|