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