]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Dhcp6Dxe/ComponentName.c
NetworkPkg: Apply uncrustify changes
[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
f75a7f56 4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
a3bcde70 5\r
ecf98fbc 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a3bcde70
HT
7\r
8**/\r
9\r
10#include "Dhcp6Impl.h"\r
11\r
a3bcde70
HT
12/**\r
13 Retrieves a Unicode string that is the user-readable name of the driver.\r
14\r
15 This function retrieves the user-readable name of a driver in the form of a\r
16 Unicode string. If the driver specified by This has a user-readable name in\r
17 the language specified by Language, then a pointer to the driver name is\r
18 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
19 by This does not support the language specified by Language,\r
20 then EFI_UNSUPPORTED is returned.\r
21\r
22 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
23 EFI_COMPONENT_NAME_PROTOCOL instance.\r
24\r
25 @param[in] Language A pointer to a Null-terminated ASCII string\r
26 array indicating the language. This is the\r
27 language of the driver name that the caller is\r
28 requesting, and it must match one of the\r
29 languages specified in SupportedLanguages. The\r
30 number of languages supported by a driver is up\r
31 to the driver writer. Language is specified\r
32 in RFC 4646 or ISO 639-2 language code format.\r
33\r
34 @param[out] DriverName A pointer to the Unicode string to return.\r
35 This Unicode string is the name of the\r
36 driver specified by This in the language\r
37 specified by Language.\r
38\r
39 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
40 This and the language specified by Language was\r
41 returned in DriverName.\r
42\r
43 @retval EFI_INVALID_PARAMETER Language is NULL.\r
44\r
45 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
46\r
47 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
48 the language specified by Language.\r
49\r
50**/\r
51EFI_STATUS\r
52EFIAPI\r
53Dhcp6ComponentNameGetDriverName (\r
54 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
55 IN CHAR8 *Language,\r
56 OUT CHAR16 **DriverName\r
57 );\r
58\r
a3bcde70
HT
59/**\r
60 Retrieves a Unicode string that is the user-readable name of the controller\r
61 that is being managed by a driver.\r
62\r
63 This function retrieves the user-readable name of the controller specified by\r
64 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
65 driver specified by This has a user-readable name in the language specified by\r
66 Language, then a pointer to the controller name is returned in ControllerName,\r
67 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
68 managing the controller specified by ControllerHandle and ChildHandle,\r
69 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
70 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
71\r
72 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
73 EFI_COMPONENT_NAME_PROTOCOL instance.\r
74\r
75 @param[in] ControllerHandle The handle of a controller that the driver\r
76 specified by This is managing. This handle\r
77 specifies the controller whose name is to be\r
78 returned.\r
79\r
80 @param[in] ChildHandle The handle of the child controller to retrieve\r
81 the name of. This is an optional parameter that\r
82 may be NULL. It will be NULL for device\r
83 drivers. It will also be NULL for a bus drivers\r
84 that attempt to retrieve the name of the bus\r
85 controller. It will not be NULL for a bus\r
86 driver that attempts to retrieve the name of a\r
87 child controller.\r
88\r
89 @param[in] Language A pointer to a Null-terminated ASCII string\r
90 array indicating the language. This is the\r
91 language of the driver name that the caller is\r
92 requesting, and it must match one of the\r
93 languages specified in SupportedLanguages. The\r
94 number of languages supported by a driver is up\r
95 to the driver writer. Language is specified in\r
96 RFC 4646 or ISO 639-2 language code format.\r
97\r
98 @param[out] ControllerName A pointer to the Unicode string to return.\r
99 This Unicode string is the name of the\r
100 controller specified by ControllerHandle and\r
101 ChildHandle in the language specified by\r
102 Language, from the point of view of the driver\r
103 specified by This.\r
104\r
105 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
106 the language specified by Language for the\r
107 driver specified by This was returned in\r
108 DriverName.\r
109\r
15ee13fc 110 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
111\r
112 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
113 EFI_HANDLE.\r
114\r
115 @retval EFI_INVALID_PARAMETER Language is NULL.\r
116\r
117 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
118\r
119 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
120 managing the controller specified by\r
121 ControllerHandle and ChildHandle.\r
122\r
123 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
124 the language specified by Language.\r
125\r
126**/\r
127EFI_STATUS\r
128EFIAPI\r
129Dhcp6ComponentNameGetControllerName (\r
d1050b9d
MK
130 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
131 IN EFI_HANDLE ControllerHandle,\r
132 IN EFI_HANDLE ChildHandle OPTIONAL,\r
133 IN CHAR8 *Language,\r
134 OUT CHAR16 **ControllerName\r
a3bcde70
HT
135 );\r
136\r
a3bcde70
HT
137//\r
138// EFI Component Name Protocol\r
139//\r
d1050b9d 140GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDhcp6ComponentName = {\r
a3bcde70
HT
141 Dhcp6ComponentNameGetDriverName,\r
142 Dhcp6ComponentNameGetControllerName,\r
143 "eng"\r
144};\r
145\r
146//\r
147// EFI Component Name 2 Protocol\r
148//\r
d1050b9d
MK
149GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDhcp6ComponentName2 = {\r
150 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Dhcp6ComponentNameGetDriverName,\r
151 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Dhcp6ComponentNameGetControllerName,\r
a3bcde70
HT
152 "en"\r
153};\r
154\r
d1050b9d 155GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcp6DriverNameTable[] = {\r
a3bcde70
HT
156 {\r
157 "eng;en",\r
158 L"DHCP6 Protocol Driver"\r
159 },\r
160 {\r
161 NULL,\r
162 NULL\r
163 }\r
164};\r
165\r
d1050b9d 166GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDhcp6ControllerNameTable = NULL;\r
216f7970 167\r
d1050b9d 168CHAR16 *mDhcp6ControllerName[] = {\r
216f7970 169 L"DHCPv6 (State=0, Init)",\r
170 L"DHCPv6 (State=1, Selecting)",\r
171 L"DHCPv6 (State=2, Requesting)",\r
172 L"DHCPv6 (State=3, Declining)",\r
173 L"DHCPv6 (State=4, Confirming)",\r
174 L"DHCPv6 (State=5, Releasing)",\r
175 L"DHCPv6 (State=6, Bound)",\r
176 L"DHCPv6 (State=7, Renewing)",\r
177 L"DHCPv6 (State=8, Rebinding)"\r
178};\r
a3bcde70
HT
179\r
180/**\r
181 Retrieves a Unicode string that is the user-readable name of the driver.\r
182\r
183 This function retrieves the user-readable name of a driver in the form of a\r
184 Unicode string. If the driver specified by This has a user-readable name in\r
185 the language specified by Language, then a pointer to the driver name is\r
186 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
187 by This does not support the language specified by Language,\r
188 then EFI_UNSUPPORTED is returned.\r
189\r
190 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
191 EFI_COMPONENT_NAME_PROTOCOL instance.\r
192\r
193 @param[in] Language A pointer to a Null-terminated ASCII string\r
194 array indicating the language. This is the\r
195 language of the driver name that the caller is\r
196 requesting, and it must match one of the\r
197 languages specified in SupportedLanguages. The\r
198 number of languages supported by a driver is up\r
199 to the driver writer. Language is specified\r
200 in RFC 4646 or ISO 639-2 language code format.\r
201\r
202 @param[out] DriverName A pointer to the Unicode string to return.\r
203 This Unicode string is the name of the\r
204 driver specified by This in the language\r
205 specified by Language.\r
206\r
207 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
208 This and the language specified by Language was\r
209 returned in DriverName.\r
210\r
211 @retval EFI_INVALID_PARAMETER Language is NULL.\r
212\r
213 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
214\r
215 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
216 the language specified by Language.\r
217\r
218**/\r
219EFI_STATUS\r
220EFIAPI\r
221Dhcp6ComponentNameGetDriverName (\r
222 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
223 IN CHAR8 *Language,\r
224 OUT CHAR16 **DriverName\r
225 )\r
226{\r
227 return LookupUnicodeString2 (\r
228 Language,\r
229 This->SupportedLanguages,\r
230 mDhcp6DriverNameTable,\r
231 DriverName,\r
232 (BOOLEAN)(This == &gDhcp6ComponentName)\r
233 );\r
234}\r
235\r
216f7970 236/**\r
237 Update the component name for the Dhcp6 child handle.\r
238\r
239 @param Dhcp6[in] A pointer to the EFI_DHCP6_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
d1050b9d 248 IN EFI_DHCP6_PROTOCOL *Dhcp6\r
216f7970 249 )\r
250{\r
d1050b9d
MK
251 EFI_STATUS Status;\r
252 EFI_DHCP6_MODE_DATA Dhcp6ModeData;\r
253 CHAR16 *HandleName;\r
216f7970 254\r
255 if (Dhcp6 == NULL) {\r
256 return EFI_INVALID_PARAMETER;\r
257 }\r
258\r
259 //\r
260 // Format the child name into the string buffer.\r
261 //\r
262 Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);\r
263 if (EFI_ERROR (Status)) {\r
264 return Status;\r
265 }\r
f75a7f56 266\r
216f7970 267 if (gDhcp6ControllerNameTable != NULL) {\r
268 FreeUnicodeStringTable (gDhcp6ControllerNameTable);\r
269 gDhcp6ControllerNameTable = NULL;\r
270 }\r
f75a7f56 271\r
216f7970 272 if (Dhcp6ModeData.Ia == NULL) {\r
a4faf336 273 HandleName = L"DHCPv6 (No configured IA)";\r
216f7970 274 } else {\r
a4faf336
FS
275 if (Dhcp6ModeData.Ia->State > Dhcp6Rebinding) {\r
276 return EFI_DEVICE_ERROR;\r
277 }\r
d1050b9d 278\r
a4faf336 279 HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];\r
216f7970 280 }\r
ce22514e
ZL
281\r
282 if (Dhcp6ModeData.Ia != NULL) {\r
283 FreePool (Dhcp6ModeData.Ia);\r
284 }\r
d1050b9d 285\r
ce22514e
ZL
286 if (Dhcp6ModeData.ClientId != NULL) {\r
287 FreePool (Dhcp6ModeData.ClientId);\r
288 }\r
289\r
216f7970 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
f75a7f56 300\r
216f7970 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
d1050b9d
MK
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
a3bcde70
HT
386 )\r
387{\r
d1050b9d
MK
388 EFI_STATUS Status;\r
389 EFI_DHCP6_PROTOCOL *Dhcp6;\r
216f7970 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
f75a7f56
LG
397\r
398 //\r
399 // Make sure this driver produced ChildHandle\r
400 //\r
216f7970 401 Status = EfiTestChildHandle (\r
402 ControllerHandle,\r
f75a7f56 403 ChildHandle,\r
216f7970 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
f75a7f56 416 (VOID **)&Dhcp6,\r
216f7970 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