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