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