]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/WinNtBlockIoDxe/DriverDiagnostics.c
Fix an issue to match invalid Language codes like "enus"
[mirror_edk2.git] / Nt32Pkg / WinNtBlockIoDxe / DriverDiagnostics.c
CommitLineData
10160456 1/*++\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 DriverDiagnostics.c\r
15\r
16Abstract:\r
17\r
18--*/\r
19#include <Uefi.h>\r
20#include <WinNtDxe.h>\r
21#include <Protocol/BlockIo.h>\r
22#include <Protocol/ComponentName.h>\r
23#include <Protocol/DriverBinding.h>\r
24\r
25#include "WinNtBlockIo.h"\r
26\r
27//\r
28// EFI Driver Diagnostics Functions\r
29//\r
30EFI_STATUS\r
31EFIAPI\r
32WinNtBlockIoDriverDiagnosticsRunDiagnostics (\r
33 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
34 IN EFI_HANDLE ControllerHandle,\r
35 IN EFI_HANDLE ChildHandle OPTIONAL,\r
36 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
37 IN CHAR8 *Language,\r
38 OUT EFI_GUID **ErrorType,\r
39 OUT UINTN *BufferSize,\r
40 OUT CHAR16 **Buffer\r
41 );\r
42\r
43//\r
44// EFI Driver Diagnostics Protocol\r
45//\r
db168de9 46GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS_PROTOCOL gWinNtBlockIoDriverDiagnostics = {\r
10160456 47 WinNtBlockIoDriverDiagnosticsRunDiagnostics,\r
db168de9 48 "eng"\r
49};\r
50\r
51//\r
52// EFI Driver Diagnostics 2 Protocol\r
53//\r
54GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gWinNtBlockIoDriverDiagnostics2 = {\r
55 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) WinNtBlockIoDriverDiagnosticsRunDiagnostics,\r
56 "en"\r
10160456 57};\r
58\r
59EFI_STATUS\r
60EFIAPI\r
61WinNtBlockIoDriverDiagnosticsRunDiagnostics (\r
62 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
63 IN EFI_HANDLE ControllerHandle,\r
64 IN EFI_HANDLE ChildHandle OPTIONAL,\r
65 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
66 IN CHAR8 *Language,\r
67 OUT EFI_GUID **ErrorType,\r
68 OUT UINTN *BufferSize,\r
69 OUT CHAR16 **Buffer\r
70 )\r
71/*++\r
72\r
73 Routine Description:\r
74 Runs diagnostics on a controller.\r
75\r
76 Arguments:\r
77 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
78 ControllerHandle - The handle of the controller to run diagnostics on.\r
79 ChildHandle - The handle of the child controller to run diagnostics on\r
80 This is an optional parameter that may be NULL. It will\r
81 be NULL for device drivers. It will also be NULL for a\r
82 bus drivers that wish to run diagnostics on the bus\r
83 controller. It will not be NULL for a bus driver that\r
84 wishes to run diagnostics on one of its child controllers.\r
85 DiagnosticType - Indicates type of diagnostics to perform on the controller\r
86 specified by ControllerHandle and ChildHandle. See\r
87 "Related Definitions" for the list of supported types.\r
88 Language - A pointer to a three character ISO 639-2 language\r
db168de9 89 identifier or a Null-terminated ASCII string array indicating\r
90 the language. This is the language in which the optional\r
10160456 91 error message should be returned in Buffer, and it must\r
92 match one of the languages specified in SupportedLanguages.\r
93 The number of languages supported by a driver is up to\r
94 the driver writer.\r
95 ErrorType - A GUID that defines the format of the data returned in\r
96 Buffer.\r
97 BufferSize - The size, in bytes, of the data returned in Buffer.\r
98 Buffer - A buffer that contains a Null-terminated Unicode string\r
99 plus some additional data whose format is defined by\r
100 ErrorType. Buffer is allocated by this function with\r
101 AllocatePool(), and it is the caller's responsibility\r
102 to free it with a call to FreePool().\r
103\r
104 Returns:\r
105 EFI_SUCCESS - The controller specified by ControllerHandle and\r
106 ChildHandle passed the diagnostic.\r
107 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
108 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid\r
109 EFI_HANDLE.\r
110 EFI_INVALID_PARAMETER - Language is NULL.\r
111 EFI_INVALID_PARAMETER - ErrorType is NULL.\r
112 EFI_INVALID_PARAMETER - BufferType is NULL.\r
113 EFI_INVALID_PARAMETER - Buffer is NULL.\r
114 EFI_UNSUPPORTED - The driver specified by This does not support\r
115 running diagnostics for the controller specified\r
116 by ControllerHandle and ChildHandle.\r
117 EFI_UNSUPPORTED - The driver specified by This does not support the\r
118 type of diagnostic specified by DiagnosticType.\r
119 EFI_UNSUPPORTED - The driver specified by This does not support the\r
120 language specified by Language.\r
121 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete\r
122 the diagnostics.\r
123 EFI_OUT_OF_RESOURCES - There are not enough resources available to return\r
124 the status information in ErrorType, BufferSize,\r
125 and Buffer.\r
126 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and\r
127 ChildHandle did not pass the diagnostic.\r
128\r
129--*/\r
130{\r
131 EFI_STATUS Status;\r
132 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
db168de9 133 CHAR8 *SupportedLanguages;\r
134 BOOLEAN Iso639Language;\r
135 BOOLEAN Found;\r
136 UINTN Index;\r
10160456 137\r
138 if (Language == NULL ||\r
139 ErrorType == NULL ||\r
140 Buffer == NULL ||\r
141 ControllerHandle == NULL ||\r
142 BufferSize == NULL) {\r
143\r
144 return EFI_INVALID_PARAMETER;\r
145 }\r
146\r
db168de9 147 SupportedLanguages = This->SupportedLanguages;\r
148 Iso639Language = (BOOLEAN)(This == &gWinNtBlockIoDriverDiagnostics);\r
149 //\r
150 // Make sure Language is in the set of Supported Languages\r
151 //\r
152 Found = FALSE;\r
153 while (*SupportedLanguages != 0) {\r
154 if (Iso639Language) {\r
155 if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
156 Found = TRUE;\r
157 break;\r
158 }\r
159 SupportedLanguages += 3;\r
160 } else {\r
161 for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
5127b471 162 if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
db168de9 163 Found = TRUE;\r
164 break;\r
165 }\r
166 SupportedLanguages += Index;\r
167 for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
10160456 168 }\r
10160456 169 }\r
db168de9 170 //\r
171 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
172 //\r
173 if (!Found) {\r
10160456 174 return EFI_UNSUPPORTED;\r
175 }\r
db168de9 176 \r
10160456 177 *ErrorType = NULL;\r
178 *BufferSize = 0;\r
179 if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
180 *ErrorType = &gEfiBlockIoProtocolGuid;\r
181 *BufferSize = 0x60;\r
182 Buffer = AllocatePool ((UINTN) (*BufferSize));\r
183 CopyMem (*Buffer, L"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
184 return EFI_DEVICE_ERROR;\r
185 }\r
186\r
187 //\r
188 // Validate controller handle\r
189 //\r
190 Status = gBS->OpenProtocol (\r
191 ControllerHandle,\r
192 &gEfiWinNtIoProtocolGuid,\r
193 &BlockIo,\r
194 gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
195 ControllerHandle,\r
196 EFI_OPEN_PROTOCOL_BY_DRIVER\r
197 );\r
198\r
199 if (!EFI_ERROR (Status)) {\r
200 gBS->CloseProtocol (\r
201 ControllerHandle,\r
202 &gEfiWinNtIoProtocolGuid,\r
203 gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
204 ControllerHandle\r
205 );\r
206\r
207 return EFI_UNSUPPORTED;\r
208 }\r
209\r
210 if (Status == EFI_UNSUPPORTED) {\r
211 return Status;\r
212 } else if (Status != EFI_ALREADY_STARTED) {\r
213 return EFI_INVALID_PARAMETER;\r
214 }\r
215\r
216 return EFI_SUCCESS;\r
217}\r