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