2 Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // EFI Component Name Functions
21 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
23 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
24 @param Language A pointer to a three-character ISO 639-2 language identifier.
25 This is the language of the driver name that that the caller
26 is requesting, and it must match one of the languages specified
27 in SupportedLanguages. The number of languages supported by a
28 driver is up to the driver writer.
29 @param DriverName A pointer to the Unicode string to return. This Unicode string
30 is the name of the driver specified by This in the language
31 specified by Language.
33 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
34 and the language specified by Language was returned
36 @retval EFI_INVALID_PARAMETER Language is NULL.
37 @retval EFI_INVALID_PARAMETER DriverName is NULL.
38 @retval EFI_UNSUPPORTED The driver specified by This does not support the
39 language specified by Language.
44 DnsComponentNameGetDriverName (
45 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
47 OUT CHAR16
**DriverName
51 Retrieves a Unicode string that is the user readable name of the controller
52 that is being managed by an EFI Driver.
54 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
55 @param ControllerHandle The handle of a controller that the driver specified by
56 This is managing. This handle specifies the controller
57 whose name is to be returned.
58 @param ChildHandle The handle of the child controller to retrieve the name
59 of. This is an optional parameter that may be NULL. It
60 will be NULL for device drivers. It will also be NULL
61 for a bus drivers that wish to retrieve the name of the
62 bus controller. It will not be NULL for a bus driver
63 that wishes to retrieve the name of a child controller.
64 @param Language A pointer to a three character ISO 639-2 language
65 identifier. This is the language of the controller name
66 that the caller is requesting, and it must match one
67 of the languages specified in SupportedLanguages. The
68 number of languages supported by a driver is up to the
70 @param ControllerName A pointer to the Unicode string to return. This Unicode
71 string is the name of the controller specified by
72 ControllerHandle and ChildHandle in the language specified
73 by Language, from the point of view of the driver specified
76 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
77 language specified by Language for the driver
78 specified by This was returned in DriverName.
79 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
80 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
81 @retval EFI_INVALID_PARAMETER Language is NULL.
82 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
83 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
84 the controller specified by ControllerHandle and
86 @retval EFI_UNSUPPORTED The driver specified by This does not support the
87 language specified by Language.
92 DnsComponentNameGetControllerName (
93 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
94 IN EFI_HANDLE ControllerHandle
,
95 IN EFI_HANDLE ChildHandle OPTIONAL
,
97 OUT CHAR16
**ControllerName
102 /// Component Name Protocol instance
104 GLOBAL_REMOVE_IF_UNREFERENCED
105 EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName
= {
106 DnsComponentNameGetDriverName
,
107 DnsComponentNameGetControllerName
,
112 /// Component Name 2 Protocol instance
114 GLOBAL_REMOVE_IF_UNREFERENCED
115 EFI_COMPONENT_NAME2_PROTOCOL gDnsComponentName2
= {
116 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME
) DnsComponentNameGetDriverName
,
117 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME
) DnsComponentNameGetControllerName
,
122 /// Table of driver names
124 GLOBAL_REMOVE_IF_UNREFERENCED
125 EFI_UNICODE_STRING_TABLE mDnsDriverNameTable
[] = {
126 { "eng;en", (CHAR16
*)L
"DNS Network Service Driver" },
130 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
*gDnsControllerNameTable
= NULL
;
133 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
135 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
136 @param Language A pointer to a three-character ISO 639-2 language identifier.
137 This is the language of the driver name that that the caller
138 is requesting, and it must match one of the languages specified
139 in SupportedLanguages. The number of languages supported by a
140 driver is up to the driver writer.
141 @param DriverName A pointer to the Unicode string to return. This Unicode string
142 is the name of the driver specified by This in the language
143 specified by Language.
145 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
146 and the language specified by Language was returned
148 @retval EFI_INVALID_PARAMETER Language is NULL.
149 @retval EFI_INVALID_PARAMETER DriverName is NULL.
150 @retval EFI_UNSUPPORTED The driver specified by This does not support the
151 language specified by Language.
156 DnsComponentNameGetDriverName (
157 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
159 OUT CHAR16
**DriverName
162 return LookupUnicodeString2 (
164 This
->SupportedLanguages
,
167 (BOOLEAN
)(This
== &gDnsComponentName
)
172 Update the component name for the Dns4 child handle.
174 @param Dns4 A pointer to the EFI_DNS4_PROTOCOL.
177 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
178 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
183 EFI_DNS4_PROTOCOL
*Dns4
187 CHAR16 HandleName
[80];
188 EFI_DNS4_MODE_DATA ModeData
;
191 return EFI_INVALID_PARAMETER
;
195 // Format the child name into the string buffer as:
196 // DNSv4 (StationIp=?, LocalPort=?)
198 Status
= Dns4
->GetModeData (Dns4
, &ModeData
);
199 if (EFI_ERROR (Status
)) {
206 L
"DNSv4 (StationIp=%d.%d.%d.%d, LocalPort=%d)",
207 ModeData
.DnsConfigData
.StationIp
.Addr
[0],
208 ModeData
.DnsConfigData
.StationIp
.Addr
[1],
209 ModeData
.DnsConfigData
.StationIp
.Addr
[2],
210 ModeData
.DnsConfigData
.StationIp
.Addr
[3],
211 ModeData
.DnsConfigData
.LocalPort
214 if (gDnsControllerNameTable
!= NULL
) {
215 FreeUnicodeStringTable (gDnsControllerNameTable
);
216 gDnsControllerNameTable
= NULL
;
219 Status
= AddUnicodeString2 (
221 gDnsComponentName
.SupportedLanguages
,
222 &gDnsControllerNameTable
,
226 if (EFI_ERROR (Status
)) {
230 return AddUnicodeString2 (
232 gDnsComponentName2
.SupportedLanguages
,
233 &gDnsControllerNameTable
,
240 Update the component name for the Dns6 child handle.
242 @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.
245 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
246 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
251 EFI_DNS6_PROTOCOL
*Dns6
255 CHAR16 HandleName
[128];
256 EFI_DNS6_MODE_DATA ModeData
;
257 CHAR16 Address
[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
260 return EFI_INVALID_PARAMETER
;
264 // Format the child name into the string buffer as:
265 // DNSv6 (StationIp=?, LocalPort=?)
267 Status
= Dns6
->GetModeData (Dns6
, &ModeData
);
268 if (EFI_ERROR (Status
)) {
272 Status
= NetLibIp6ToStr (&ModeData
.DnsConfigData
.StationIp
, Address
, sizeof (Address
));
273 if (EFI_ERROR (Status
)) {
279 L
"DNSv6 (StationIp=%s, LocalPort=%d)",
281 ModeData
.DnsConfigData
.LocalPort
284 if (gDnsControllerNameTable
!= NULL
) {
285 FreeUnicodeStringTable (gDnsControllerNameTable
);
286 gDnsControllerNameTable
= NULL
;
289 Status
= AddUnicodeString2 (
291 gDnsComponentName
.SupportedLanguages
,
292 &gDnsControllerNameTable
,
296 if (EFI_ERROR (Status
)) {
300 return AddUnicodeString2 (
302 gDnsComponentName2
.SupportedLanguages
,
303 &gDnsControllerNameTable
,
310 Retrieves a Unicode string that is the user readable name of the controller
311 that is being managed by an EFI Driver.
313 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
314 @param ControllerHandle The handle of a controller that the driver specified by
315 This is managing. This handle specifies the controller
316 whose name is to be returned.
317 @param ChildHandle The handle of the child controller to retrieve the name
318 of. This is an optional parameter that may be NULL. It
319 will be NULL for device drivers. It will also be NULL
320 for a bus drivers that wish to retrieve the name of the
321 bus controller. It will not be NULL for a bus driver
322 that wishes to retrieve the name of a child controller.
323 @param Language A pointer to a three character ISO 639-2 language
324 identifier. This is the language of the controller name
325 that the caller is requesting, and it must match one
326 of the languages specified in SupportedLanguages. The
327 number of languages supported by a driver is up to the
329 @param ControllerName A pointer to the Unicode string to return. This Unicode
330 string is the name of the controller specified by
331 ControllerHandle and ChildHandle in the language specified
332 by Language, from the point of view of the driver specified
335 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
336 language specified by Language for the driver
337 specified by This was returned in DriverName.
338 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
339 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
340 @retval EFI_INVALID_PARAMETER Language is NULL.
341 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
342 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
343 the controller specified by ControllerHandle and
345 @retval EFI_UNSUPPORTED The driver specified by This does not support the
346 language specified by Language.
351 DnsComponentNameGetControllerName (
352 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
353 IN EFI_HANDLE ControllerHandle
,
354 IN EFI_HANDLE ChildHandle OPTIONAL
,
356 OUT CHAR16
**ControllerName
360 EFI_DNS4_PROTOCOL
*Dns4
;
361 EFI_DNS6_PROTOCOL
*Dns6
;
364 // ChildHandle must be NULL for a Device Driver
366 if (ChildHandle
== NULL
) {
367 return EFI_UNSUPPORTED
;
371 // Make sure this driver produced ChildHandle
373 Status
= EfiTestChildHandle (
376 &gEfiUdp6ProtocolGuid
378 if (!EFI_ERROR (Status
)) {
380 // Retrieve an instance of a produced protocol from ChildHandle
382 Status
= gBS
->OpenProtocol (
384 &gEfiDns6ProtocolGuid
,
388 EFI_OPEN_PROTOCOL_GET_PROTOCOL
390 if (EFI_ERROR (Status
)) {
395 // Update the component name for this child handle.
397 Status
= UpdateDns6Name (Dns6
);
398 if (EFI_ERROR (Status
)) {
404 // Make sure this driver produced ChildHandle
406 Status
= EfiTestChildHandle (
409 &gEfiUdp4ProtocolGuid
411 if (!EFI_ERROR (Status
)) {
413 // Retrieve an instance of a produced protocol from ChildHandle
415 Status
= gBS
->OpenProtocol (
417 &gEfiDns4ProtocolGuid
,
421 EFI_OPEN_PROTOCOL_GET_PROTOCOL
423 if (EFI_ERROR (Status
)) {
428 // Update the component name for this child handle.
430 Status
= UpdateDns4Name (Dns4
);
431 if (EFI_ERROR (Status
)) {
436 return LookupUnicodeString2 (
438 This
->SupportedLanguages
,
439 gDnsControllerNameTable
,
441 (BOOLEAN
)(This
== &gDnsComponentName
)