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