]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Dhcp6Dxe/ComponentName.c
SecurityPkg: Correct data copy in Tpm2NvReadPublic.
[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
2922e29a 4 Copyright (c) 2009 - 2014, 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
a4faf336 262 CHAR16 *HandleName;\r
216f7970 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
a4faf336 282 HandleName = L"DHCPv6 (No configured IA)";\r
216f7970 283 } else {\r
a4faf336
FS
284 if (Dhcp6ModeData.Ia->State > Dhcp6Rebinding) {\r
285 return EFI_DEVICE_ERROR;\r
286 }\r
287 HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];\r
216f7970 288 }\r
289 \r
290 Status = AddUnicodeString2 (\r
291 "eng",\r
292 gDhcp6ComponentName.SupportedLanguages,\r
293 &gDhcp6ControllerNameTable,\r
294 HandleName,\r
295 TRUE\r
296 );\r
297 if (EFI_ERROR (Status)) {\r
298 return Status;\r
299 }\r
300 \r
301 return AddUnicodeString2 (\r
302 "en",\r
303 gDhcp6ComponentName2.SupportedLanguages,\r
304 &gDhcp6ControllerNameTable,\r
305 HandleName,\r
306 FALSE\r
307 );\r
308}\r
a3bcde70
HT
309\r
310/**\r
311 Retrieves a Unicode string that is the user-readable name of the controller\r
312 that is being managed by a driver.\r
313\r
314 This function retrieves the user-readable name of the controller specified by\r
315 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
316 driver specified by This has a user-readable name in the language specified by\r
317 Language, then a pointer to the controller name is returned in ControllerName,\r
318 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
319 managing the controller specified by ControllerHandle and ChildHandle,\r
320 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
321 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
322\r
323 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
324 EFI_COMPONENT_NAME_PROTOCOL instance.\r
325\r
326 @param[in] ControllerHandle The handle of a controller that the driver\r
327 specified by This is managing. This handle\r
328 specifies the controller whose name is to be\r
329 returned.\r
330\r
331 @param[in] ChildHandle The handle of the child controller to retrieve\r
332 the name of. This is an optional parameter that\r
333 may be NULL. It will be NULL for device\r
334 drivers. It will also be NULL for a bus drivers\r
335 that wish to retrieve the name of the bus\r
336 controller. It will not be NULL for a bus\r
337 driver that wishes to retrieve the name of a\r
338 child controller.\r
339\r
340 @param[in] Language A pointer to a Null-terminated ASCII string\r
341 array indicating the language. This is the\r
342 language of the driver name that the caller is\r
343 requesting, and it must match one of the\r
344 languages specified in SupportedLanguages. The\r
345 number of languages supported by a driver is up\r
346 to the driver writer. Language is specified in the\r
347 RFC 4646 or ISO 639-2 language code format.\r
348\r
349 @param[out] ControllerName A pointer to the Unicode string to return.\r
350 This Unicode string is the name of the\r
351 controller specified by ControllerHandle and\r
352 ChildHandle in the language specified by\r
353 Language, from the point of view of the driver\r
354 specified by This.\r
355\r
356 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
357 the language specified by Language for the\r
358 driver specified by This was returned in\r
359 DriverName.\r
360\r
15ee13fc 361 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
362\r
363 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
364 EFI_HANDLE.\r
365\r
366 @retval EFI_INVALID_PARAMETER Language is NULL.\r
367\r
368 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
369\r
370 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
371 managing the controller specified by\r
372 ControllerHandle and ChildHandle.\r
373\r
374 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
375 the language specified by Language.\r
376\r
377**/\r
378EFI_STATUS\r
379EFIAPI\r
380Dhcp6ComponentNameGetControllerName (\r
381 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
382 IN EFI_HANDLE ControllerHandle,\r
383 IN EFI_HANDLE ChildHandle OPTIONAL,\r
384 IN CHAR8 *Language,\r
385 OUT CHAR16 **ControllerName\r
386 )\r
387{\r
216f7970 388 EFI_STATUS Status;\r
389 EFI_DHCP6_PROTOCOL *Dhcp6;\r
390\r
391 //\r
392 // Only provide names for child handles.\r
393 //\r
394 if (ChildHandle == NULL) {\r
395 return EFI_UNSUPPORTED;\r
396 }\r
397 \r
398 // \r
399 // Make sure this driver produced ChildHandle \r
400 // \r
401 Status = EfiTestChildHandle (\r
402 ControllerHandle,\r
403 ChildHandle, \r
404 &gEfiUdp6ProtocolGuid\r
405 );\r
406 if (EFI_ERROR (Status)) {\r
407 return Status;\r
408 }\r
409\r
410 //\r
411 // Retrieve an instance of a produced protocol from ChildHandle\r
412 //\r
413 Status = gBS->OpenProtocol (\r
414 ChildHandle,\r
415 &gEfiDhcp6ProtocolGuid,\r
416 (VOID **)&Dhcp6, \r
417 NULL,\r
418 NULL,\r
419 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
420 );\r
421 if (EFI_ERROR (Status)) {\r
422 return Status;\r
423 }\r
424\r
425 //\r
426 // Update the component name for this child handle.\r
427 //\r
428 Status = UpdateName (Dhcp6);\r
429 if (EFI_ERROR (Status)) {\r
430 return Status;\r
431 }\r
432\r
433 return LookupUnicodeString2 (\r
434 Language,\r
435 This->SupportedLanguages,\r
436 gDhcp6ControllerNameTable,\r
437 ControllerName,\r
438 (BOOLEAN)(This == &gDhcp6ComponentName)\r
439 );\r
a3bcde70 440}\r
216f7970 441\r