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