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