]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Dhcp4Dxe/ComponentName.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / 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 #include "Dhcp4Impl.h"
9
10 //
11 // EFI Component Name Functions
12 //
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 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 wish to retrieve the name of the bus
87 controller. It will not be NULL for a bus
88 driver that wishes 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 DhcpComponentNameGetControllerName (
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 // EFI Component Name Protocol
141 //
142 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDhcp4ComponentName = {
143 DhcpComponentNameGetDriverName,
144 DhcpComponentNameGetControllerName,
145 "eng"
146 };
147
148 //
149 // EFI Component Name 2 Protocol
150 //
151 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDhcp4ComponentName2 = {
152 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)DhcpComponentNameGetDriverName,
153 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)DhcpComponentNameGetControllerName,
154 "en"
155 };
156
157 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcpDriverNameTable[] = {
158 {
159 "eng;en",
160 L"DHCP Protocol Driver"
161 },
162 {
163 NULL,
164 NULL
165 }
166 };
167
168 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDhcpControllerNameTable = NULL;
169
170 CHAR16 *mDhcp4ControllerName[] = {
171 L"DHCPv4 (State=0, Stopped)",
172 L"DHCPv4 (State=1, Init)",
173 L"DHCPv4 (State=2, Selecting)",
174 L"DHCPv4 (State=3, Requesting)",
175 L"DHCPv4 (State=4, Bound)",
176 L"DHCPv4 (State=5, Renewing)",
177 L"DHCPv4 (State=6, Rebinding)",
178 L"DHCPv4 (State=7, InitReboot)",
179 L"DHCPv4 (State=8, Rebooting)"
180 };
181
182 /**
183 Retrieves a Unicode string that is the user readable name of the driver.
184
185 This function retrieves the user readable name of a driver in the form of a
186 Unicode string. If the driver specified by This has a user readable name in
187 the language specified by Language, then a pointer to the driver name is
188 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
189 by This does not support the language specified by Language,
190 then EFI_UNSUPPORTED is returned.
191
192 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
193 EFI_COMPONENT_NAME_PROTOCOL instance.
194
195 @param[in] Language A pointer to a Null-terminated ASCII string
196 array indicating the language. This is the
197 language of the driver name that the caller is
198 requesting, and it must match one of the
199 languages specified in SupportedLanguages. The
200 number of languages supported by a driver is up
201 to the driver writer. Language is specified
202 in RFC 4646 or ISO 639-2 language code format.
203
204 @param[out] DriverName A pointer to the Unicode string to return.
205 This Unicode string is the name of the
206 driver specified by This in the language
207 specified by Language.
208
209 @retval EFI_SUCCESS The Unicode string for the Driver specified by
210 This and the language specified by Language was
211 returned in DriverName.
212
213 @retval EFI_INVALID_PARAMETER Language is NULL.
214
215 @retval EFI_INVALID_PARAMETER DriverName is NULL.
216
217 @retval EFI_UNSUPPORTED The driver specified by This does not support
218 the language specified by Language.
219
220 **/
221 EFI_STATUS
222 EFIAPI
223 DhcpComponentNameGetDriverName (
224 IN EFI_COMPONENT_NAME_PROTOCOL *This,
225 IN CHAR8 *Language,
226 OUT CHAR16 **DriverName
227 )
228 {
229 return LookupUnicodeString2 (
230 Language,
231 This->SupportedLanguages,
232 mDhcpDriverNameTable,
233 DriverName,
234 (BOOLEAN)(This == &gDhcp4ComponentName)
235 );
236 }
237
238 /**
239 Update the component name for the Dhcp4 child handle.
240
241 @param Dhcp4[in] A pointer to the EFI_DHCP4_PROTOCOL.
242
243
244 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
245 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
246 @retval EFI_DEVICE_ERROR DHCP is in unknown state.
247
248 **/
249 EFI_STATUS
250 UpdateName (
251 IN EFI_DHCP4_PROTOCOL *Dhcp4
252 )
253 {
254 EFI_STATUS Status;
255 EFI_DHCP4_MODE_DATA Dhcp4ModeData;
256
257 if (Dhcp4 == NULL) {
258 return EFI_INVALID_PARAMETER;
259 }
260
261 //
262 // Format the child name into the string buffer.
263 //
264 Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData);
265 if (EFI_ERROR (Status)) {
266 return Status;
267 }
268
269 if (gDhcpControllerNameTable != NULL) {
270 FreeUnicodeStringTable (gDhcpControllerNameTable);
271 gDhcpControllerNameTable = NULL;
272 }
273
274 if (Dhcp4ModeData.State > Dhcp4Rebooting) {
275 return EFI_DEVICE_ERROR;
276 }
277
278 Status = AddUnicodeString2 (
279 "eng",
280 gDhcp4ComponentName.SupportedLanguages,
281 &gDhcpControllerNameTable,
282 mDhcp4ControllerName[Dhcp4ModeData.State],
283 TRUE
284 );
285 if (EFI_ERROR (Status)) {
286 return Status;
287 }
288
289 return AddUnicodeString2 (
290 "en",
291 gDhcp4ComponentName2.SupportedLanguages,
292 &gDhcpControllerNameTable,
293 mDhcp4ControllerName[Dhcp4ModeData.State],
294 FALSE
295 );
296 }
297
298 /**
299 Retrieves a Unicode string that is the user readable name of the controller
300 that is being managed by a driver.
301
302 This function retrieves the user readable name of the controller specified by
303 ControllerHandle and ChildHandle in the form of a Unicode string. If the
304 driver specified by This has a user readable name in the language specified by
305 Language, then a pointer to the controller name is returned in ControllerName,
306 and EFI_SUCCESS is returned. If the driver specified by This is not currently
307 managing the controller specified by ControllerHandle and ChildHandle,
308 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
309 support the language specified by Language, then EFI_UNSUPPORTED is returned.
310
311 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
312 EFI_COMPONENT_NAME_PROTOCOL instance.
313
314 @param[in] ControllerHandle The handle of a controller that the driver
315 specified by This is managing. This handle
316 specifies the controller whose name is to be
317 returned.
318
319 @param[in] ChildHandle The handle of the child controller to retrieve
320 the name of. This is an optional parameter that
321 may be NULL. It will be NULL for device
322 drivers. It will also be NULL for a bus drivers
323 that wish to retrieve the name of the bus
324 controller. It will not be NULL for a bus
325 driver that wishes to retrieve the name of a
326 child controller.
327
328 @param[in] Language A pointer to a Null-terminated ASCII string
329 array indicating the language. This is the
330 language of the driver name that the caller is
331 requesting, and it must match one of the
332 languages specified in SupportedLanguages. The
333 number of languages supported by a driver is up
334 to the driver writer. Language is specified in
335 RFC 4646 or ISO 639-2 language code format.
336
337 @param[out] ControllerName A pointer to the Unicode string to return.
338 This Unicode string is the name of the
339 controller specified by ControllerHandle and
340 ChildHandle in the language specified by
341 Language from the point of view of the driver
342 specified by This.
343
344 @retval EFI_SUCCESS The Unicode string for the user readable name in
345 the language specified by Language for the
346 driver specified by This was returned in
347 DriverName.
348
349 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
350
351 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
352 EFI_HANDLE.
353
354 @retval EFI_INVALID_PARAMETER Language is NULL.
355
356 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
357
358 @retval EFI_UNSUPPORTED The driver specified by This is not currently
359 managing the controller specified by
360 ControllerHandle and ChildHandle.
361
362 @retval EFI_UNSUPPORTED The driver specified by This does not support
363 the language specified by Language.
364
365 **/
366 EFI_STATUS
367 EFIAPI
368 DhcpComponentNameGetControllerName (
369 IN EFI_COMPONENT_NAME_PROTOCOL *This,
370 IN EFI_HANDLE ControllerHandle,
371 IN EFI_HANDLE ChildHandle OPTIONAL,
372 IN CHAR8 *Language,
373 OUT CHAR16 **ControllerName
374 )
375 {
376 EFI_STATUS Status;
377 EFI_DHCP4_PROTOCOL *Dhcp4;
378
379 //
380 // Only provide names for child handles.
381 //
382 if (ChildHandle == NULL) {
383 return EFI_UNSUPPORTED;
384 }
385
386 //
387 // Make sure this driver produced ChildHandle
388 //
389 Status = EfiTestChildHandle (
390 ControllerHandle,
391 ChildHandle,
392 &gEfiUdp4ProtocolGuid
393 );
394 if (EFI_ERROR (Status)) {
395 return Status;
396 }
397
398 //
399 // Retrieve an instance of a produced protocol from ChildHandle
400 //
401 Status = gBS->OpenProtocol (
402 ChildHandle,
403 &gEfiDhcp4ProtocolGuid,
404 (VOID **)&Dhcp4,
405 NULL,
406 NULL,
407 EFI_OPEN_PROTOCOL_GET_PROTOCOL
408 );
409 if (EFI_ERROR (Status)) {
410 return Status;
411 }
412
413 //
414 // Update the component name for this child handle.
415 //
416 Status = UpdateName (Dhcp4);
417 if (EFI_ERROR (Status)) {
418 return Status;
419 }
420
421 return LookupUnicodeString2 (
422 Language,
423 This->SupportedLanguages,
424 gDhcpControllerNameTable,
425 ControllerName,
426 (BOOLEAN)(This == &gDhcp4ComponentName)
427 );
428 }