From b87fc6b140772ba3017de311c7063c259424264c Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 15 Aug 2016 17:11:31 +0200 Subject: First public release. Used by VeraCrypt 1.18. --- Library/CommonLib/EfiBeep.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Library/CommonLib/EfiBeep.c (limited to 'Library/CommonLib/EfiBeep.c') diff --git a/Library/CommonLib/EfiBeep.c b/Library/CommonLib/EfiBeep.c new file mode 100644 index 0000000..2522078 --- /dev/null +++ b/Library/CommonLib/EfiBeep.c @@ -0,0 +1,69 @@ +/** @file +EFI speaker beep helpers routines/wrappers + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials are licensed and made available +under the terms and conditions of the GNU Lesser General Public License, version 3.0 (LGPL-3.0). + +The full text of the license may be found at +https://opensource.org/licenses/LGPL-3.0 +**/ + +#include +#include +#include + +////////////////////////////////////////////////////////////////////////// +// Beep +////////////////////////////////////////////////////////////////////////// +EFI_HANDLE* gSpeakerHandles = NULL; +UINTN gSpeakerCount = 0; +EFI_SPEAKER_IF_PROTOCOL* gSpeaker = NULL; +EFI_GUID gSpeakerGuid = EFI_SPEAKER_INTERFACE_PROTOCOL_GUID; + +// Beep defaults +int gBeepEnabled = 1; +BOOLEAN gBeepControlEnabled = 1; +int gBeepDevice = -1; +int gBeepNumberDefault = 1; +int gBeepDurationDefault = 100; +int gBeepIntervalDefault = 0; +int gBeepToneDefault = 0x500; + +EFI_STATUS +InitSpeaker() { + EFI_STATUS res; + // Init Console control if supported + res = EfiGetHandles(ByProtocol, &gSpeakerGuid, 0, &gSpeakerHandles, &gSpeakerCount); + if (gSpeakerCount > 0) { + return SpeakerSelect(gSpeakerCount - 1); + } + return res; +} + +EFI_STATUS +SpeakerSelect( + IN UINTN index) { + if (index < gSpeakerCount) { + return gBS->HandleProtocol(gSpeakerHandles[index], &gSpeakerGuid, (VOID**)&gSpeaker); + } + return EFI_NOT_FOUND; +} + +EFI_STATUS +SpeakerBeep( + IN UINT16 Tone, + IN UINTN NumberOfBeeps, + IN UINTN Duration, + IN UINTN Interval + ) +{ + if (gSpeaker != NULL) { + gSpeaker->SetSpeakerToneFrequency(gSpeaker, Tone); + return gSpeaker->GenerateBeep(gSpeaker, NumberOfBeeps, Duration, Interval); + } + return EFI_UNSUPPORTED; +} + -- cgit v1.2.3