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