]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/TcpDxe/ComponentName.c
Initialize data and correct faulty logic in TcpComponentNameGetControllerName().
[mirror_edk2.git] / NetworkPkg / TcpDxe / ComponentName.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 Implementation of protocols EFI_COMPONENT_NAME_PROTOCOL and\r
3 EFI_COMPONENT_NAME2_PROTOCOL.\r
4\r
ec305839 5 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "TcpMain.h"\r
18\r
19//\r
20// EFI Component Name Functions\r
21//\r
22\r
23/**\r
24 Retrieves a Unicode string that is the user-readable name of the driver.\r
25\r
26 This function retrieves the user-readable name of a driver in the form of a\r
27 Unicode string. If the driver specified by This has a user-readable name in\r
28 the language specified by Language, then a pointer to the driver name is\r
29 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
30 by This does not support the language specified by Language,\r
31 then EFI_UNSUPPORTED is returned.\r
32\r
33 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
34 EFI_COMPONENT_NAME_PROTOCOL instance.\r
35\r
36 @param[in] Language A pointer to a Null-terminated ASCII string\r
37 array indicating the language. This is the\r
38 language of the driver name that the caller is\r
39 requesting, and it must match one of the\r
40 languages specified in SupportedLanguages. The\r
41 number of languages supported by a driver is up\r
42 to the driver writer. Language is specified\r
43 in RFC 4646 or ISO 639-2 language code format.\r
44\r
45 @param[out] DriverName A pointer to the Unicode string to return.\r
46 This Unicode string is the name of the\r
47 driver specified by This in the language\r
48 specified by Language.\r
49\r
50 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
51 This, and the language specified by Language was\r
52 returned in DriverName.\r
53\r
54 @retval EFI_INVALID_PARAMETER Language or DriverName is NULL.\r
55\r
56 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
57 the language specified by Language.\r
58\r
59**/\r
60EFI_STATUS\r
61EFIAPI\r
62TcpComponentNameGetDriverName (\r
63 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
64 IN CHAR8 *Language,\r
65 OUT CHAR16 **DriverName\r
66 );\r
67\r
68/**\r
69 Retrieves a Unicode string that is the user-readable name of the controller\r
70 that is being managed by a driver.\r
71\r
72 This function retrieves the user-readable name of the controller specified by\r
73 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
74 driver specified by This has a user-readable name in the language specified by\r
75 Language, then a pointer to the controller name is returned in ControllerName,\r
76 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
77 managing the controller specified by ControllerHandle and ChildHandle,\r
78 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
79 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
80\r
81 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
82 EFI_COMPONENT_NAME_PROTOCOL instance.\r
83\r
84 @param[in] ControllerHandle The handle of a controller that the driver\r
85 specified by This is managing. This handle\r
86 specifies the controller whose name is to be\r
87 returned.\r
88\r
89 @param[in] ChildHandle The handle of the child controller to retrieve\r
90 the name of. This is an optional parameter that\r
91 may be NULL. It will be NULL for device\r
92 drivers. It will also be NULL for a bus drivers\r
93 that wish to retrieve the name of the bus\r
94 controller. It will not be NULL for a bus\r
95 driver that wishes to retrieve the name of a\r
96 child controller.\r
97\r
98 @param[in] Language A pointer to a Null-terminated ASCII string\r
99 array indicating the language. This is the\r
100 language of the driver name that the caller is\r
101 requesting, and it must match one of the\r
102 languages specified in SupportedLanguages. The\r
103 number of languages supported by a driver is up\r
104 to the driver writer. Language is specified in\r
105 RFC 4646 or ISO 639-2 language code format.\r
106\r
107 @param[out] ControllerName A pointer to the Unicode string to return.\r
108 This Unicode string is the name of the\r
109 controller specified by ControllerHandle and\r
110 ChildHandle in the language specified by\r
111 Language, from the point of view of the driver\r
112 specified by This.\r
113\r
114 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
115 the language specified by Language for the\r
116 driver specified by This was returned in\r
117 DriverName.\r
118\r
15ee13fc 119 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
120\r
121 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
122 EFI_HANDLE.\r
123\r
124 @retval EFI_INVALID_PARAMETER Language or ControllerName is NULL.\r
125\r
126 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
127 managing the controller specified by\r
128 ControllerHandle and ChildHandle.\r
129\r
130 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
131 the language specified by Language.\r
132\r
133**/\r
134EFI_STATUS\r
135EFIAPI\r
136TcpComponentNameGetControllerName (\r
137 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
138 IN EFI_HANDLE ControllerHandle,\r
139 IN EFI_HANDLE ChildHandle OPTIONAL,\r
140 IN CHAR8 *Language,\r
141 OUT CHAR16 **ControllerName\r
142 );\r
143\r
144///\r
145/// EFI Component Name Protocol\r
146///\r
147GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gTcpComponentName = {\r
148 TcpComponentNameGetDriverName,\r
149 TcpComponentNameGetControllerName,\r
150 "eng"\r
151};\r
152\r
153///\r
154/// EFI Component Name 2 Protocol\r
155///\r
156GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTcpComponentName2 = {\r
157 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) TcpComponentNameGetDriverName,\r
158 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) TcpComponentNameGetControllerName,\r
159 "en"\r
160};\r
161\r
162GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mTcpDriverNameTable[] = {\r
163 {\r
164 "eng;en",\r
165 L"TCP Network Service Driver"\r
166 },\r
167 {\r
168 NULL,\r
169 NULL\r
170 }\r
171};\r
172\r
216f7970 173GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gTcpControllerNameTable = NULL;\r
174\r
a3bcde70
HT
175/**\r
176 Retrieves a Unicode string that is the user-readable name of the driver.\r
177\r
178 This function retrieves the user-readable name of a driver in the form of a\r
179 Unicode string. If the driver specified by This has a user-readable name in\r
180 the language specified by Language, then a pointer to the driver name is\r
181 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
182 by This does not support the language specified by Language,\r
183 then EFI_UNSUPPORTED is returned.\r
184\r
185 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
186 EFI_COMPONENT_NAME_PROTOCOL instance.\r
187\r
188 @param[in] Language A pointer to a Null-terminated ASCII string\r
189 array indicating the language. This is the\r
190 language of the driver name that the caller is\r
191 requesting, and it must match one of the\r
192 languages specified in SupportedLanguages. The\r
193 number of languages supported by a driver is up\r
194 to the driver writer. Language is specified\r
195 in RFC 4646 or ISO 639-2 language code format.\r
196\r
197 @param[out] DriverName A pointer to the Unicode string to return.\r
198 This Unicode string is the name of the\r
199 driver specified by This in the language\r
200 specified by Language.\r
201\r
202 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
203 This, and the language specified by Language was\r
204 returned in DriverName.\r
205\r
206 @retval EFI_INVALID_PARAMETER Language or DriverName is NULL.\r
207\r
208 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
209 the language specified by Language.\r
210\r
211**/\r
212EFI_STATUS\r
213EFIAPI\r
214TcpComponentNameGetDriverName (\r
215 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
216 IN CHAR8 *Language,\r
217 OUT CHAR16 **DriverName\r
218 )\r
219{\r
220 return LookupUnicodeString2 (\r
221 Language,\r
222 This->SupportedLanguages,\r
223 mTcpDriverNameTable,\r
224 DriverName,\r
225 (BOOLEAN) (This == &gTcpComponentName)\r
226 );\r
227}\r
228\r
216f7970 229/**\r
230 Update the component name for the Tcp4 child handle.\r
231\r
232 @param Tcp4[in] A pointer to the EFI_TCP4_PROTOCOL.\r
233\r
234 \r
235 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
236 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
237 \r
238**/\r
239EFI_STATUS\r
240UpdateTcp4Name (\r
241 IN EFI_TCP4_PROTOCOL *Tcp4\r
242 )\r
243{\r
244 EFI_STATUS Status;\r
245 CHAR16 HandleName[80];\r
246 EFI_TCP4_CONFIG_DATA Tcp4ConfigData;\r
247\r
248 if (Tcp4 == NULL) {\r
249 return EFI_INVALID_PARAMETER;\r
250 }\r
251\r
252 //\r
253 // Format the child name into the string buffer as:\r
254 // TCPv4 (SrcPort=59, DestPort=60, ActiveFlag=TRUE)\r
255 //\r
ec305839 256 ZeroMem (&Tcp4ConfigData, sizeof (Tcp4ConfigData));\r
216f7970 257 Status = Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, NULL);\r
258 if (!EFI_ERROR (Status)) {\r
259 UnicodeSPrint (HandleName, sizeof (HandleName),\r
c5fba0fe 260 L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",\r
216f7970 261 Tcp4ConfigData.AccessPoint.StationPort,\r
262 Tcp4ConfigData.AccessPoint.RemotePort,\r
263 (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")\r
264 );\r
ec305839 265 } else if (Status == EFI_NOT_STARTED) {\r
216f7970 266 UnicodeSPrint (\r
267 HandleName,\r
268 sizeof (HandleName),\r
269 L"TCPv4 (Not started)"\r
270 );\r
271 } else {\r
272 return Status;\r
273 }\r
274\r
275 if (gTcpControllerNameTable != NULL) {\r
276 FreeUnicodeStringTable (gTcpControllerNameTable);\r
277 gTcpControllerNameTable = NULL;\r
278 }\r
279 \r
280 Status = AddUnicodeString2 (\r
281 "eng",\r
282 gTcpComponentName.SupportedLanguages,\r
283 &gTcpControllerNameTable,\r
284 HandleName,\r
285 TRUE\r
286 );\r
287 if (EFI_ERROR (Status)) {\r
288 return Status;\r
289 }\r
290 \r
291 return AddUnicodeString2 (\r
292 "en",\r
293 gTcpComponentName2.SupportedLanguages,\r
294 &gTcpControllerNameTable,\r
295 HandleName,\r
296 FALSE\r
297 );\r
298}\r
299\r
300/**\r
301 Update the component name for the Tcp6 child handle.\r
302\r
303 @param Tcp6[in] A pointer to the EFI_TCP6_PROTOCOL.\r
304\r
305 \r
306 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
307 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
308 \r
309**/\r
310EFI_STATUS\r
311UpdateTcp6Name (\r
312 IN EFI_TCP6_PROTOCOL *Tcp6\r
313 )\r
314{\r
315 EFI_STATUS Status;\r
316 CHAR16 HandleName[80];\r
317 EFI_TCP6_CONFIG_DATA Tcp6ConfigData;\r
318\r
319 if (Tcp6 == NULL) {\r
320 return EFI_INVALID_PARAMETER;\r
321 }\r
322\r
323 //\r
324 // Format the child name into the string buffer.\r
325 //\r
ec305839 326 ZeroMem (&Tcp6ConfigData, sizeof (Tcp6ConfigData));\r
216f7970 327 Status = Tcp6->GetModeData (Tcp6, NULL, &Tcp6ConfigData, NULL, NULL, NULL);\r
328 if (!EFI_ERROR (Status)) {\r
329 UnicodeSPrint (HandleName, sizeof (HandleName),\r
330 L"TCPv6(SrcPort=%d, DestPort=%d, ActiveFlag=%d)",\r
331 Tcp6ConfigData.AccessPoint.StationPort,\r
332 Tcp6ConfigData.AccessPoint.RemotePort,\r
333 Tcp6ConfigData.AccessPoint.ActiveFlag\r
334 );\r
335 } else if (Status == EFI_NOT_STARTED) {\r
336 UnicodeSPrint (HandleName, sizeof (HandleName), L"TCPv6(Not started)");\r
337 } else {\r
338 return Status;\r
339 }\r
340\r
341\r
342 if (gTcpControllerNameTable != NULL) {\r
343 FreeUnicodeStringTable (gTcpControllerNameTable);\r
344 gTcpControllerNameTable = NULL;\r
345 }\r
346 \r
347 Status = AddUnicodeString2 (\r
348 "eng",\r
349 gTcpComponentName.SupportedLanguages,\r
350 &gTcpControllerNameTable,\r
351 HandleName,\r
352 TRUE\r
353 );\r
354 if (EFI_ERROR (Status)) {\r
355 return Status;\r
356 }\r
357 \r
358 return AddUnicodeString2 (\r
359 "en",\r
360 gTcpComponentName2.SupportedLanguages,\r
361 &gTcpControllerNameTable,\r
362 HandleName,\r
363 FALSE\r
364 );\r
365}\r
366\r
a3bcde70
HT
367/**\r
368 Retrieves a Unicode string that is the user-readable name of the controller\r
369 that is being managed by a driver.\r
370\r
371 This function retrieves the user-readable name of the controller specified by\r
372 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
373 driver specified by This has a user-readable name in the language specified by\r
374 Language, then a pointer to the controller name is returned in ControllerName,\r
375 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
376 managing the controller specified by ControllerHandle and ChildHandle,\r
377 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
378 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
379\r
380 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
381 EFI_COMPONENT_NAME_PROTOCOL instance.\r
382\r
383 @param[in] ControllerHandle The handle of a controller that the driver\r
384 specified by This is managing. This handle\r
385 specifies the controller whose name is to be\r
386 returned.\r
387\r
388 @param[in] ChildHandle The handle of the child controller to retrieve\r
389 the name of. This is an optional parameter that\r
390 may be NULL. It will be NULL for device\r
391 drivers. It will also be NULL for a bus drivers\r
392 that wish to retrieve the name of the bus\r
393 controller. It will not be NULL for a bus\r
394 driver that wishes to retrieve the name of a\r
395 child controller.\r
396\r
397 @param[in] Language A pointer to a Null-terminated ASCII string\r
398 array indicating the language. This is the\r
399 language of the driver name that the caller is\r
400 requesting, and it must match one of the\r
401 languages specified in SupportedLanguages. The\r
402 number of languages supported by a driver is up\r
403 to the driver writer. Language is specified in\r
404 RFC 4646 or ISO 639-2 language code format.\r
405\r
406 @param[out] ControllerName A pointer to the Unicode string to return.\r
407 This Unicode string is the name of the\r
408 controller specified by ControllerHandle and\r
409 ChildHandle in the language specified by\r
410 Language, from the point of view of the driver\r
411 specified by This.\r
412\r
413 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
414 the language specified by Language for the\r
415 driver specified by This was returned in\r
416 DriverName.\r
417\r
15ee13fc 418 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
419\r
420 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
421 EFI_HANDLE.\r
422\r
423 @retval EFI_INVALID_PARAMETER Language or ControllerName is NULL.\r
424\r
425 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
426 managing the controller specified by\r
427 ControllerHandle and ChildHandle.\r
428\r
429 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
430 the language specified by Language.\r
431\r
432**/\r
433EFI_STATUS\r
434EFIAPI\r
435TcpComponentNameGetControllerName (\r
436 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
437 IN EFI_HANDLE ControllerHandle,\r
438 IN EFI_HANDLE ChildHandle OPTIONAL,\r
439 IN CHAR8 *Language,\r
440 OUT CHAR16 **ControllerName\r
441 )\r
442{\r
216f7970 443 EFI_STATUS Status;\r
444 EFI_TCP4_PROTOCOL *Tcp4;\r
445 EFI_TCP6_PROTOCOL *Tcp6;\r
446\r
447 //\r
448 // Only provide names for child handles.\r
449 //\r
450 if (ChildHandle == NULL) {\r
451 return EFI_UNSUPPORTED;\r
452 }\r
453\r
454 //\r
455 // Make sure this driver produced ChildHandle\r
456 //\r
457 Status = EfiTestChildHandle (\r
458 ControllerHandle,\r
459 ChildHandle,\r
460 &gEfiIp6ProtocolGuid\r
461 );\r
462 if (!EFI_ERROR (Status)) {\r
463 //\r
464 // Retrieve an instance of a produced protocol from ChildHandle\r
465 //\r
466 Status = gBS->OpenProtocol (\r
467 ChildHandle,\r
468 &gEfiTcp6ProtocolGuid,\r
469 (VOID **)&Tcp6,\r
470 NULL,\r
471 NULL,\r
472 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
473 );\r
474 if (EFI_ERROR (Status)) {\r
475 return Status;\r
476 }\r
477\r
478 //\r
479 // Update the component name for this child handle.\r
480 //\r
481 Status = UpdateTcp6Name (Tcp6);\r
482 if (EFI_ERROR (Status)) {\r
483 return Status;\r
484 }\r
485 }\r
486\r
487 //\r
488 // Make sure this driver is currently managing ControllHandle\r
489 //\r
490 Status = EfiTestChildHandle (\r
491 ControllerHandle,\r
492 ChildHandle,\r
493 &gEfiIp4ProtocolGuid\r
494 );\r
495 if (!EFI_ERROR (Status)) {\r
496 //\r
497 // Retrieve an instance of a produced protocol from ChildHandle\r
498 //\r
499 Status = gBS->OpenProtocol (\r
500 ChildHandle,\r
501 &gEfiTcp4ProtocolGuid,\r
502 (VOID **)&Tcp4,\r
503 NULL,\r
504 NULL,\r
505 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
506 );\r
507 if (EFI_ERROR (Status)) {\r
508 return Status;\r
509 }\r
510\r
511 //\r
512 // Update the component name for this child handle.\r
513 //\r
514 Status = UpdateTcp4Name (Tcp4);\r
515 if (EFI_ERROR (Status)) {\r
516 return Status;\r
517 }\r
518 }\r
519\r
520 return LookupUnicodeString2 (\r
521 Language,\r
522 This->SupportedLanguages,\r
523 gTcpControllerNameTable,\r
524 ControllerName,\r
525 (BOOLEAN)(This == &gTcpComponentName)\r
526 );\r
a3bcde70 527}\r
216f7970 528\r