VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/Library/CommonLib/EfiBml.c
blob: 184ca75337919c4f4cda7e71cc979882d70149fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** @file
EFI DCS BML 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 <Library/CommonLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/DcsBmlProto.h>

//////////////////////////////////////////////////////////////////////////
// BML
//////////////////////////////////////////////////////////////////////////
EFI_HANDLE*                gBmlHandles = NULL;
UINTN                      gBmlCount = 0;
EFI_DCSBML_PROTOCOL*	   gBml = NULL;
EFI_GUID                   gBmlGuid = EFI_DCSBML_INTERFACE_PROTOCOL_GUID;

EFI_STATUS
BmlSelect(
    IN UINTN index) {
    if (index < gBmlCount) {
        return gBS->HandleProtocol(gBmlHandles[index], &gBmlGuid, (VOID**)&gBml);
    }
    return EFI_NOT_FOUND;
}

EFI_STATUS
InitBml() {
	EFI_STATUS	res;
	// BML control if supported
	res = EfiGetHandles(ByProtocol, &gBmlGuid, 0, &gBmlHandles, &gBmlCount);
	if (gBmlCount > 0) {
		return BmlSelect(gBmlCount - 1);
    }
    return EFI_NOT_FOUND;
}


EFI_STATUS
BmlLock(
	IN BOOLEAN lock
	)
{
	if (gBml != NULL) {
        return gBml->BootMenuLock(gBml, lock);
	}
	return EFI_UNSUPPORTED;
}