]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/TcpDxe/ComponentName.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
d1050b9d 141GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gTcpComponentName = {\r
a3bcde70
HT
142 TcpComponentNameGetDriverName,\r
143 TcpComponentNameGetControllerName,\r
144 "eng"\r
145};\r
146\r
147///\r
148/// EFI Component Name 2 Protocol\r
149///\r
d1050b9d
MK
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
a3bcde70
HT
153 "en"\r
154};\r
155\r
d1050b9d 156GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mTcpDriverNameTable[] = {\r
a3bcde70
HT
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
d1050b9d 167GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gTcpControllerNameTable = NULL;\r
216f7970 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
d1050b9d 219 (BOOLEAN)(This == &gTcpComponentName)\r
a3bcde70
HT
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
d1050b9d 235 IN EFI_TCP4_PROTOCOL *Tcp4\r
216f7970 236 )\r
237{\r
d1050b9d
MK
238 EFI_STATUS Status;\r
239 CHAR16 HandleName[80];\r
240 EFI_TCP4_CONFIG_DATA Tcp4ConfigData;\r
216f7970 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
d1050b9d
MK
253 UnicodeSPrint (\r
254 HandleName,\r
255 sizeof (HandleName),\r
c5fba0fe 256 L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",\r
216f7970 257 Tcp4ConfigData.AccessPoint.StationPort,\r
258 Tcp4ConfigData.AccessPoint.RemotePort,\r
259 (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")\r
260 );\r
ec305839 261 } else if (Status == EFI_NOT_STARTED) {\r
216f7970 262 UnicodeSPrint (\r
263 HandleName,\r
264 sizeof (HandleName),\r
265 L"TCPv4 (Not started)"\r
266 );\r
267 } else {\r
268 return Status;\r
269 }\r
270\r
271 if (gTcpControllerNameTable != NULL) {\r
272 FreeUnicodeStringTable (gTcpControllerNameTable);\r
273 gTcpControllerNameTable = NULL;\r
274 }\r
f75a7f56 275\r
216f7970 276 Status = AddUnicodeString2 (\r
277 "eng",\r
278 gTcpComponentName.SupportedLanguages,\r
279 &gTcpControllerNameTable,\r
280 HandleName,\r
281 TRUE\r
282 );\r
283 if (EFI_ERROR (Status)) {\r
284 return Status;\r
285 }\r
f75a7f56 286\r
216f7970 287 return AddUnicodeString2 (\r
288 "en",\r
289 gTcpComponentName2.SupportedLanguages,\r
290 &gTcpControllerNameTable,\r
291 HandleName,\r
292 FALSE\r
293 );\r
294}\r
295\r
296/**\r
297 Update the component name for the Tcp6 child handle.\r
298\r
299 @param Tcp6[in] A pointer to the EFI_TCP6_PROTOCOL.\r
300\r
f75a7f56 301\r
216f7970 302 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
303 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
f75a7f56 304\r
216f7970 305**/\r
306EFI_STATUS\r
307UpdateTcp6Name (\r
d1050b9d 308 IN EFI_TCP6_PROTOCOL *Tcp6\r
216f7970 309 )\r
310{\r
d1050b9d
MK
311 EFI_STATUS Status;\r
312 CHAR16 HandleName[80];\r
313 EFI_TCP6_CONFIG_DATA Tcp6ConfigData;\r
216f7970 314\r
315 if (Tcp6 == NULL) {\r
316 return EFI_INVALID_PARAMETER;\r
317 }\r
318\r
319 //\r
320 // Format the child name into the string buffer.\r
321 //\r
ec305839 322 ZeroMem (&Tcp6ConfigData, sizeof (Tcp6ConfigData));\r
216f7970 323 Status = Tcp6->GetModeData (Tcp6, NULL, &Tcp6ConfigData, NULL, NULL, NULL);\r
324 if (!EFI_ERROR (Status)) {\r
d1050b9d
MK
325 UnicodeSPrint (\r
326 HandleName,\r
327 sizeof (HandleName),\r
216f7970 328 L"TCPv6(SrcPort=%d, DestPort=%d, ActiveFlag=%d)",\r
329 Tcp6ConfigData.AccessPoint.StationPort,\r
330 Tcp6ConfigData.AccessPoint.RemotePort,\r
331 Tcp6ConfigData.AccessPoint.ActiveFlag\r
332 );\r
333 } else if (Status == EFI_NOT_STARTED) {\r
334 UnicodeSPrint (HandleName, sizeof (HandleName), L"TCPv6(Not started)");\r
335 } else {\r
336 return Status;\r
337 }\r
338\r
216f7970 339 if (gTcpControllerNameTable != NULL) {\r
340 FreeUnicodeStringTable (gTcpControllerNameTable);\r
341 gTcpControllerNameTable = NULL;\r
342 }\r
f75a7f56 343\r
216f7970 344 Status = AddUnicodeString2 (\r
345 "eng",\r
346 gTcpComponentName.SupportedLanguages,\r
347 &gTcpControllerNameTable,\r
348 HandleName,\r
349 TRUE\r
350 );\r
351 if (EFI_ERROR (Status)) {\r
352 return Status;\r
353 }\r
f75a7f56 354\r
216f7970 355 return AddUnicodeString2 (\r
356 "en",\r
357 gTcpComponentName2.SupportedLanguages,\r
358 &gTcpControllerNameTable,\r
359 HandleName,\r
360 FALSE\r
361 );\r
362}\r
363\r
a3bcde70
HT
364/**\r
365 Retrieves a Unicode string that is the user-readable name of the controller\r
366 that is being managed by a driver.\r
367\r
368 This function retrieves the user-readable name of the controller specified by\r
369 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
370 driver specified by This has a user-readable name in the language specified by\r
371 Language, then a pointer to the controller name is returned in ControllerName,\r
372 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
373 managing the controller specified by ControllerHandle and ChildHandle,\r
374 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
375 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
376\r
377 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
378 EFI_COMPONENT_NAME_PROTOCOL instance.\r
379\r
380 @param[in] ControllerHandle The handle of a controller that the driver\r
381 specified by This is managing. This handle\r
382 specifies the controller whose name is to be\r
383 returned.\r
384\r
385 @param[in] ChildHandle The handle of the child controller to retrieve\r
386 the name of. This is an optional parameter that\r
387 may be NULL. It will be NULL for device\r
388 drivers. It will also be NULL for a bus drivers\r
389 that wish to retrieve the name of the bus\r
390 controller. It will not be NULL for a bus\r
391 driver that wishes to retrieve the name of a\r
392 child controller.\r
393\r
394 @param[in] Language A pointer to a Null-terminated ASCII string\r
395 array indicating the language. This is the\r
396 language of the driver name that the caller is\r
397 requesting, and it must match one of the\r
398 languages specified in SupportedLanguages. The\r
399 number of languages supported by a driver is up\r
400 to the driver writer. Language is specified in\r
401 RFC 4646 or ISO 639-2 language code format.\r
402\r
403 @param[out] ControllerName A pointer to the Unicode string to return.\r
404 This Unicode string is the name of the\r
405 controller specified by ControllerHandle and\r
406 ChildHandle in the language specified by\r
407 Language, from the point of view of the driver\r
408 specified by This.\r
409\r
410 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
411 the language specified by Language for the\r
412 driver specified by This was returned in\r
413 DriverName.\r
414\r
15ee13fc 415 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
416\r
417 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
418 EFI_HANDLE.\r
419\r
420 @retval EFI_INVALID_PARAMETER Language or ControllerName is NULL.\r
421\r
422 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
423 managing the controller specified by\r
424 ControllerHandle and ChildHandle.\r
425\r
426 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
427 the language specified by Language.\r
428\r
429**/\r
430EFI_STATUS\r
431EFIAPI\r
432TcpComponentNameGetControllerName (\r
433 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
434 IN EFI_HANDLE ControllerHandle,\r
435 IN EFI_HANDLE ChildHandle OPTIONAL,\r
436 IN CHAR8 *Language,\r
437 OUT CHAR16 **ControllerName\r
438 )\r
439{\r
d1050b9d
MK
440 EFI_STATUS Status;\r
441 EFI_TCP4_PROTOCOL *Tcp4;\r
442 EFI_TCP6_PROTOCOL *Tcp6;\r
216f7970 443\r
444 //\r
445 // Only provide names for child handles.\r
446 //\r
447 if (ChildHandle == NULL) {\r
448 return EFI_UNSUPPORTED;\r
449 }\r
450\r
451 //\r
452 // Make sure this driver produced ChildHandle\r
453 //\r
454 Status = EfiTestChildHandle (\r
455 ControllerHandle,\r
456 ChildHandle,\r
457 &gEfiIp6ProtocolGuid\r
458 );\r
459 if (!EFI_ERROR (Status)) {\r
460 //\r
461 // Retrieve an instance of a produced protocol from ChildHandle\r
462 //\r
463 Status = gBS->OpenProtocol (\r
464 ChildHandle,\r
465 &gEfiTcp6ProtocolGuid,\r
d1050b9d 466 (VOID **)&Tcp6,\r
216f7970 467 NULL,\r
468 NULL,\r
469 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
470 );\r
471 if (EFI_ERROR (Status)) {\r
472 return Status;\r
473 }\r
474\r
475 //\r
476 // Update the component name for this child handle.\r
477 //\r
478 Status = UpdateTcp6Name (Tcp6);\r
479 if (EFI_ERROR (Status)) {\r
480 return Status;\r
481 }\r
482 }\r
483\r
484 //\r
485 // Make sure this driver is currently managing ControllHandle\r
486 //\r
487 Status = EfiTestChildHandle (\r
488 ControllerHandle,\r
489 ChildHandle,\r
490 &gEfiIp4ProtocolGuid\r
491 );\r
492 if (!EFI_ERROR (Status)) {\r
493 //\r
494 // Retrieve an instance of a produced protocol from ChildHandle\r
495 //\r
496 Status = gBS->OpenProtocol (\r
d1050b9d
MK
497 ChildHandle,\r
498 &gEfiTcp4ProtocolGuid,\r
499 (VOID **)&Tcp4,\r
500 NULL,\r
501 NULL,\r
502 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
503 );\r
216f7970 504 if (EFI_ERROR (Status)) {\r
505 return Status;\r
506 }\r
507\r
508 //\r
509 // Update the component name for this child handle.\r
510 //\r
511 Status = UpdateTcp4Name (Tcp4);\r
512 if (EFI_ERROR (Status)) {\r
513 return Status;\r
514 }\r
515 }\r
516\r
517 return LookupUnicodeString2 (\r
518 Language,\r
519 This->SupportedLanguages,\r
520 gTcpControllerNameTable,\r
521 ControllerName,\r
522 (BOOLEAN)(This == &gTcpComponentName)\r
523 );\r
a3bcde70 524}\r