]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Ip6Dxe/ComponentName.c
Fix a bug about the iSCSI DHCP dependency issue.
[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
216f7970 5 Copyright (c) 2009 - 2012, 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
241 \r
242 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
243 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
244 \r
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
266 if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) {\r
267 Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof(Address));\r
268 if (EFI_ERROR (Status)) {\r
269 return Status;\r
270 }\r
271 Offset += UnicodeSPrint (\r
272 HandleName,\r
273 sizeof(HandleName),\r
274 L"IPv6(StationAddress=%s, ",\r
275 Address\r
276 );\r
277 Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.DestinationAddress, Address, sizeof(Address));\r
278 if (EFI_ERROR (Status)) {\r
279 return Status;\r
280 }\r
281 UnicodeSPrint (\r
282 HandleName + Offset,\r
f8c075d1 283 sizeof(HandleName) - Offset * sizeof (CHAR16),\r
216f7970 284 L"DestinationAddress=%s)",\r
285 Address\r
286 );\r
287 } else if (!Ip6ModeData.IsStarted) {\r
288 UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(Not started)");\r
289 } else {\r
290 UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(%r)", Status);\r
291 }\r
292\r
293 if (gIp6ControllerNameTable != NULL) {\r
294 FreeUnicodeStringTable (gIp6ControllerNameTable);\r
295 gIp6ControllerNameTable = NULL;\r
296 }\r
297 \r
298 Status = AddUnicodeString2 (\r
299 "eng",\r
300 gIp6ComponentName.SupportedLanguages,\r
301 &gIp6ControllerNameTable,\r
302 HandleName,\r
303 TRUE\r
304 );\r
305 if (EFI_ERROR (Status)) {\r
306 return Status;\r
307 }\r
308 \r
309 return AddUnicodeString2 (\r
310 "en",\r
311 gIp6ComponentName2.SupportedLanguages,\r
312 &gIp6ControllerNameTable,\r
313 HandleName,\r
314 FALSE\r
315 );\r
316}\r
317\r
a3bcde70
HT
318/**\r
319 Retrieves a Unicode string that is the user-readable name of the controller\r
320 that is being managed by a driver.\r
321\r
322 This function retrieves the user-readable name of the controller specified by\r
323 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
324 driver specified by This has a user-readable name in the language specified by\r
325 Language, then a pointer to the controller name is returned in ControllerName,\r
326 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
327 managing the controller specified by ControllerHandle and ChildHandle,\r
328 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
329 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
330\r
331 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
332 EFI_COMPONENT_NAME_PROTOCOL instance.\r
333\r
334 @param[in] ControllerHandle The handle of a controller that the driver\r
335 specified by This is managing. This handle\r
336 specifies the controller whose name is to be\r
337 returned.\r
338\r
339 @param[in] ChildHandle The handle of the child controller to retrieve\r
340 the name of. This is an optional parameter that\r
341 may be NULL. It will be NULL for device\r
342 drivers. It will also be NULL for a bus drivers\r
343 that wish to retrieve the name of the bus\r
344 controller. It will not be NULL for a bus\r
345 driver that wishes to retrieve the name of a\r
346 child controller.\r
347\r
348 @param[in] Language A pointer to a Null-terminated ASCII string\r
349 array indicating the language. This is the\r
350 language of the driver name that the caller is\r
351 requesting, and it must match one of the\r
352 languages specified in SupportedLanguages. The\r
353 number of languages supported by a driver is up\r
354 to the driver writer. Language is specified in\r
355 RFC 4646 or ISO 639-2 language code format.\r
356\r
357 @param[out] ControllerName A pointer to the Unicode string to return.\r
358 This Unicode string is the name of the\r
359 controller specified by ControllerHandle and\r
360 ChildHandle in the language specified by\r
361 Language from the point of view of the driver\r
362 specified by This.\r
363\r
364 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
365 the language specified by Language for the\r
366 driver specified by This was returned in\r
367 DriverName.\r
368\r
15ee13fc 369 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
370\r
371 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
372 EFI_HANDLE.\r
373\r
374 @retval EFI_INVALID_PARAMETER Language is NULL.\r
375\r
376 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
377\r
378 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
379 managing the controller specified by\r
380 ControllerHandle and ChildHandle.\r
381\r
382 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
383 the language specified by Language.\r
384\r
385**/\r
386EFI_STATUS\r
387EFIAPI\r
388Ip6ComponentNameGetControllerName (\r
389 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
390 IN EFI_HANDLE ControllerHandle,\r
391 IN EFI_HANDLE ChildHandle OPTIONAL,\r
392 IN CHAR8 *Language,\r
393 OUT CHAR16 **ControllerName\r
394 )\r
395{\r
216f7970 396 EFI_STATUS Status;\r
397 EFI_IP6_PROTOCOL *Ip6;\r
398 \r
399 //\r
400 // Only provide names for child handles.\r
401 //\r
402 if (ChildHandle == NULL) {\r
403 return EFI_UNSUPPORTED;\r
404 }\r
405\r
406 //\r
407 // Make sure this driver produced ChildHandle \r
408 //\r
409 Status = EfiTestChildHandle (\r
410 ControllerHandle,\r
411 ChildHandle,\r
412 &gEfiManagedNetworkProtocolGuid\r
413 );\r
414 if (EFI_ERROR (Status)) {\r
415 return Status;\r
416 }\r
417\r
418 //\r
419 // Retrieve an instance of a produced protocol from ChildHandle\r
420 //\r
421 Status = gBS->OpenProtocol (\r
422 ChildHandle,\r
423 &gEfiIp6ProtocolGuid,\r
424 (VOID **)&Ip6,\r
425 NULL,\r
426 NULL,\r
427 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
428 );\r
429 if (EFI_ERROR (Status)) {\r
430 return Status;\r
431 }\r
432\r
433 //\r
434 // Update the component name for this child handle.\r
435 //\r
436 Status = UpdateName (Ip6);\r
437 if (EFI_ERROR (Status)) {\r
438 return Status;\r
439 }\r
440\r
441 return LookupUnicodeString2 (\r
442 Language,\r
443 This->SupportedLanguages,\r
444 gIp6ControllerNameTable,\r
445 ControllerName,\r
446 (BOOLEAN)(This == &gIp6ComponentName)\r
447 );\r
a3bcde70 448}\r