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