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