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