]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/DnsDxe/ComponentName.c
NetworkPkg: Clean up source files
[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 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
9
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.
12
13 **/
14
15 #include "DnsImpl.h"
16
17 //
18 // EFI Component Name Functions
19 //
20 /**
21 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
22
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.
32
33 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
34 and the language specified by Language was returned
35 in DriverName.
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.
40
41 **/
42 EFI_STATUS
43 EFIAPI
44 DnsComponentNameGetDriverName (
45 IN EFI_COMPONENT_NAME_PROTOCOL *This,
46 IN CHAR8 *Language,
47 OUT CHAR16 **DriverName
48 );
49
50 /**
51 Retrieves a Unicode string that is the user readable name of the controller
52 that is being managed by an EFI Driver.
53
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
69 driver writer.
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
74 by This.
75
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
85 ChildHandle.
86 @retval EFI_UNSUPPORTED The driver specified by This does not support the
87 language specified by Language.
88
89 **/
90 EFI_STATUS
91 EFIAPI
92 DnsComponentNameGetControllerName (
93 IN EFI_COMPONENT_NAME_PROTOCOL *This,
94 IN EFI_HANDLE ControllerHandle,
95 IN EFI_HANDLE ChildHandle OPTIONAL,
96 IN CHAR8 *Language,
97 OUT CHAR16 **ControllerName
98 );
99
100
101 ///
102 /// Component Name Protocol instance
103 ///
104 GLOBAL_REMOVE_IF_UNREFERENCED
105 EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName = {
106 DnsComponentNameGetDriverName,
107 DnsComponentNameGetControllerName,
108 "eng"
109 };
110
111 ///
112 /// Component Name 2 Protocol instance
113 ///
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,
118 "en"
119 };
120
121 ///
122 /// Table of driver names
123 ///
124 GLOBAL_REMOVE_IF_UNREFERENCED
125 EFI_UNICODE_STRING_TABLE mDnsDriverNameTable[] = {
126 { "eng;en", (CHAR16 *)L"DNS Network Service Driver" },
127 { NULL, NULL }
128 };
129
130 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDnsControllerNameTable = NULL;
131
132 /**
133 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
134
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.
144
145 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
146 and the language specified by Language was returned
147 in DriverName.
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.
152
153 **/
154 EFI_STATUS
155 EFIAPI
156 DnsComponentNameGetDriverName (
157 IN EFI_COMPONENT_NAME_PROTOCOL *This,
158 IN CHAR8 *Language,
159 OUT CHAR16 **DriverName
160 )
161 {
162 return LookupUnicodeString2 (
163 Language,
164 This->SupportedLanguages,
165 mDnsDriverNameTable,
166 DriverName,
167 (BOOLEAN)(This == &gDnsComponentName)
168 );
169 }
170
171 /**
172 Update the component name for the Dns4 child handle.
173
174 @param Dns4 A pointer to the EFI_DNS4_PROTOCOL.
175
176
177 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
178 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
179
180 **/
181 EFI_STATUS
182 UpdateDns4Name (
183 EFI_DNS4_PROTOCOL *Dns4
184 )
185 {
186 EFI_STATUS Status;
187 CHAR16 HandleName[80];
188 EFI_DNS4_MODE_DATA ModeData;
189
190 if (Dns4 == NULL) {
191 return EFI_INVALID_PARAMETER;
192 }
193
194 //
195 // Format the child name into the string buffer as:
196 // DNSv4 (StationIp=?, LocalPort=?)
197 //
198 Status = Dns4->GetModeData (Dns4, &ModeData);
199 if (EFI_ERROR (Status)) {
200 return Status;
201 }
202
203 UnicodeSPrint (
204 HandleName,
205 sizeof (HandleName),
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
212 );
213
214 if (ModeData.DnsCacheList != NULL) {
215 FreePool (ModeData.DnsCacheList);
216 }
217 if (ModeData.DnsServerList != NULL) {
218 FreePool (ModeData.DnsServerList);
219 }
220
221 if (gDnsControllerNameTable != NULL) {
222 FreeUnicodeStringTable (gDnsControllerNameTable);
223 gDnsControllerNameTable = NULL;
224 }
225
226 Status = AddUnicodeString2 (
227 "eng",
228 gDnsComponentName.SupportedLanguages,
229 &gDnsControllerNameTable,
230 HandleName,
231 TRUE
232 );
233 if (EFI_ERROR (Status)) {
234 return Status;
235 }
236
237 return AddUnicodeString2 (
238 "en",
239 gDnsComponentName2.SupportedLanguages,
240 &gDnsControllerNameTable,
241 HandleName,
242 FALSE
243 );
244 }
245
246 /**
247 Update the component name for the Dns6 child handle.
248
249 @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.
250
251
252 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
253 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
254
255 **/
256 EFI_STATUS
257 UpdateDns6Name (
258 EFI_DNS6_PROTOCOL *Dns6
259 )
260 {
261 EFI_STATUS Status;
262 CHAR16 HandleName[128];
263 EFI_DNS6_MODE_DATA ModeData;
264 CHAR16 Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
265
266 if (Dns6 == NULL) {
267 return EFI_INVALID_PARAMETER;
268 }
269
270 //
271 // Format the child name into the string buffer as:
272 // DNSv6 (StationIp=?, LocalPort=?)
273 //
274 Status = Dns6->GetModeData (Dns6, &ModeData);
275 if (EFI_ERROR (Status)) {
276 return Status;
277 }
278
279 Status = NetLibIp6ToStr (&ModeData.DnsConfigData.StationIp, Address, sizeof (Address));
280 if (EFI_ERROR (Status)) {
281 return Status;
282 }
283 UnicodeSPrint (
284 HandleName,
285 sizeof (HandleName),
286 L"DNSv6 (StationIp=%s, LocalPort=%d)",
287 Address,
288 ModeData.DnsConfigData.LocalPort
289 );
290
291 if (ModeData.DnsCacheList != NULL) {
292 FreePool (ModeData.DnsCacheList);
293 }
294 if (ModeData.DnsServerList != NULL) {
295 FreePool (ModeData.DnsServerList);
296 }
297
298 if (gDnsControllerNameTable != NULL) {
299 FreeUnicodeStringTable (gDnsControllerNameTable);
300 gDnsControllerNameTable = NULL;
301 }
302
303 Status = AddUnicodeString2 (
304 "eng",
305 gDnsComponentName.SupportedLanguages,
306 &gDnsControllerNameTable,
307 HandleName,
308 TRUE
309 );
310 if (EFI_ERROR (Status)) {
311 return Status;
312 }
313
314 return AddUnicodeString2 (
315 "en",
316 gDnsComponentName2.SupportedLanguages,
317 &gDnsControllerNameTable,
318 HandleName,
319 FALSE
320 );
321 }
322
323 /**
324 Retrieves a Unicode string that is the user readable name of the controller
325 that is being managed by an EFI Driver.
326
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
342 driver writer.
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
347 by This.
348
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
358 ChildHandle.
359 @retval EFI_UNSUPPORTED The driver specified by This does not support the
360 language specified by Language.
361
362 **/
363 EFI_STATUS
364 EFIAPI
365 DnsComponentNameGetControllerName (
366 IN EFI_COMPONENT_NAME_PROTOCOL *This,
367 IN EFI_HANDLE ControllerHandle,
368 IN EFI_HANDLE ChildHandle OPTIONAL,
369 IN CHAR8 *Language,
370 OUT CHAR16 **ControllerName
371 )
372 {
373 EFI_STATUS Status;
374 EFI_DNS4_PROTOCOL *Dns4;
375 EFI_DNS6_PROTOCOL *Dns6;
376
377 //
378 // ChildHandle must be NULL for a Device Driver
379 //
380 if (ChildHandle == NULL) {
381 return EFI_UNSUPPORTED;
382 }
383
384 //
385 // Make sure this driver produced ChildHandle
386 //
387 Status = EfiTestChildHandle (
388 ControllerHandle,
389 ChildHandle,
390 &gEfiUdp6ProtocolGuid
391 );
392 if (!EFI_ERROR (Status)) {
393 //
394 // Retrieve an instance of a produced protocol from ChildHandle
395 //
396 Status = gBS->OpenProtocol (
397 ChildHandle,
398 &gEfiDns6ProtocolGuid,
399 (VOID **)&Dns6,
400 NULL,
401 NULL,
402 EFI_OPEN_PROTOCOL_GET_PROTOCOL
403 );
404 if (EFI_ERROR (Status)) {
405 return Status;
406 }
407
408 //
409 // Update the component name for this child handle.
410 //
411 Status = UpdateDns6Name (Dns6);
412 if (EFI_ERROR (Status)) {
413 return Status;
414 }
415 }
416
417 //
418 // Make sure this driver produced ChildHandle
419 //
420 Status = EfiTestChildHandle (
421 ControllerHandle,
422 ChildHandle,
423 &gEfiUdp4ProtocolGuid
424 );
425 if (!EFI_ERROR (Status)) {
426 //
427 // Retrieve an instance of a produced protocol from ChildHandle
428 //
429 Status = gBS->OpenProtocol (
430 ChildHandle,
431 &gEfiDns4ProtocolGuid,
432 (VOID **)&Dns4,
433 NULL,
434 NULL,
435 EFI_OPEN_PROTOCOL_GET_PROTOCOL
436 );
437 if (EFI_ERROR (Status)) {
438 return Status;
439 }
440
441 //
442 // Update the component name for this child handle.
443 //
444 Status = UpdateDns4Name (Dns4);
445 if (EFI_ERROR (Status)) {
446 return Status;
447 }
448 }
449
450 return LookupUnicodeString2 (
451 Language,
452 This->SupportedLanguages,
453 gDnsControllerNameTable,
454 ControllerName,
455 (BOOLEAN)(This == &gDnsComponentName)
456 );
457 }