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