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. --- Include/Library/CommonLib.h | 540 ++++++++++++++++++++++++++++++++++++++ Include/Library/DcsCfgLib.h | 213 +++++++++++++++ Include/Library/GraphLib.h | 200 ++++++++++++++ Include/Library/PasswordLib.h | 108 ++++++++ Include/Protocol/ConsoleControl.h | 123 +++++++++ Include/Protocol/Speaker.h | 84 ++++++ 6 files changed, 1268 insertions(+) create mode 100644 Include/Library/CommonLib.h create mode 100644 Include/Library/DcsCfgLib.h create mode 100644 Include/Library/GraphLib.h create mode 100644 Include/Library/PasswordLib.h create mode 100644 Include/Protocol/ConsoleControl.h create mode 100644 Include/Protocol/Speaker.h (limited to 'Include') diff --git a/Include/Library/CommonLib.h b/Include/Library/CommonLib.h new file mode 100644 index 0000000..395d4c4 --- /dev/null +++ b/Include/Library/CommonLib.h @@ -0,0 +1,540 @@ +/** @file +EFI common library (helpers) + +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 +**/ + +#ifndef __COMMONLIB_H__ +#define __COMMONLIB_H__ + +#include +#include +#include +#include +#include +#include +#include + +#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) +#define FIELD_OFFSET(t, f) ((UINTN)(&((t*)0)->f)) + +////////////////////////////////////////////////////////////////////////// +// Memory procedures wrappers +////////////////////////////////////////////////////////////////////////// + +#define MEM_ALLOC MemAlloc +#define MEM_FREE MemFree +#define MEM_REALLOC MemRealloc + +VOID* +MemAlloc( + IN UINTN size + ); + +VOID +MemFree( + IN VOID* ptr + ); + +VOID* +MemRealloc( + IN UINTN OldSize, + IN UINTN NewSize, + IN VOID *OldBuffer OPTIONAL + ); + +EFI_STATUS +PrepareMemory( + IN UINTN address, + IN UINTN len, + OUT VOID** mem + ); + +////////////////////////////////////////////////////////////////////////// +// handles +////////////////////////////////////////////////////////////////////////// + +EFI_STATUS +EfiGetHandles( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol, OPTIONAL + IN VOID *SearchKey, OPTIONAL + OUT EFI_HANDLE **Buffer, + OUT UINTN *Count + ); + +EFI_STATUS +EfiGetStartDevice( + OUT EFI_HANDLE* handle + ); +////////////////////////////////////////////////////////////////////////// +// Print handle info +////////////////////////////////////////////////////////////////////////// + +VOID EfiPrintDevicePath( + IN EFI_HANDLE handle + ); + +VOID +EfiPrintProtocols( + IN EFI_HANDLE handle + ); + +////////////////////////////////////////////////////////////////////////// +// Block I/O +////////////////////////////////////////////////////////////////////////// + +EFI_BLOCK_IO_PROTOCOL* +EfiGetBlockIO( + IN EFI_HANDLE handle + ); + +extern EFI_HANDLE* gBIOHandles; +extern UINTN gBIOCount; + +EFI_STATUS +InitBio(); + +BOOLEAN +EfiIsPartition( + IN EFI_HANDLE h + ); + +EFI_STATUS +EfiGetPartDetails( + IN EFI_HANDLE h, + OUT HARDDRIVE_DEVICE_PATH* dpVolme, + OUT EFI_HANDLE* hDisk + ); + +EFI_STATUS +EfiGetPartGUID( + IN EFI_HANDLE h, + OUT EFI_GUID* guid + ); + +EFI_STATUS +EfiFindPartByGUID( + IN EFI_GUID* guid, + OUT EFI_HANDLE* h + ); + +////////////////////////////////////////////////////////////////////////// +// USB +////////////////////////////////////////////////////////////////////////// +extern EFI_HANDLE* gUSBHandles; +extern UINTN gUSBCount; + +EFI_STATUS +InitUsb(); + +EFI_STATUS +UsbGetIO( + IN EFI_HANDLE Handle, + OUT EFI_USB_IO_PROTOCOL** UsbIo + ); + +EFI_STATUS +UsbGetIOwithDescriptor( + IN EFI_HANDLE Handle, + OUT EFI_USB_IO_PROTOCOL** UsbIo, + OUT EFI_USB_DEVICE_DESCRIPTOR* UsbDescriptor + ); + +EFI_STATUS +UsbGetId( + IN EFI_HANDLE Handle, + OUT CHAR8** id + ); + +////////////////////////////////////////////////////////////////////////// +// Touch +////////////////////////////////////////////////////////////////////////// + +extern EFI_HANDLE* gTouchHandles; +extern UINTN gTouchCount; +extern int gTouchSimulate; +extern EFI_ABSOLUTE_POINTER_PROTOCOL* gTouchPointer; +extern UINT32 gTouchSimulateStep; + +EFI_STATUS +InitTouch(); + +EFI_STATUS +TouchGetIO( + IN EFI_HANDLE Handle, + OUT EFI_ABSOLUTE_POINTER_PROTOCOL** io + ); + + +////////////////////////////////////////////////////////////////////////// +// Console I/O +////////////////////////////////////////////////////////////////////////// + +#define OUT_PRINT(format, ...) AttrPrintEx(-1,-1, format, ##__VA_ARGS__) +#define ERR_PRINT(format, ...) AttrPrintEx(-1,-1, L"%E" format L"%N" , ##__VA_ARGS__) + +EFI_STATUS +ConsoleGetOutput( + IN EFI_HANDLE handle, + OUT EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL** io + ); + +VOID +FlushInput(); + +VOID +FlushInputDelay( + IN UINTN delay + ); + +EFI_INPUT_KEY +KeyWait( + CHAR16* Prompt, + UINTN mDelay, + UINT16 scanCode, + UINT16 unicodeChar); + +EFI_INPUT_KEY +GetKey(void); + +VOID +ConsoleShowTip( + IN CHAR16* tip, + IN UINTN delay); + +VOID +GetLine( + UINTN *length, + CHAR16 *line, + CHAR8 *asciiLine, + UINTN line_max, + UINT8 show); + +int +AskAsciiString( + CHAR8* prompt, + CHAR8* str, + UINTN max_len, + UINT8 visible); + +int +AskInt( + CHAR8* prompt, + UINT8 visible); + + +UINT8 +AskConfirm( + CHAR8* prompt, + UINT8 visible); + +UINT64 +AskUINT64( + IN char* prompt, + IN UINT64 def); + +UINT64 +AskHexUINT64( + IN char* prompt, + IN UINT64 def); + +UINTN +AskUINTN( + IN char* prompt, + IN UINTN def); + +BOOLEAN +AsciiHexToDigit( + OUT UINT8 *b, + IN CHAR8 *str + ); + +BOOLEAN +AsciiHexToByte( + OUT UINT8 *b, + IN CHAR8 *str + ); + +BOOLEAN +AsciiStrToGuid( + OUT EFI_GUID *guid, + IN CHAR8 *str + ); + + +////////////////////////////////////////////////////////////////////////// +// Attribute print +////////////////////////////////////////////////////////////////////////// + +extern BOOLEAN gShellReady; + +VOID +SetShellAPI( + IN VOID* shellProtocol, + IN VOID* shellParametersProtocol + ); + +/** +Print at a specific location on the screen. + +This function will move the cursor to a given screen location and print the specified string. + +If -1 is specified for either the Row or Col the current screen location for BOTH +will be used. + +If either Row or Col is out of range for the current console, then ASSERT. +If Format is NULL, then ASSERT. + +In addition to the standard %-based flags as supported by UefiLib Print() this supports +the following additional flags: +%N - Set output attribute to normal +%H - Set output attribute to highlight +%E - Set output attribute to error +%B - Set output attribute to blue color +%V - Set output attribute to green color + +Note: The background color is controlled by the shell command cls. + +@param[in] Col the column to print at +@param[in] Row the row to print at +@param[in] Format the format string +@param[in] ... The variable argument list. + +@return EFI_SUCCESS The printing was successful. +@return EFI_DEVICE_ERROR The console device reported an error. +**/ +EFI_STATUS +EFIAPI +AttrPrintEx( + IN INT32 Col OPTIONAL, + IN INT32 Row OPTIONAL, + IN CONST CHAR16 *Format, + ... + ); + +////////////////////////////////////////////////////////////////////////// +// Console control +////////////////////////////////////////////////////////////////////////// + +extern EFI_HANDLE* gConsoleControlHandles; +extern UINTN gConsoleControlCount; + +EFI_STATUS +InitConsoleControl(); + +////////////////////////////////////////////////////////////////////////// +// Beep +////////////////////////////////////////////////////////////////////////// +extern EFI_HANDLE* gSpeakerHandles; +extern UINTN gSpeakerCount; +extern EFI_GUID gSpeakerGuid; + +extern int gBeepEnabled; +extern BOOLEAN gBeepControlEnabled; +extern int gBeepDevice; +extern int gBeepNumberDefault; +extern int gBeepDurationDefault; +extern int gBeepIntervalDefault; +extern int gBeepToneDefault; + + +EFI_STATUS +InitSpeaker(); + +EFI_STATUS +SpeakerBeep( + IN UINT16 Tone, + IN UINTN NumberOfBeeps, + IN UINTN Duration, + IN UINTN Interval + ); + +EFI_STATUS +SpeakerSelect( + IN UINTN index + ); + +////////////////////////////////////////////////////////////////////////// +// Efi variables +////////////////////////////////////////////////////////////////////////// + +#define DCS_BOOT_STR L"DcsBoot" + +extern EFI_GUID gEfiDcsVariableGuid; + +EFI_STATUS +EfiGetVar( + IN CONST CHAR16* varName, + IN EFI_GUID* varGuid, + OUT VOID** varValue, + OUT UINTN* varSize, + OUT UINT32* varAttr + ); + +EFI_STATUS +EfiSetVar( + IN CONST CHAR16* varName, + IN EFI_GUID* varGuid, + IN VOID* varValue, + IN UINTN varSize, + IN UINT32 varAttr + ); + +EFI_STATUS +BootOrderInsert( + IN CHAR16 *OrderVarName, + IN UINTN index, + UINT16 value); + +EFI_STATUS +BootOrderRemove( + IN CHAR16 *OrderVarName, + UINT16 value + ); + +EFI_STATUS +BootMenuItemCreate( + IN CHAR16 *VarName, + IN CHAR16 *Desc, + IN EFI_HANDLE volumeHandle, + IN CHAR16 *Path, + IN BOOLEAN Reduced + ); + +EFI_STATUS +BootMenuItemRemove( + IN CHAR16 *VarName + ); + + + +////////////////////////////////////////////////////////////////////////// +// File +////////////////////////////////////////////////////////////////////////// + + +extern EFI_FILE* gFileRoot; +extern EFI_HANDLE gFileRootHandle; + +extern EFI_HANDLE* gFSHandles; +extern UINTN gFSCount; + +EFI_STATUS +InitFS(); + +EFI_STATUS +FileOpenRoot( + IN EFI_HANDLE rootHandle, + OUT EFI_FILE** rootFile); + +EFI_STATUS +FileOpen( + IN EFI_FILE* root, + IN CHAR16* name, + OUT EFI_FILE** file, + IN UINT64 mode, + IN UINT64 attributes + ); + +EFI_STATUS +FileClose( + IN EFI_FILE* f); + +EFI_STATUS +FileDelete( + IN EFI_FILE* root, + IN CHAR16* name + ); + +EFI_STATUS +FileRead( + IN EFI_FILE* f, + OUT VOID* data, + IN OUT UINTN* bytes, + IN OUT UINT64* position); + +EFI_STATUS +FileWrite( + IN EFI_FILE* f, + IN VOID* data, + IN OUT UINTN* bytes, + IN OUT UINT64* position); + +EFI_STATUS +FileGetInfo( + IN EFI_FILE* f, + OUT EFI_FILE_INFO** info, + OUT UINTN* size + ); + +EFI_STATUS +FileGetSize( + IN EFI_FILE* f, + OUT UINTN* size + ); + +EFI_STATUS +FileLoad( + IN EFI_FILE* root, + IN CHAR16* name, + OUT VOID** data, + OUT UINTN* size + ); + +EFI_STATUS +FileSave( + IN EFI_FILE* root, + IN CHAR16* name, + IN VOID* data, + IN UINTN size + ); + +EFI_STATUS +FileExist( + IN EFI_FILE* root, + IN CHAR16* name + ); + +EFI_STATUS +FileRename( + IN EFI_FILE* root, + IN CHAR16* src, + IN CHAR16* dst + ); + +EFI_STATUS +FileCopy( + IN EFI_FILE* srcroot, + IN CHAR16* src, + IN EFI_FILE* dstroot, + IN CHAR16* dst, + IN UINTN bufSz + ); + +////////////////////////////////////////////////////////////////////////// +// Exec +////////////////////////////////////////////////////////////////////////// + +EFI_STATUS +EfiExec( + IN EFI_HANDLE deviceHandle, + IN CHAR16* path + ); + +EFI_STATUS +ConnectAllEfi( + VOID + ); + +VOID +EfiCpuHalt(); + +#endif \ No newline at end of file diff --git a/Include/Library/DcsCfgLib.h b/Include/Library/DcsCfgLib.h new file mode 100644 index 0000000..6d74729 --- /dev/null +++ b/Include/Library/DcsCfgLib.h @@ -0,0 +1,213 @@ +/** @file +DCS configuration + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov + +This program and the accompanying materials +are licensed and made available under the terms and conditions +of the [to be defined License, Version]. The full text of the license may be found at +[opensource license to be defined] +**/ + +#ifndef __DCSCFGLIB_H__ +#define __DCSCFGLIB_H__ + +#include + +////////////////////////////////////////////////////////////////////////// +// DeList and GPT +////////////////////////////////////////////////////////////////////////// +#define EFI_PART_TYPE_BASIC_DATA_PART_GUID \ + { \ + 0xEBD0A0A2, 0xB9E5, 0x4433, { 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7 } \ + } + +#define EFI_PART_TYPE_MS_RESERVED_PART_GUID \ + { \ + 0xE3C9E316, 0x0B5C, 0x4DB8, { 0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE } \ + } + +#define EFI_PART_TYPE_MS_RECOVERY_PART_GUID \ + { \ + 0xDE94BBA4, 0x06D1, 0x06D1, { 0xA1, 0x6A, 0xBF, 0xD5, 0x01, 0x79, 0xD6, 0xAC } \ + } + +typedef struct _DCS_DISK_ENTRY_LIST DCS_DISK_ENTRY_LIST; +typedef struct _DCS_DEP_EXEC DCS_DEP_EXEC; + +extern EFI_GUID gEfiPartTypeBasicDataPartGuid; +extern EFI_GUID gEfiPartTypeMsReservedPartGuid; +extern EFI_GUID gEfiPartTypeMsRecoveryPartGuid; + +extern UINT64 gDcsDiskEntryListHeaderID; + +extern DCS_DISK_ENTRY_LIST *DeList; +extern DCS_DEP_EXEC *DeExecParams; + +// DcsCfg data +extern CONST CHAR16* DcsDiskEntrysFileName; +extern EFI_PARTITION_ENTRY DcsHidePart; +extern EFI_PARTITION_ENTRY *GptMainEntrys; +extern UINTN BootPartIdx; +extern UINTN MirrorPartIdx; + +EFI_STATUS +DeListParseSaved( + IN UINT8 *DeBuffer + ); + +EFI_STATUS +DeListLoadFromFile(); + +EFI_STATUS +DeListZero(); + +VOID +DeListPrint(); + +VOID +DeListSaveToFile(); + +EFI_STATUS +DeListApplySectorsToDisk( + IN UINTN diskIdx + ); + +EFI_STATUS +DeListExecEdit(); + +EFI_STATUS +DeListPwdCacheEdit(); + +EFI_STATUS +DeListRndSave(); + +EFI_STATUS +DeListRndLoad(); + +EFI_STATUS +GptLoadFromDisk( + IN UINTN diskIdx + ); + +VOID +GptHideParts(); + +VOID +GptSort(); + +VOID +GptSqueze(); + +EFI_STATUS +GptSyncMainAlt(); + +BOOLEAN +GptAskGUID( + IN char* prompt, + IN OUT EFI_GUID* guid + ); + +BOOLEAN +IsRegionOverlap(UINT64 start1, UINT64 end1, UINT64 start2, UINT64 end2); + +////////////////////////////////////////////////////////////////////////// +// Random +////////////////////////////////////////////////////////////////////////// +enum RndGeneratorTypes { + RndTypeNone = 0, + RndTypeFile, + RndTypeRDRand, + RndTypeDtrmHmacSha512 +}; + +#define RND_HEADER_SIGN SIGNATURE_64('D','C','S','_','R','A','N','D') + +typedef struct _DCS_RND DCS_RND; + +typedef +EFI_STATUS +(*DCS_RND_PREPARE)( + IN OUT DCS_RND *Rnd + ); + +typedef +EFI_STATUS +(*DCS_RND_GET_BYTES)( + IN DCS_RND *Rnd, + OUT UINT8 *buf, + IN UINTN len + ); + +#pragma pack(1) +/* state of DRBG HMAC SHA512 */ +typedef struct _RND_DTRM_HMAC_SHA512_STATE +{ + UINT8 V[64]; /* internal state 10.1.1.1 1a) */ + UINT8 C[64]; /* hmac key */ + UINT64 ReseedCtr; /* Number of RNG requests since last reseed --* 10.1.1.1 1c)*/ +} RND_DTRM_HMAC_SHA512_STATE; + +typedef struct _RND_FILE_STATE +{ + CHAR16 *FileName; + UINT8 *Data; + UINTN Size; + UINTN Pos; +} RND_FILE_STATE; + +typedef union _DCS_RND_STATE { + RND_DTRM_HMAC_SHA512_STATE HMacSha512; + RND_FILE_STATE File; +} DCS_RND_STATE; + +typedef struct _DCS_RND_SAVED { + UINT64 Sign; + UINT32 CRC; + UINT32 Size; + UINT32 Type; + UINT32 Pad; + EFI_TIME SavedAt; + DCS_RND_STATE State; + UINT8 pad[512 - 8 - 4 - 4 - 4 - 4 - sizeof(EFI_TIME) - sizeof(DCS_RND_STATE)]; +} DCS_RND_SAVED; +#pragma pack() +static_assert(sizeof(DCS_RND_SAVED) == 512, "Wrong size DCS_RND_SAVED"); + +typedef struct _DCS_RND { + DCS_RND_PREPARE Prepare; + DCS_RND_GET_BYTES GetBytes; + UINT32 Type; + UINT32 Pad; + DCS_RND_STATE State; +} DCS_RND; + +EFI_STATUS +RndInit( + IN UINTN rndType, + IN VOID* Context, + OUT DCS_RND **rnd); + +// Serialize rnd with state to/from memory +EFI_STATUS +RndLoad( + IN DCS_RND_SAVED *rndSaved, + OUT DCS_RND **rndOut + ); + +EFI_STATUS +RndSave( + DCS_RND *rnd, + DCS_RND_SAVED **rndSaved); + +// Global RND +extern DCS_RND* gRnd; + +EFI_STATUS +RndGetBytes(UINT8 *buf, UINTN len); + +EFI_STATUS +RndPreapare(); + +#endif + diff --git a/Include/Library/GraphLib.h b/Include/Library/GraphLib.h new file mode 100644 index 0000000..49cea5c --- /dev/null +++ b/Include/Library/GraphLib.h @@ -0,0 +1,200 @@ +/** @file +Graph library + +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 +**/ + +#ifndef __GRAPHLIB_H__ +#define __GRAPHLIB_H__ + +#include +#include + +////////////////////////////////////////////////////////////////////////// +// Graph +////////////////////////////////////////////////////////////////////////// + +extern EFI_HANDLE* gGraphHandles; +extern UINTN gGraphCount; +extern EFI_GRAPHICS_OUTPUT_PROTOCOL* gGraphOut; + +EFI_STATUS +InitGraph(); + +EFI_STATUS +GraphGetIO( + IN EFI_HANDLE Handle, + OUT EFI_GRAPHICS_OUTPUT_PROTOCOL** io + ); + +EFI_STATUS +GraphGetModeInfo( + IN UINTN mode, + OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **info, + OUT UINTN* szInfo + ); + +typedef struct _RECT { + UINT32 left; + UINT32 top; + UINT32 right; + UINT32 bottom; +} RECT, *PRECT; + +#pragma pack(1) +typedef struct { + UINT32 Width; + UINT32 Height; + RECT Dirty; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL Pixels[0]; +} BLT_HEADER; +#pragma pack() + +enum DRAW_OPERATION { + DrawOpSet = 0, + DrawOpOr, + DrawOpXor, + DrawOpClear, + DrawOpAlpha +}; + +typedef struct _DRAW_CONTEXT { + EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color; + UINT32 Op; + UINT32 DashLine; + UINT32 Alpha; //< 0..255 + EFI_GRAPHICS_OUTPUT_BLT_PIXEL AlphaColor; + INT32* Brush; // brush points(default 1) +} DRAW_CONTEXT, *PDRAW_CONTEXT; + +extern DRAW_CONTEXT gDrawContext; +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL gColorBlack; +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL gColorWhite; +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL gColorBlue; +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL gColorGreen; +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL gColorRed; +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL gColorGray; +extern INT32 gBrush3[5 * 2]; + +EFI_STATUS +ScreenGetSize( + OUT UINTN *Height, + OUT UINTN *Width + ); + +EFI_STATUS ScreenFillRect( + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *color, + IN UINTN x, + IN UINTN y, + IN UINTN width, + IN UINTN height + ); + +EFI_STATUS ScreenDrawBlt( + IN BLT_HEADER *blt, + IN UINTN x, + IN UINTN y + ); + +EFI_STATUS +ScreenSaveBlt( + OUT BLT_HEADER **bltScreen + ); + +EFI_STATUS ScreenUpdateDirty( + IN BLT_HEADER *blt + ); + +EFI_STATUS +BltDrawBlt( + IN OUT BLT_HEADER* canvas, + IN BLT_HEADER* blt, + IN UINTN x, + IN UINTN y + ); + +EFI_STATUS +RectMarkDirty( + IN OUT PRECT rect, + IN UINTN x, + IN UINTN y + ); + +EFI_STATUS +BltPoint( + IN BLT_HEADER* blt, + IN PDRAW_CONTEXT draw, + IN UINTN x, + IN UINTN y + ); + +VOID +BltLine( + IN BLT_HEADER* blt, + IN PDRAW_CONTEXT draw, + IN INT32 x0, + IN INT32 y0, + IN INT32 x1, + IN INT32 y1); + +VOID +BltBox( + IN BLT_HEADER* blt, + IN PDRAW_CONTEXT draw, + IN INT32 x0, + IN INT32 y0, + IN INT32 x1, + IN INT32 y1); + +VOID +BltCircle( + IN BLT_HEADER* blt, + IN PDRAW_CONTEXT draw, + IN INT32 xm, + IN INT32 ym, + IN INT32 r, + IN BOOLEAN fill); + +VOID +BltText( + IN BLT_HEADER* blt, + IN PDRAW_CONTEXT draw, + IN INT32 x, + IN INT32 y, + IN INT32 scale, // 0..256 reduce 256... enlarge + IN CONST CHAR8 *text); + + +EFI_STATUS +BmpGetSize( + IN const unsigned char* BmpImage, + IN UINTN BmpImageSize, + OUT UINTN *Height, + OUT UINTN *Width + ); + +EFI_STATUS +BmpToBlt( + IN CONST VOID *BmpImage, + IN UINTN BmpImageSize, + OUT BLT_HEADER **blt + ); + +VOID +BltFill( + IN BLT_HEADER* blt, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL fill, + IN INT32 x0, + IN INT32 y0, + IN INT32 x1, + IN INT32 y1 + ); + +#endif \ No newline at end of file diff --git a/Include/Library/PasswordLib.h b/Include/Library/PasswordLib.h new file mode 100644 index 0000000..62cad21 --- /dev/null +++ b/Include/Library/PasswordLib.h @@ -0,0 +1,108 @@ +/** @file +Password library + +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 +**/ + +#ifndef __PASSWORDLIB_H__ +#define __PASSWORDLIB_H__ + +#include +#include + +extern CHAR16* gPasswordPictureFileName; + +extern CHAR8* gPasswordPictureChars; +extern CHAR8* gPasswordPictureCharsDefault; +extern UINTN gPasswordPictureCharsLen; +extern UINT8 gPasswordVisible; +extern int gPasswordShowMark; + +extern int gPlatformLocked; +extern int gTPMLocked; +extern int gSCLocked; + +enum AskPwdType { + AskPwdLogin = 1, + AskPwdNew, + AskPwdConfirm +}; + +enum AskPwdRetCode { + AskPwdRetCancel = 0, + AskPwdRetLogin = 1, + AskPwdRetChange +}; + +VOID +AskPictPwdInt( + IN UINTN pwdType, + IN UINTN pwdMax, + OUT CHAR8* pwd, + OUT UINT32* pwdLen, + OUT INT32* retCode + ); + +VOID +AskConsolePwdInt( + OUT UINT32 *length, + OUT CHAR8 *asciiLine, + OUT INT32 *retCode, + IN UINTN line_max, + IN UINT8 show + ); + +extern EFI_GUID* gSmbSystemUUID; // Universal unique ID +extern CHAR8* gSmbSystemSerial; // System serial +extern CHAR8* gSmbSystemSKU; // SKU number +extern CHAR8* gSmbBaseBoardSerial; // Base board serial +extern UINT64* gSmbProcessorID; // Processor ID + +EFI_STATUS +SMBIOSGetSerials(); + +EFI_STATUS +PaltformGetIDCRC( + IN EFI_HANDLE handle, + OUT UINT32 *crc32 + ); + +EFI_STATUS +PlatformGetID( + IN EFI_HANDLE handle, + OUT CHAR8 **id, + OUT UINTN *idLen + ); + +EFI_STATUS +PlatformGetIDCRC( + IN EFI_HANDLE handle, + OUT UINT32 *crc32 + ); + +extern UINTN gBioIndexAuth; +extern BOOLEAN gBioIndexAuthOnRemovable; + +typedef struct _DCS_AUTH_DATA_MARK { + UINT32 HeaderCrc; + UINT32 PlatformCrc; + UINT32 AuthDataSize; + UINT32 Reserved; +} DCS_AUTH_DATA_MARK; + + +EFI_STATUS +PlatformGetAuthData( + OUT UINT8 **data, + OUT UINTN *len, + OUT EFI_HANDLE *secRegionHandle + ); + +#endif \ No newline at end of file diff --git a/Include/Protocol/ConsoleControl.h b/Include/Protocol/ConsoleControl.h new file mode 100644 index 0000000..c935970 --- /dev/null +++ b/Include/Protocol/ConsoleControl.h @@ -0,0 +1,123 @@ +/*++ + +Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. +The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + ConsoleControl.h + +Abstract: + + Abstraction of a Text mode or GOP/UGA screen + +--*/ + +#ifndef __CONSOLE_CONTROL_H__ +#define __CONSOLE_CONTROL_H__ + +#define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \ + { 0xf42f7782, 0x12e, 0x4c12, {0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21} } + +typedef struct _EFI_CONSOLE_CONTROL_PROTOCOL EFI_CONSOLE_CONTROL_PROTOCOL; + + +typedef enum { + EfiConsoleControlScreenText, + EfiConsoleControlScreenGraphics, + EfiConsoleControlScreenMaxValue +} EFI_CONSOLE_CONTROL_SCREEN_MODE; + + +typedef +EFI_STATUS +(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE) ( + IN EFI_CONSOLE_CONTROL_PROTOCOL *This, + OUT EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode, + OUT BOOLEAN *GopUgaExists, OPTIONAL + OUT BOOLEAN *StdInLocked OPTIONAL + ) +/*++ + + Routine Description: + Return the current video mode information. Also returns info about existence + of Graphics Output devices or UGA Draw devices in system, and if the Std In + device is locked. All the arguments are optional and only returned if a non + NULL pointer is passed in. + + Arguments: + This - Protocol instance pointer. + Mode - Are we in text of grahics mode. + GopUgaExists - TRUE if Console Spliter has found a GOP or UGA device + StdInLocked - TRUE if StdIn device is keyboard locked + + Returns: + EFI_SUCCESS - Mode information returned. + +--*/ +; + + +typedef +EFI_STATUS +(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE) ( + IN EFI_CONSOLE_CONTROL_PROTOCOL *This, + IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode + ) +/*++ + + Routine Description: + Set the current mode to either text or graphics. Graphics is + for Quiet Boot. + + Arguments: + This - Protocol instance pointer. + Mode - Mode to set the + + Returns: + EFI_SUCCESS - Mode information returned. + +--*/ +; + + +typedef +EFI_STATUS +(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN) ( + IN EFI_CONSOLE_CONTROL_PROTOCOL *This, + IN CHAR16 *Password + ) +/*++ + + Routine Description: + Lock Std In devices until Password is typed. + + Arguments: + This - Protocol instance pointer. + Password - Password needed to unlock screen. NULL means unlock keyboard + + Returns: + EFI_SUCCESS - Mode information returned. + EFI_DEVICE_ERROR - Std In not locked + +--*/ +; + + + +struct _EFI_CONSOLE_CONTROL_PROTOCOL { + EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE GetMode; + EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE SetMode; + EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN LockStdIn; +}; + +extern EFI_GUID gEfiConsoleControlProtocolGuid; + +#endif diff --git a/Include/Protocol/Speaker.h b/Include/Protocol/Speaker.h new file mode 100644 index 0000000..938f575 --- /dev/null +++ b/Include/Protocol/Speaker.h @@ -0,0 +1,84 @@ +/*++ + + Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
+ + + This program and the accompanying materials are licensed and made available under + + the terms and conditions of the BSD License that accompanies this distribution. + + +The full text of the license may be found at + + http://opensource.org/licenses/bsd-license.php. + + + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + + + +Module Name: + + Speaker.h + +Abstract: + + EFI Speaker Interface Protocol + +Revision History + +**/ + +#ifndef _EFI_SPEAKER_H +#define _EFI_SPEAKER_H + +#include +#include +#include + +// +// Global Id for Speaker Interface +// +#define EFI_SPEAKER_INTERFACE_PROTOCOL_GUID \ + { \ + 0x400b4476, 0x3081, 0x11d6, 0x87, 0xed, 0x00, 0x06, 0x29, 0x45, 0xc3, 0xb9 \ + } + +typedef struct _EFI_SPEAKER_IF_PROTOCOL EFI_SPEAKER_IF_PROTOCOL; + +// +// Beep Code +// +typedef +EFI_STATUS +(EFIAPI *EFI_GENERATE_BEEP) ( + IN EFI_SPEAKER_IF_PROTOCOL * This, + IN UINTN NumberOfBeep, + IN UINTN BeepDuration, + IN UINTN TimeInterval + ); + +// +// Set Frequency +// +typedef +EFI_STATUS +(EFIAPI *EFI_SPEAKER_SET_FREQUENCY) ( + IN EFI_SPEAKER_IF_PROTOCOL * This, + IN UINT16 Frequency + ); + +// +// Protocol definition +// +struct _EFI_SPEAKER_IF_PROTOCOL { + EFI_SPEAKER_SET_FREQUENCY SetSpeakerToneFrequency; + EFI_GENERATE_BEEP GenerateBeep; +} ; + +extern EFI_GUID gEfiSpeakerInterfaceProtocolGuid; +#endif -- cgit v1.2.3