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