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