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