]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Console/Terminal/Dxe/ComponentName.c
Fix component name bugs when input Controller Name is invalid
[mirror_edk2.git] / EdkModulePkg / Universal / Console / Terminal / Dxe / ComponentName.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ComponentName.c
15
16 Abstract:
17
18 --*/
19
20
21 #include "Terminal.h"
22
23 //
24 // EFI Component Name Functions
25 //
26 EFI_STATUS
27 EFIAPI
28 TerminalComponentNameGetDriverName (
29 IN EFI_COMPONENT_NAME_PROTOCOL *This,
30 IN CHAR8 *Language,
31 OUT CHAR16 **DriverName
32 );
33
34 EFI_STATUS
35 EFIAPI
36 TerminalComponentNameGetControllerName (
37 IN EFI_COMPONENT_NAME_PROTOCOL *This,
38 IN EFI_HANDLE ControllerHandle,
39 IN EFI_HANDLE ChildHandle OPTIONAL,
40 IN CHAR8 *Language,
41 OUT CHAR16 **ControllerName
42 );
43
44 //
45 // EFI Component Name Protocol
46 //
47 EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName = {
48 TerminalComponentNameGetDriverName,
49 TerminalComponentNameGetControllerName,
50 "eng"
51 };
52
53 static EFI_UNICODE_STRING_TABLE mTerminalDriverNameTable[] = {
54 {
55 "eng",
56 (CHAR16 *) L"Serial Terminal Driver"
57 },
58 {
59 NULL,
60 NULL
61 }
62 };
63
64 EFI_STATUS
65 EFIAPI
66 TerminalComponentNameGetDriverName (
67 IN EFI_COMPONENT_NAME_PROTOCOL *This,
68 IN CHAR8 *Language,
69 OUT CHAR16 **DriverName
70 )
71 /*++
72
73 Routine Description:
74 Retrieves a Unicode string that is the user readable name of the EFI Driver.
75
76 Arguments:
77 This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
78 Language - A pointer to a three character ISO 639-2 language identifier.
79 This is the language of the driver name that that the caller
80 is requesting, and it must match one of the languages specified
81 in SupportedLanguages. The number of languages supported by a
82 driver is up to the driver writer.
83 DriverName - A pointer to the Unicode string to return. This Unicode string
84 is the name of the driver specified by This in the language
85 specified by Language.
86
87 Returns:
88 EFI_SUCCESS - The Unicode string for the Driver specified by This
89 and the language specified by Language was returned
90 in DriverName.
91 EFI_INVALID_PARAMETER - Language is NULL.
92 EFI_INVALID_PARAMETER - DriverName is NULL.
93 EFI_UNSUPPORTED - The driver specified by This does not support the
94 language specified by Language.
95
96 --*/
97 {
98 return LookupUnicodeString (
99 Language,
100 gTerminalComponentName.SupportedLanguages,
101 mTerminalDriverNameTable,
102 DriverName
103 );
104 }
105
106 EFI_STATUS
107 EFIAPI
108 TerminalComponentNameGetControllerName (
109 IN EFI_COMPONENT_NAME_PROTOCOL *This,
110 IN EFI_HANDLE ControllerHandle,
111 IN EFI_HANDLE ChildHandle OPTIONAL,
112 IN CHAR8 *Language,
113 OUT CHAR16 **ControllerName
114 )
115 /*++
116
117 Routine Description:
118 Retrieves a Unicode string that is the user readable name of the controller
119 that is being managed by an EFI Driver.
120
121 Arguments:
122 This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
123 ControllerHandle - The handle of a controller that the driver specified by
124 This is managing. This handle specifies the controller
125 whose name is to be returned.
126 ChildHandle - The handle of the child controller to retrieve the name
127 of. This is an optional parameter that may be NULL. It
128 will be NULL for device drivers. It will also be NULL
129 for a bus drivers that wish to retrieve the name of the
130 bus controller. It will not be NULL for a bus driver
131 that wishes to retrieve the name of a child controller.
132 Language - A pointer to a three character ISO 639-2 language
133 identifier. This is the language of the controller name
134 that that the caller is requesting, and it must match one
135 of the languages specified in SupportedLanguages. The
136 number of languages supported by a driver is up to the
137 driver writer.
138 ControllerName - A pointer to the Unicode string to return. This Unicode
139 string is the name of the controller specified by
140 ControllerHandle and ChildHandle in the language
141 specified by Language from the point of view of the
142 driver specified by This.
143
144 Returns:
145 EFI_SUCCESS - The Unicode string for the user readable name in the
146 language specified by Language for the driver
147 specified by This was returned in DriverName.
148 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
149 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
150 EFI_HANDLE.
151 EFI_INVALID_PARAMETER - Language is NULL.
152 EFI_INVALID_PARAMETER - ControllerName is NULL.
153 EFI_UNSUPPORTED - The driver specified by This is not currently
154 managing the controller specified by
155 ControllerHandle and ChildHandle.
156 EFI_UNSUPPORTED - The driver specified by This does not support the
157 language specified by Language.
158
159 --*/
160 {
161 EFI_STATUS Status;
162 EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOutput;
163 TERMINAL_DEV *TerminalDevice;
164
165 //
166 // Make sure this driver is currently managing ControllHandle
167 //
168 Status = EfiTestManagedDevice (
169 ControllerHandle,
170 gTerminalDriverBinding.DriverBindingHandle,
171 &gEfiSerialIoProtocolGuid
172 );
173 if (EFI_ERROR (Status)) {
174 return Status;
175 }
176
177 //
178 // This is a bus driver, so ChildHandle can not be NULL.
179 //
180 if (ChildHandle == NULL) {
181 return EFI_UNSUPPORTED;
182 }
183
184 Status = EfiTestChildHandle (
185 ControllerHandle,
186 ChildHandle,
187 &gEfiSerialIoProtocolGuid
188 );
189 if (EFI_ERROR (Status)) {
190 return Status;
191 }
192
193 //
194 // Get our context back
195 //
196 Status = gBS->OpenProtocol (
197 ChildHandle,
198 &gEfiSimpleTextOutProtocolGuid,
199 (VOID **) &SimpleTextOutput,
200 gTerminalDriverBinding.DriverBindingHandle,
201 ChildHandle,
202 EFI_OPEN_PROTOCOL_GET_PROTOCOL
203 );
204 if (EFI_ERROR (Status)) {
205 return EFI_UNSUPPORTED;
206 }
207
208 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);
209
210 return LookupUnicodeString (
211 Language,
212 gTerminalComponentName.SupportedLanguages,
213 TerminalDevice->ControllerNameTable,
214 ControllerName
215 );
216 }