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