]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Ip6Dxe/ComponentName.c
NetworkPkg: Apply uncrustify changes
[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 Update the component name for the IP6 child handle.
231
232 @param Ip6[in] A pointer to the EFI_IP6_PROTOCOL.
233
234
235 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
236 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
237
238 **/
239 EFI_STATUS
240 UpdateName (
241 IN EFI_IP6_PROTOCOL *Ip6
242 )
243 {
244 EFI_STATUS Status;
245 CHAR16 HandleName[128];
246 EFI_IP6_MODE_DATA Ip6ModeData;
247 UINTN Offset;
248 CHAR16 Address[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
249
250 if (Ip6 == NULL) {
251 return EFI_INVALID_PARAMETER;
252 }
253
254 //
255 // Format the child name into the string buffer.
256 //
257 Offset = 0;
258 Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL);
259 if (!EFI_ERROR (Status)) {
260 if (Ip6ModeData.AddressList != NULL) {
261 FreePool (Ip6ModeData.AddressList);
262 }
263
264 if (Ip6ModeData.GroupTable != NULL) {
265 FreePool (Ip6ModeData.GroupTable);
266 }
267
268 if (Ip6ModeData.RouteTable != NULL) {
269 FreePool (Ip6ModeData.RouteTable);
270 }
271
272 if (Ip6ModeData.NeighborCache != NULL) {
273 FreePool (Ip6ModeData.NeighborCache);
274 }
275
276 if (Ip6ModeData.PrefixTable != NULL) {
277 FreePool (Ip6ModeData.PrefixTable);
278 }
279
280 if (Ip6ModeData.IcmpTypeList != NULL) {
281 FreePool (Ip6ModeData.IcmpTypeList);
282 }
283 }
284
285 if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) {
286 Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof (Address));
287 if (EFI_ERROR (Status)) {
288 return Status;
289 }
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
302 UnicodeSPrint (
303 HandleName + Offset,
304 sizeof (HandleName) - Offset * sizeof (CHAR16),
305 L"DestinationAddress=%s)",
306 Address
307 );
308 } else if (!Ip6ModeData.IsStarted) {
309 UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv6(Not started)");
310 } else {
311 UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv6(%r)", Status);
312 }
313
314 if (gIp6ControllerNameTable != NULL) {
315 FreeUnicodeStringTable (gIp6ControllerNameTable);
316 gIp6ControllerNameTable = NULL;
317 }
318
319 Status = AddUnicodeString2 (
320 "eng",
321 gIp6ComponentName.SupportedLanguages,
322 &gIp6ControllerNameTable,
323 HandleName,
324 TRUE
325 );
326 if (EFI_ERROR (Status)) {
327 return Status;
328 }
329
330 return AddUnicodeString2 (
331 "en",
332 gIp6ComponentName2.SupportedLanguages,
333 &gIp6ControllerNameTable,
334 HandleName,
335 FALSE
336 );
337 }
338
339 /**
340 Retrieves a Unicode string that is the user-readable name of the controller
341 that is being managed by a driver.
342
343 This function retrieves the user-readable name of the controller specified by
344 ControllerHandle and ChildHandle in the form of a Unicode string. If the
345 driver specified by This has a user-readable name in the language specified by
346 Language, then a pointer to the controller name is returned in ControllerName,
347 and EFI_SUCCESS is returned. If the driver specified by This is not currently
348 managing the controller specified by ControllerHandle and ChildHandle,
349 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
350 support the language specified by Language, then EFI_UNSUPPORTED is returned.
351
352 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
353 EFI_COMPONENT_NAME_PROTOCOL instance.
354
355 @param[in] ControllerHandle The handle of a controller that the driver
356 specified by This is managing. This handle
357 specifies the controller whose name is to be
358 returned.
359
360 @param[in] ChildHandle The handle of the child controller to retrieve
361 the name of. This is an optional parameter that
362 may be NULL. It will be NULL for device
363 drivers. It will also be NULL for a bus drivers
364 that wish to retrieve the name of the bus
365 controller. It will not be NULL for a bus
366 driver that wishes to retrieve the name of a
367 child controller.
368
369 @param[in] Language A pointer to a Null-terminated ASCII string
370 array indicating the language. This is the
371 language of the driver name that the caller is
372 requesting, and it must match one of the
373 languages specified in SupportedLanguages. The
374 number of languages supported by a driver is up
375 to the driver writer. Language is specified in
376 RFC 4646 or ISO 639-2 language code format.
377
378 @param[out] ControllerName A pointer to the Unicode string to return.
379 This Unicode string is the name of the
380 controller specified by ControllerHandle and
381 ChildHandle in the language specified by
382 Language from the point of view of the driver
383 specified by This.
384
385 @retval EFI_SUCCESS The Unicode string for the user-readable name in
386 the language specified by Language for the
387 driver specified by This was returned in
388 DriverName.
389
390 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
391
392 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
393 EFI_HANDLE.
394
395 @retval EFI_INVALID_PARAMETER Language is NULL.
396
397 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
398
399 @retval EFI_UNSUPPORTED The driver specified by This is not currently
400 managing the controller specified by
401 ControllerHandle and ChildHandle.
402
403 @retval EFI_UNSUPPORTED The driver specified by This does not support
404 the language specified by Language.
405
406 **/
407 EFI_STATUS
408 EFIAPI
409 Ip6ComponentNameGetControllerName (
410 IN EFI_COMPONENT_NAME_PROTOCOL *This,
411 IN EFI_HANDLE ControllerHandle,
412 IN EFI_HANDLE ChildHandle OPTIONAL,
413 IN CHAR8 *Language,
414 OUT CHAR16 **ControllerName
415 )
416 {
417 EFI_STATUS Status;
418 EFI_IP6_PROTOCOL *Ip6;
419
420 //
421 // Only provide names for child handles.
422 //
423 if (ChildHandle == NULL) {
424 return EFI_UNSUPPORTED;
425 }
426
427 //
428 // Make sure this driver produced ChildHandle
429 //
430 Status = EfiTestChildHandle (
431 ControllerHandle,
432 ChildHandle,
433 &gEfiManagedNetworkProtocolGuid
434 );
435 if (EFI_ERROR (Status)) {
436 return Status;
437 }
438
439 //
440 // Retrieve an instance of a produced protocol from ChildHandle
441 //
442 Status = gBS->OpenProtocol (
443 ChildHandle,
444 &gEfiIp6ProtocolGuid,
445 (VOID **)&Ip6,
446 NULL,
447 NULL,
448 EFI_OPEN_PROTOCOL_GET_PROTOCOL
449 );
450 if (EFI_ERROR (Status)) {
451 return Status;
452 }
453
454 //
455 // Update the component name for this child handle.
456 //
457 Status = UpdateName (Ip6);
458 if (EFI_ERROR (Status)) {
459 return Status;
460 }
461
462 return LookupUnicodeString2 (
463 Language,
464 This->SupportedLanguages,
465 gIp6ControllerNameTable,
466 ControllerName,
467 (BOOLEAN)(This == &gIp6ComponentName)
468 );
469 }