ReactOS 0.4.16-dev-251-ga17b6e9
firmware.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Win32 Base API
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: NT6+ Firmware API
5 * COPYRIGHT: Copyright 2023-2024 Ratin Gao <ratin@knsoft.org>
6 */
7
8/* We need NT6+ Ex definitions */
9#undef NTDDI_VERSION
10#define NTDDI_VERSION NTDDI_VISTA
11#include <ndk/exfuncs.h>
12
13#include "k32_vista.h"
14
15_Success_(return > 0)
18GetFirmwareEnvironmentVariableExW(
20 _In_ LPCWSTR lpGuid,
23 _Out_opt_ PDWORD pdwAttribubutes)
24{
26 UNICODE_STRING VariableName, Namespace;
27 GUID VendorGuid;
29
30 /* Check input parameters and build NT strings */
31 if (!lpName || !lpGuid)
32 {
34 return 0;
35 }
36 RtlInitUnicodeString(&VariableName, lpName);
37 RtlInitUnicodeString(&Namespace, lpGuid);
38 Status = RtlGUIDFromString(&Namespace, &VendorGuid);
39 if (!NT_SUCCESS(Status))
40 {
42 return 0;
43 }
44
45 /* Query firmware system environment variable value */
46 Length = nSize;
48 &VendorGuid,
49 pBuffer,
50 &Length,
51 pdwAttribubutes);
52 if (!NT_SUCCESS(Status))
53 {
55 return 0;
56 }
57
58 return Length;
59}
60
61_Success_(return > 0)
64GetFirmwareEnvironmentVariableExA(
66 _In_ LPCSTR lpGuid,
69 _Out_opt_ PDWORD pdwAttribubutes)
70{
73 UNICODE_STRING VariableName, Namespace;
74 ANSI_STRING AnsiVariableName, AnsiNamespace;
75
76 /* Check input parameters and build NT strings */
77 if (!lpName || !lpGuid)
78 {
80 return 0;
81 }
82 RtlInitString(&AnsiVariableName, lpName);
83 Status = RtlAnsiStringToUnicodeString(&VariableName, &AnsiVariableName, TRUE);
84 if (!NT_SUCCESS(Status))
85 {
87 return 0;
88 }
89 RtlInitString(&AnsiNamespace, lpGuid);
90 Status = RtlAnsiStringToUnicodeString(&Namespace, &AnsiNamespace, TRUE);
91 if (!NT_SUCCESS(Status))
92 {
93 RtlFreeUnicodeString(&VariableName);
95 return 0;
96 }
97
98 /* Call unicode version interface */
99 Length = GetFirmwareEnvironmentVariableExW(VariableName.Buffer,
100 Namespace.Buffer,
101 pBuffer,
102 nSize,
103 pdwAttribubutes);
104
105 /* Cleanup and return */
106 RtlFreeUnicodeString(&Namespace);
107 RtlFreeUnicodeString(&VariableName);
108 return Length;
109}
110
111BOOL
112WINAPI
115 _In_ LPCWSTR lpGuid,
119{
121 UNICODE_STRING VariableName, Namespace;
122 GUID VendorGuid;
123
124 /* Check input parameters and build NT strings */
125 if (!lpName || !lpGuid)
126 {
128 return FALSE;
129 }
130 RtlInitUnicodeString(&VariableName, lpName);
131 RtlInitUnicodeString(&Namespace, lpGuid);
132 Status = RtlGUIDFromString(&Namespace, &VendorGuid);
133 if (!NT_SUCCESS(Status))
134 {
136 return FALSE;
137 }
138
139 /* Set firmware system environment variable value */
141 &VendorGuid,
142 pValue,
143 nSize,
145 if (!NT_SUCCESS(Status))
146 {
148 return FALSE;
149 }
150
151 return TRUE;
152}
153
154BOOL
155WINAPI
158 _In_ LPCSTR lpGuid,
162{
164 BOOL Result;
165 UNICODE_STRING VariableName, Namespace;
166 ANSI_STRING AnsiVariableName, AnsiNamespace;
167
168 /* Check input parameters and build NT strings */
169 if (!lpName || !lpGuid)
170 {
172 return FALSE;
173 }
174 RtlInitString(&AnsiVariableName, lpName);
175 Status = RtlAnsiStringToUnicodeString(&VariableName, &AnsiVariableName, TRUE);
176 if (!NT_SUCCESS(Status))
177 {
179 return FALSE;
180 }
181 RtlInitString(&AnsiNamespace, lpGuid);
182 Status = RtlAnsiStringToUnicodeString(&Namespace, &AnsiNamespace, TRUE);
183 if (!NT_SUCCESS(Status))
184 {
185 RtlFreeUnicodeString(&VariableName);
187 return FALSE;
188 }
189
190 /* Call unicode version interface */
192 Namespace.Buffer,
193 pValue,
194 nSize,
196
197 /* Cleanup and return */
198 RtlFreeUnicodeString(&Namespace);
199 RtlFreeUnicodeString(&VariableName);
200 return Result;
201}
202
204BOOL
205WINAPI
206GetFirmwareType(_Out_ PFIRMWARE_TYPE FirmwareType)
207{
210
211 /* Check input parameters */
212 if (FirmwareType == NULL)
213 {
215 return FALSE;
216 }
217
218 /* Query firmware type */
220 &BootInfo,
221 sizeof(BootInfo),
222 0);
223 if (!NT_SUCCESS(Status))
224 {
226 return FALSE;
227 }
228
229 *FirmwareType = BootInfo.FirmwareType;
230 return TRUE;
231}
enum _FIRMWARE_TYPE * PFIRMWARE_TYPE
LONG NTSTATUS
Definition: precomp.h:26
return
Definition: dirsup.c:529
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
BOOL WINAPI SetFirmwareEnvironmentVariableExA(_In_ LPCSTR lpName, _In_ LPCSTR lpGuid, _In_reads_bytes_opt_(nSize) PVOID pValue, _In_ DWORD nSize, _In_ DWORD dwAttributes)
Definition: firmware.c:156
BOOL WINAPI SetFirmwareEnvironmentVariableExW(_In_ LPCWSTR lpName, _In_ LPCWSTR lpGuid, _In_reads_bytes_opt_(nSize) PVOID pValue, _In_ DWORD nSize, _In_ DWORD dwAttributes)
Definition: firmware.c:113
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PWCHAR pValue
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING, GUID *)
@ SystemBootEnvironmentInformation
Definition: extypes.h:307
#define _Out_opt_
Definition: no_sal2.h:214
#define _Success_(c)
Definition: no_sal2.h:84
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _Out_writes_bytes_to_opt_(s, c)
Definition: no_sal2.h:240
#define _In_reads_bytes_opt_(s)
Definition: no_sal2.h:224
NTSYSAPI VOID NTAPI RtlInitString(PSTRING DestinationString, PCSZ SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI NtSetSystemEnvironmentValueEx(_In_ PUNICODE_STRING VariableName, _In_ LPGUID VendorGuid, _In_reads_bytes_opt_(ValueLength) PVOID Value, _In_ ULONG ValueLength, _In_ ULONG Attributes)
Definition: sysinfo.c:580
NTSTATUS NTAPI NtQuerySystemEnvironmentValueEx(_In_ PUNICODE_STRING VariableName, _In_ LPGUID VendorGuid, _Out_opt_ PVOID Value, _Inout_ PULONG ReturnLength, _Out_opt_ PULONG Attributes)
Definition: sysinfo.c:567
DWORD * PDWORD
Definition: pedump.c:68
PVOID pBuffer
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
uint32_t ULONG
Definition: typedefs.h:59
DWORD dwAttributes
Definition: vdmdbg.h:34
_In_ LPCSTR lpName
Definition: winbase.h:2814
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2109
#define WINAPI
Definition: msvc.h:6
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185