2 Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
4 Copyright (c) 2016, 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 (ModeData
.DnsCacheList
!= NULL
) {
215 FreePool (ModeData
.DnsCacheList
);
217 if (ModeData
.DnsServerList
!= NULL
) {
218 FreePool (ModeData
.DnsServerList
);
221 if (gDnsControllerNameTable
!= NULL
) {
222 FreeUnicodeStringTable (gDnsControllerNameTable
);
223 gDnsControllerNameTable
= NULL
;
226 Status
= AddUnicodeString2 (
228 gDnsComponentName
.SupportedLanguages
,
229 &gDnsControllerNameTable
,
233 if (EFI_ERROR (Status
)) {
237 return AddUnicodeString2 (
239 gDnsComponentName2
.SupportedLanguages
,
240 &gDnsControllerNameTable
,
247 Update the component name for the Dns6 child handle.
249 @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.
252 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
253 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
258 EFI_DNS6_PROTOCOL
*Dns6
262 CHAR16 HandleName
[128];
263 EFI_DNS6_MODE_DATA ModeData
;
264 CHAR16 Address
[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
267 return EFI_INVALID_PARAMETER
;
271 // Format the child name into the string buffer as:
272 // DNSv6 (StationIp=?, LocalPort=?)
274 Status
= Dns6
->GetModeData (Dns6
, &ModeData
);
275 if (EFI_ERROR (Status
)) {
279 Status
= NetLibIp6ToStr (&ModeData
.DnsConfigData
.StationIp
, Address
, sizeof (Address
));
280 if (EFI_ERROR (Status
)) {
286 L
"DNSv6 (StationIp=%s, LocalPort=%d)",
288 ModeData
.DnsConfigData
.LocalPort
291 if (ModeData
.DnsCacheList
!= NULL
) {
292 FreePool (ModeData
.DnsCacheList
);
294 if (ModeData
.DnsServerList
!= NULL
) {
295 FreePool (ModeData
.DnsServerList
);
298 if (gDnsControllerNameTable
!= NULL
) {
299 FreeUnicodeStringTable (gDnsControllerNameTable
);
300 gDnsControllerNameTable
= NULL
;
303 Status
= AddUnicodeString2 (
305 gDnsComponentName
.SupportedLanguages
,
306 &gDnsControllerNameTable
,
310 if (EFI_ERROR (Status
)) {
314 return AddUnicodeString2 (
316 gDnsComponentName2
.SupportedLanguages
,
317 &gDnsControllerNameTable
,
324 Retrieves a Unicode string that is the user readable name of the controller
325 that is being managed by an EFI Driver.
327 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
328 @param ControllerHandle The handle of a controller that the driver specified by
329 This is managing. This handle specifies the controller
330 whose name is to be returned.
331 @param ChildHandle The handle of the child controller to retrieve the name
332 of. This is an optional parameter that may be NULL. It
333 will be NULL for device drivers. It will also be NULL
334 for a bus drivers that wish to retrieve the name of the
335 bus controller. It will not be NULL for a bus driver
336 that wishes to retrieve the name of a child controller.
337 @param Language A pointer to a three character ISO 639-2 language
338 identifier. This is the language of the controller name
339 that the caller is requesting, and it must match one
340 of the languages specified in SupportedLanguages. The
341 number of languages supported by a driver is up to the
343 @param ControllerName A pointer to the Unicode string to return. This Unicode
344 string is the name of the controller specified by
345 ControllerHandle and ChildHandle in the language specified
346 by Language, from the point of view of the driver specified
349 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
350 language specified by Language for the driver
351 specified by This was returned in DriverName.
352 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
353 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
354 @retval EFI_INVALID_PARAMETER Language is NULL.
355 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
356 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
357 the controller specified by ControllerHandle and
359 @retval EFI_UNSUPPORTED The driver specified by This does not support the
360 language specified by Language.
365 DnsComponentNameGetControllerName (
366 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
367 IN EFI_HANDLE ControllerHandle
,
368 IN EFI_HANDLE ChildHandle OPTIONAL
,
370 OUT CHAR16
**ControllerName
374 EFI_DNS4_PROTOCOL
*Dns4
;
375 EFI_DNS6_PROTOCOL
*Dns6
;
378 // ChildHandle must be NULL for a Device Driver
380 if (ChildHandle
== NULL
) {
381 return EFI_UNSUPPORTED
;
385 // Make sure this driver produced ChildHandle
387 Status
= EfiTestChildHandle (
390 &gEfiUdp6ProtocolGuid
392 if (!EFI_ERROR (Status
)) {
394 // Retrieve an instance of a produced protocol from ChildHandle
396 Status
= gBS
->OpenProtocol (
398 &gEfiDns6ProtocolGuid
,
402 EFI_OPEN_PROTOCOL_GET_PROTOCOL
404 if (EFI_ERROR (Status
)) {
409 // Update the component name for this child handle.
411 Status
= UpdateDns6Name (Dns6
);
412 if (EFI_ERROR (Status
)) {
418 // Make sure this driver produced ChildHandle
420 Status
= EfiTestChildHandle (
423 &gEfiUdp4ProtocolGuid
425 if (!EFI_ERROR (Status
)) {
427 // Retrieve an instance of a produced protocol from ChildHandle
429 Status
= gBS
->OpenProtocol (
431 &gEfiDns4ProtocolGuid
,
435 EFI_OPEN_PROTOCOL_GET_PROTOCOL
437 if (EFI_ERROR (Status
)) {
442 // Update the component name for this child handle.
444 Status
= UpdateDns4Name (Dns4
);
445 if (EFI_ERROR (Status
)) {
450 return LookupUnicodeString2 (
452 This
->SupportedLanguages
,
453 gDnsControllerNameTable
,
455 (BOOLEAN
)(This
== &gDnsComponentName
)