2 Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // EFI Component Name Functions
15 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
17 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
18 @param Language A pointer to a three-character ISO 639-2 language identifier.
19 This is the language of the driver name that that the caller
20 is requesting, and it must match one of the languages specified
21 in SupportedLanguages. The number of languages supported by a
22 driver is up to the driver writer.
23 @param DriverName A pointer to the Unicode string to return. This Unicode string
24 is the name of the driver specified by This in the language
25 specified by Language.
27 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
28 and the language specified by Language was returned
30 @retval EFI_INVALID_PARAMETER Language is NULL.
31 @retval EFI_INVALID_PARAMETER DriverName is NULL.
32 @retval EFI_UNSUPPORTED The driver specified by This does not support the
33 language specified by Language.
38 DnsComponentNameGetDriverName (
39 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
41 OUT CHAR16
**DriverName
45 Retrieves a Unicode string that is the user readable name of the controller
46 that is being managed by an EFI Driver.
48 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
49 @param ControllerHandle The handle of a controller that the driver specified by
50 This is managing. This handle specifies the controller
51 whose name is to be returned.
52 @param ChildHandle The handle of the child controller to retrieve the name
53 of. This is an optional parameter that may be NULL. It
54 will be NULL for device drivers. It will also be NULL
55 for a bus drivers that wish to retrieve the name of the
56 bus controller. It will not be NULL for a bus driver
57 that wishes to retrieve the name of a child controller.
58 @param Language A pointer to a three character ISO 639-2 language
59 identifier. This is the language of the controller name
60 that the caller is requesting, and it must match one
61 of the languages specified in SupportedLanguages. The
62 number of languages supported by a driver is up to the
64 @param ControllerName A pointer to the Unicode string to return. This Unicode
65 string is the name of the controller specified by
66 ControllerHandle and ChildHandle in the language specified
67 by Language, from the point of view of the driver specified
70 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
71 language specified by Language for the driver
72 specified by This was returned in DriverName.
73 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
74 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
75 @retval EFI_INVALID_PARAMETER Language is NULL.
76 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
77 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
78 the controller specified by ControllerHandle and
80 @retval EFI_UNSUPPORTED The driver specified by This does not support the
81 language specified by Language.
86 DnsComponentNameGetControllerName (
87 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
88 IN EFI_HANDLE ControllerHandle
,
89 IN EFI_HANDLE ChildHandle OPTIONAL
,
91 OUT CHAR16
**ControllerName
96 /// Component Name Protocol instance
98 GLOBAL_REMOVE_IF_UNREFERENCED
99 EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName
= {
100 DnsComponentNameGetDriverName
,
101 DnsComponentNameGetControllerName
,
106 /// Component Name 2 Protocol instance
108 GLOBAL_REMOVE_IF_UNREFERENCED
109 EFI_COMPONENT_NAME2_PROTOCOL gDnsComponentName2
= {
110 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME
) DnsComponentNameGetDriverName
,
111 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME
) DnsComponentNameGetControllerName
,
116 /// Table of driver names
118 GLOBAL_REMOVE_IF_UNREFERENCED
119 EFI_UNICODE_STRING_TABLE mDnsDriverNameTable
[] = {
120 { "eng;en", (CHAR16
*)L
"DNS Network Service Driver" },
124 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
*gDnsControllerNameTable
= NULL
;
127 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
129 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
130 @param Language A pointer to a three-character ISO 639-2 language identifier.
131 This is the language of the driver name that that the caller
132 is requesting, and it must match one of the languages specified
133 in SupportedLanguages. The number of languages supported by a
134 driver is up to the driver writer.
135 @param DriverName A pointer to the Unicode string to return. This Unicode string
136 is the name of the driver specified by This in the language
137 specified by Language.
139 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
140 and the language specified by Language was returned
142 @retval EFI_INVALID_PARAMETER Language is NULL.
143 @retval EFI_INVALID_PARAMETER DriverName is NULL.
144 @retval EFI_UNSUPPORTED The driver specified by This does not support the
145 language specified by Language.
150 DnsComponentNameGetDriverName (
151 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
153 OUT CHAR16
**DriverName
156 return LookupUnicodeString2 (
158 This
->SupportedLanguages
,
161 (BOOLEAN
)(This
== &gDnsComponentName
)
166 Update the component name for the Dns4 child handle.
168 @param Dns4 A pointer to the EFI_DNS4_PROTOCOL.
171 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
172 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
177 EFI_DNS4_PROTOCOL
*Dns4
181 CHAR16 HandleName
[80];
182 EFI_DNS4_MODE_DATA ModeData
;
185 return EFI_INVALID_PARAMETER
;
189 // Format the child name into the string buffer as:
190 // DNSv4 (StationIp=?, LocalPort=?)
192 Status
= Dns4
->GetModeData (Dns4
, &ModeData
);
193 if (EFI_ERROR (Status
)) {
200 L
"DNSv4 (StationIp=%d.%d.%d.%d, LocalPort=%d)",
201 ModeData
.DnsConfigData
.StationIp
.Addr
[0],
202 ModeData
.DnsConfigData
.StationIp
.Addr
[1],
203 ModeData
.DnsConfigData
.StationIp
.Addr
[2],
204 ModeData
.DnsConfigData
.StationIp
.Addr
[3],
205 ModeData
.DnsConfigData
.LocalPort
208 if (ModeData
.DnsCacheList
!= NULL
) {
209 FreePool (ModeData
.DnsCacheList
);
211 if (ModeData
.DnsServerList
!= NULL
) {
212 FreePool (ModeData
.DnsServerList
);
215 if (gDnsControllerNameTable
!= NULL
) {
216 FreeUnicodeStringTable (gDnsControllerNameTable
);
217 gDnsControllerNameTable
= NULL
;
220 Status
= AddUnicodeString2 (
222 gDnsComponentName
.SupportedLanguages
,
223 &gDnsControllerNameTable
,
227 if (EFI_ERROR (Status
)) {
231 return AddUnicodeString2 (
233 gDnsComponentName2
.SupportedLanguages
,
234 &gDnsControllerNameTable
,
241 Update the component name for the Dns6 child handle.
243 @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.
246 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
247 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
252 EFI_DNS6_PROTOCOL
*Dns6
256 CHAR16 HandleName
[128];
257 EFI_DNS6_MODE_DATA ModeData
;
258 CHAR16 Address
[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
261 return EFI_INVALID_PARAMETER
;
265 // Format the child name into the string buffer as:
266 // DNSv6 (StationIp=?, LocalPort=?)
268 Status
= Dns6
->GetModeData (Dns6
, &ModeData
);
269 if (EFI_ERROR (Status
)) {
273 Status
= NetLibIp6ToStr (&ModeData
.DnsConfigData
.StationIp
, Address
, sizeof (Address
));
274 if (EFI_ERROR (Status
)) {
280 L
"DNSv6 (StationIp=%s, LocalPort=%d)",
282 ModeData
.DnsConfigData
.LocalPort
285 if (ModeData
.DnsCacheList
!= NULL
) {
286 FreePool (ModeData
.DnsCacheList
);
288 if (ModeData
.DnsServerList
!= NULL
) {
289 FreePool (ModeData
.DnsServerList
);
292 if (gDnsControllerNameTable
!= NULL
) {
293 FreeUnicodeStringTable (gDnsControllerNameTable
);
294 gDnsControllerNameTable
= NULL
;
297 Status
= AddUnicodeString2 (
299 gDnsComponentName
.SupportedLanguages
,
300 &gDnsControllerNameTable
,
304 if (EFI_ERROR (Status
)) {
308 return AddUnicodeString2 (
310 gDnsComponentName2
.SupportedLanguages
,
311 &gDnsControllerNameTable
,
318 Retrieves a Unicode string that is the user readable name of the controller
319 that is being managed by an EFI Driver.
321 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
322 @param ControllerHandle The handle of a controller that the driver specified by
323 This is managing. This handle specifies the controller
324 whose name is to be returned.
325 @param ChildHandle The handle of the child controller to retrieve the name
326 of. This is an optional parameter that may be NULL. It
327 will be NULL for device drivers. It will also be NULL
328 for a bus drivers that wish to retrieve the name of the
329 bus controller. It will not be NULL for a bus driver
330 that wishes to retrieve the name of a child controller.
331 @param Language A pointer to a three character ISO 639-2 language
332 identifier. This is the language of the controller name
333 that the caller is requesting, and it must match one
334 of the languages specified in SupportedLanguages. The
335 number of languages supported by a driver is up to the
337 @param ControllerName A pointer to the Unicode string to return. This Unicode
338 string is the name of the controller specified by
339 ControllerHandle and ChildHandle in the language specified
340 by Language, from the point of view of the driver specified
343 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
344 language specified by Language for the driver
345 specified by This was returned in DriverName.
346 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
347 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
348 @retval EFI_INVALID_PARAMETER Language is NULL.
349 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
350 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
351 the controller specified by ControllerHandle and
353 @retval EFI_UNSUPPORTED The driver specified by This does not support the
354 language specified by Language.
359 DnsComponentNameGetControllerName (
360 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
361 IN EFI_HANDLE ControllerHandle
,
362 IN EFI_HANDLE ChildHandle OPTIONAL
,
364 OUT CHAR16
**ControllerName
368 EFI_DNS4_PROTOCOL
*Dns4
;
369 EFI_DNS6_PROTOCOL
*Dns6
;
372 // ChildHandle must be NULL for a Device Driver
374 if (ChildHandle
== NULL
) {
375 return EFI_UNSUPPORTED
;
379 // Make sure this driver produced ChildHandle
381 Status
= EfiTestChildHandle (
384 &gEfiUdp6ProtocolGuid
386 if (!EFI_ERROR (Status
)) {
388 // Retrieve an instance of a produced protocol from ChildHandle
390 Status
= gBS
->OpenProtocol (
392 &gEfiDns6ProtocolGuid
,
396 EFI_OPEN_PROTOCOL_GET_PROTOCOL
398 if (EFI_ERROR (Status
)) {
403 // Update the component name for this child handle.
405 Status
= UpdateDns6Name (Dns6
);
406 if (EFI_ERROR (Status
)) {
412 // Make sure this driver produced ChildHandle
414 Status
= EfiTestChildHandle (
417 &gEfiUdp4ProtocolGuid
419 if (!EFI_ERROR (Status
)) {
421 // Retrieve an instance of a produced protocol from ChildHandle
423 Status
= gBS
->OpenProtocol (
425 &gEfiDns4ProtocolGuid
,
429 EFI_OPEN_PROTOCOL_GET_PROTOCOL
431 if (EFI_ERROR (Status
)) {
436 // Update the component name for this child handle.
438 Status
= UpdateDns4Name (Dns4
);
439 if (EFI_ERROR (Status
)) {
444 return LookupUnicodeString2 (
446 This
->SupportedLanguages
,
447 gDnsControllerNameTable
,
449 (BOOLEAN
)(This
== &gDnsComponentName
)