]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/DnsDxe/ComponentName.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / DnsDxe / ComponentName.c
1 /** @file
2 Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
3
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "DnsImpl.h"
10
11 //
12 // EFI Component Name Functions
13 //
14
15 /**
16 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
17
18 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
19 @param Language A pointer to a three-character ISO 639-2 language identifier.
20 This is the language of the driver name that that the caller
21 is requesting, and it must match one of the languages specified
22 in SupportedLanguages. The number of languages supported by a
23 driver is up to the driver writer.
24 @param DriverName A pointer to the Unicode string to return. This Unicode string
25 is the name of the driver specified by This in the language
26 specified by Language.
27
28 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
29 and the language specified by Language was returned
30 in DriverName.
31 @retval EFI_INVALID_PARAMETER Language is NULL.
32 @retval EFI_INVALID_PARAMETER DriverName is NULL.
33 @retval EFI_UNSUPPORTED The driver specified by This does not support the
34 language specified by Language.
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 DnsComponentNameGetDriverName (
40 IN EFI_COMPONENT_NAME_PROTOCOL *This,
41 IN CHAR8 *Language,
42 OUT CHAR16 **DriverName
43 );
44
45 /**
46 Retrieves a Unicode string that is the user readable name of the controller
47 that is being managed by an EFI Driver.
48
49 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
50 @param ControllerHandle The handle of a controller that the driver specified by
51 This is managing. This handle specifies the controller
52 whose name is to be returned.
53 @param ChildHandle The handle of the child controller to retrieve the name
54 of. This is an optional parameter that may be NULL. It
55 will be NULL for device drivers. It will also be NULL
56 for a bus drivers that wish to retrieve the name of the
57 bus controller. It will not be NULL for a bus driver
58 that wishes to retrieve the name of a child controller.
59 @param Language A pointer to a three character ISO 639-2 language
60 identifier. This is the language of the controller name
61 that the caller is requesting, and it must match one
62 of the languages specified in SupportedLanguages. The
63 number of languages supported by a driver is up to the
64 driver writer.
65 @param ControllerName A pointer to the Unicode string to return. This Unicode
66 string is the name of the controller specified by
67 ControllerHandle and ChildHandle in the language specified
68 by Language, from the point of view of the driver specified
69 by This.
70
71 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
72 language specified by Language for the driver
73 specified by This was returned in DriverName.
74 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
75 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
76 @retval EFI_INVALID_PARAMETER Language is NULL.
77 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
78 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
79 the controller specified by ControllerHandle and
80 ChildHandle.
81 @retval EFI_UNSUPPORTED The driver specified by This does not support the
82 language specified by Language.
83
84 **/
85 EFI_STATUS
86 EFIAPI
87 DnsComponentNameGetControllerName (
88 IN EFI_COMPONENT_NAME_PROTOCOL *This,
89 IN EFI_HANDLE ControllerHandle,
90 IN EFI_HANDLE ChildHandle OPTIONAL,
91 IN CHAR8 *Language,
92 OUT CHAR16 **ControllerName
93 );
94
95 ///
96 /// Component Name Protocol instance
97 ///
98 GLOBAL_REMOVE_IF_UNREFERENCED
99 EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName = {
100 DnsComponentNameGetDriverName,
101 DnsComponentNameGetControllerName,
102 "eng"
103 };
104
105 ///
106 /// Component Name 2 Protocol instance
107 ///
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,
112 "en"
113 };
114
115 ///
116 /// Table of driver names
117 ///
118 GLOBAL_REMOVE_IF_UNREFERENCED
119 EFI_UNICODE_STRING_TABLE mDnsDriverNameTable[] = {
120 { "eng;en", (CHAR16 *)L"DNS Network Service Driver" },
121 { NULL, NULL }
122 };
123
124 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDnsControllerNameTable = NULL;
125
126 /**
127 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
128
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.
138
139 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
140 and the language specified by Language was returned
141 in DriverName.
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.
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 DnsComponentNameGetDriverName (
151 IN EFI_COMPONENT_NAME_PROTOCOL *This,
152 IN CHAR8 *Language,
153 OUT CHAR16 **DriverName
154 )
155 {
156 return LookupUnicodeString2 (
157 Language,
158 This->SupportedLanguages,
159 mDnsDriverNameTable,
160 DriverName,
161 (BOOLEAN)(This == &gDnsComponentName)
162 );
163 }
164
165 /**
166 Update the component name for the Dns4 child handle.
167
168 @param Dns4 A pointer to the EFI_DNS4_PROTOCOL.
169
170
171 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
172 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
173
174 **/
175 EFI_STATUS
176 UpdateDns4Name (
177 EFI_DNS4_PROTOCOL *Dns4
178 )
179 {
180 EFI_STATUS Status;
181 CHAR16 HandleName[80];
182 EFI_DNS4_MODE_DATA ModeData;
183
184 if (Dns4 == NULL) {
185 return EFI_INVALID_PARAMETER;
186 }
187
188 //
189 // Format the child name into the string buffer as:
190 // DNSv4 (StationIp=?, LocalPort=?)
191 //
192 Status = Dns4->GetModeData (Dns4, &ModeData);
193 if (EFI_ERROR (Status)) {
194 return Status;
195 }
196
197 UnicodeSPrint (
198 HandleName,
199 sizeof (HandleName),
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
206 );
207
208 if (ModeData.DnsCacheList != NULL) {
209 FreePool (ModeData.DnsCacheList);
210 }
211
212 if (ModeData.DnsServerList != NULL) {
213 FreePool (ModeData.DnsServerList);
214 }
215
216 if (gDnsControllerNameTable != NULL) {
217 FreeUnicodeStringTable (gDnsControllerNameTable);
218 gDnsControllerNameTable = NULL;
219 }
220
221 Status = AddUnicodeString2 (
222 "eng",
223 gDnsComponentName.SupportedLanguages,
224 &gDnsControllerNameTable,
225 HandleName,
226 TRUE
227 );
228 if (EFI_ERROR (Status)) {
229 return Status;
230 }
231
232 return AddUnicodeString2 (
233 "en",
234 gDnsComponentName2.SupportedLanguages,
235 &gDnsControllerNameTable,
236 HandleName,
237 FALSE
238 );
239 }
240
241 /**
242 Update the component name for the Dns6 child handle.
243
244 @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.
245
246
247 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
248 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
249
250 **/
251 EFI_STATUS
252 UpdateDns6Name (
253 EFI_DNS6_PROTOCOL *Dns6
254 )
255 {
256 EFI_STATUS Status;
257 CHAR16 HandleName[128];
258 EFI_DNS6_MODE_DATA ModeData;
259 CHAR16 Address[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
260
261 if (Dns6 == NULL) {
262 return EFI_INVALID_PARAMETER;
263 }
264
265 //
266 // Format the child name into the string buffer as:
267 // DNSv6 (StationIp=?, LocalPort=?)
268 //
269 Status = Dns6->GetModeData (Dns6, &ModeData);
270 if (EFI_ERROR (Status)) {
271 return Status;
272 }
273
274 Status = NetLibIp6ToStr (&ModeData.DnsConfigData.StationIp, Address, sizeof (Address));
275 if (EFI_ERROR (Status)) {
276 return Status;
277 }
278
279 UnicodeSPrint (
280 HandleName,
281 sizeof (HandleName),
282 L"DNSv6 (StationIp=%s, LocalPort=%d)",
283 Address,
284 ModeData.DnsConfigData.LocalPort
285 );
286
287 if (ModeData.DnsCacheList != NULL) {
288 FreePool (ModeData.DnsCacheList);
289 }
290
291 if (ModeData.DnsServerList != NULL) {
292 FreePool (ModeData.DnsServerList);
293 }
294
295 if (gDnsControllerNameTable != NULL) {
296 FreeUnicodeStringTable (gDnsControllerNameTable);
297 gDnsControllerNameTable = NULL;
298 }
299
300 Status = AddUnicodeString2 (
301 "eng",
302 gDnsComponentName.SupportedLanguages,
303 &gDnsControllerNameTable,
304 HandleName,
305 TRUE
306 );
307 if (EFI_ERROR (Status)) {
308 return Status;
309 }
310
311 return AddUnicodeString2 (
312 "en",
313 gDnsComponentName2.SupportedLanguages,
314 &gDnsControllerNameTable,
315 HandleName,
316 FALSE
317 );
318 }
319
320 /**
321 Retrieves a Unicode string that is the user readable name of the controller
322 that is being managed by an EFI Driver.
323
324 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
325 @param ControllerHandle The handle of a controller that the driver specified by
326 This is managing. This handle specifies the controller
327 whose name is to be returned.
328 @param ChildHandle The handle of the child controller to retrieve the name
329 of. This is an optional parameter that may be NULL. It
330 will be NULL for device drivers. It will also be NULL
331 for a bus drivers that wish to retrieve the name of the
332 bus controller. It will not be NULL for a bus driver
333 that wishes to retrieve the name of a child controller.
334 @param Language A pointer to a three character ISO 639-2 language
335 identifier. This is the language of the controller name
336 that the caller is requesting, and it must match one
337 of the languages specified in SupportedLanguages. The
338 number of languages supported by a driver is up to the
339 driver writer.
340 @param ControllerName A pointer to the Unicode string to return. This Unicode
341 string is the name of the controller specified by
342 ControllerHandle and ChildHandle in the language specified
343 by Language, from the point of view of the driver specified
344 by This.
345
346 @retval EFI_SUCCESS The Unicode string for the user-readable name in the
347 language specified by Language for the driver
348 specified by This was returned in DriverName.
349 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
350 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
351 @retval EFI_INVALID_PARAMETER Language is NULL.
352 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
353 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
354 the controller specified by ControllerHandle and
355 ChildHandle.
356 @retval EFI_UNSUPPORTED The driver specified by This does not support the
357 language specified by Language.
358
359 **/
360 EFI_STATUS
361 EFIAPI
362 DnsComponentNameGetControllerName (
363 IN EFI_COMPONENT_NAME_PROTOCOL *This,
364 IN EFI_HANDLE ControllerHandle,
365 IN EFI_HANDLE ChildHandle OPTIONAL,
366 IN CHAR8 *Language,
367 OUT CHAR16 **ControllerName
368 )
369 {
370 EFI_STATUS Status;
371 EFI_DNS4_PROTOCOL *Dns4;
372 EFI_DNS6_PROTOCOL *Dns6;
373
374 //
375 // ChildHandle must be NULL for a Device Driver
376 //
377 if (ChildHandle == NULL) {
378 return EFI_UNSUPPORTED;
379 }
380
381 //
382 // Make sure this driver produced ChildHandle
383 //
384 Status = EfiTestChildHandle (
385 ControllerHandle,
386 ChildHandle,
387 &gEfiUdp6ProtocolGuid
388 );
389 if (!EFI_ERROR (Status)) {
390 //
391 // Retrieve an instance of a produced protocol from ChildHandle
392 //
393 Status = gBS->OpenProtocol (
394 ChildHandle,
395 &gEfiDns6ProtocolGuid,
396 (VOID **)&Dns6,
397 NULL,
398 NULL,
399 EFI_OPEN_PROTOCOL_GET_PROTOCOL
400 );
401 if (EFI_ERROR (Status)) {
402 return Status;
403 }
404
405 //
406 // Update the component name for this child handle.
407 //
408 Status = UpdateDns6Name (Dns6);
409 if (EFI_ERROR (Status)) {
410 return Status;
411 }
412 }
413
414 //
415 // Make sure this driver produced ChildHandle
416 //
417 Status = EfiTestChildHandle (
418 ControllerHandle,
419 ChildHandle,
420 &gEfiUdp4ProtocolGuid
421 );
422 if (!EFI_ERROR (Status)) {
423 //
424 // Retrieve an instance of a produced protocol from ChildHandle
425 //
426 Status = gBS->OpenProtocol (
427 ChildHandle,
428 &gEfiDns4ProtocolGuid,
429 (VOID **)&Dns4,
430 NULL,
431 NULL,
432 EFI_OPEN_PROTOCOL_GET_PROTOCOL
433 );
434 if (EFI_ERROR (Status)) {
435 return Status;
436 }
437
438 //
439 // Update the component name for this child handle.
440 //
441 Status = UpdateDns4Name (Dns4);
442 if (EFI_ERROR (Status)) {
443 return Status;
444 }
445 }
446
447 return LookupUnicodeString2 (
448 Language,
449 This->SupportedLanguages,
450 gDnsControllerNameTable,
451 ControllerName,
452 (BOOLEAN)(This == &gDnsComponentName)
453 );
454 }