]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c
Fix a bug in TCP driver’s component name print function.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / ComponentName.c
CommitLineData
8a67d61d 1/** @file\r
dab714aa 2 UEFI Component Name(2) protocol implementation for Tcp4Dxe driver.\r
8a67d61d 3\r
c5fba0fe 4Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
8a67d61d 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
dfc1f033 8http://opensource.org/licenses/bsd-license.php<BR>\r
8a67d61d 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
8a67d61d 13**/\r
14\r
15#include "Tcp4Main.h"\r
16\r
83cbd279 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
dfc1f033 27 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 28 EFI_COMPONENT_NAME_PROTOCOL instance.\r
29\r
dfc1f033 30 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 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
0254efc0 37 in RFC 4646 or ISO 639-2 language code format.\r
83cbd279 38\r
dfc1f033 39 @param[out] DriverName A pointer to the Unicode string to return.\r
83cbd279 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 is NULL.\r
49\r
50 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
51\r
52 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
53 the language specified by Language.\r
54\r
55**/\r
8a67d61d 56EFI_STATUS\r
57EFIAPI\r
58TcpComponentNameGetDriverName (\r
dfc1f033 59 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
60 IN CHAR8 *Language,\r
61 OUT CHAR16 **DriverName\r
8a67d61d 62 );\r
63\r
83cbd279 64\r
65/**\r
66 Retrieves a Unicode string that is the user readable name of the controller\r
67 that is being managed by a driver.\r
68\r
69 This function retrieves the user readable name of the controller specified by\r
70 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
71 driver specified by This has a user readable name in the language specified by\r
72 Language, then a pointer to the controller name is returned in ControllerName,\r
73 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
74 managing the controller specified by ControllerHandle and ChildHandle,\r
75 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
76 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
77\r
dfc1f033 78 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 79 EFI_COMPONENT_NAME_PROTOCOL instance.\r
80\r
dfc1f033 81 @param[in] ControllerHandle The handle of a controller that the driver\r
83cbd279 82 specified by This is managing. This handle\r
83 specifies the controller whose name is to be\r
84 returned.\r
85\r
dfc1f033 86 @param[in] ChildHandle The handle of the child controller to retrieve\r
83cbd279 87 the name of. This is an optional parameter that\r
88 may be NULL. It will be NULL for device\r
89 drivers. It will also be NULL for a bus drivers\r
90 that wish to retrieve the name of the bus\r
91 controller. It will not be NULL for a bus\r
92 driver that wishes to retrieve the name of a\r
93 child controller.\r
94\r
dfc1f033 95 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 96 array indicating the language. This is the\r
97 language of the driver name that the caller is\r
98 requesting, and it must match one of the\r
99 languages specified in SupportedLanguages. The\r
100 number of languages supported by a driver is up\r
101 to the driver writer. Language is specified in\r
0254efc0 102 RFC 4646 or ISO 639-2 language code format.\r
83cbd279 103\r
dfc1f033 104 @param[out] ControllerName A pointer to the Unicode string to return.\r
83cbd279 105 This Unicode string is the name of the\r
106 controller specified by ControllerHandle and\r
107 ChildHandle in the language specified by\r
108 Language from the point of view of the driver\r
109 specified by This.\r
110\r
111 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
112 the language specified by Language for the\r
113 driver specified by This was returned in\r
114 DriverName.\r
115\r
284ee2e8 116 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
83cbd279 117\r
118 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
119 EFI_HANDLE.\r
120\r
121 @retval EFI_INVALID_PARAMETER Language is NULL.\r
122\r
123 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
124\r
125 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
126 managing the controller specified by\r
127 ControllerHandle and ChildHandle.\r
128\r
129 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
130 the language specified by Language.\r
131\r
132**/\r
8a67d61d 133EFI_STATUS\r
134EFIAPI\r
135TcpComponentNameGetControllerName (\r
dfc1f033 136 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
137 IN EFI_HANDLE ControllerHandle,\r
138 IN EFI_HANDLE ChildHandle OPTIONAL,\r
139 IN CHAR8 *Language,\r
140 OUT CHAR16 **ControllerName\r
8a67d61d 141 );\r
142\r
83cbd279 143\r
dfc1f033 144///\r
145/// EFI Component Name Protocol\r
146///\r
1307dcd7 147GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gTcp4ComponentName = {\r
8a67d61d 148 TcpComponentNameGetDriverName,\r
149 TcpComponentNameGetControllerName,\r
150 "eng"\r
1307dcd7 151};\r
83cbd279 152\r
dfc1f033 153///\r
154/// EFI Component Name 2 Protocol\r
155///\r
1307dcd7 156GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTcp4ComponentName2 = {\r
83cbd279 157 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) TcpComponentNameGetDriverName,\r
158 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) TcpComponentNameGetControllerName,\r
159 "en"\r
1307dcd7 160};\r
83cbd279 161\r
8a67d61d 162\r
d1aeb0bd 163GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mTcpDriverNameTable[] = {\r
8a67d61d 164 {\r
83cbd279 165 "eng;en",\r
8a67d61d 166 L"Tcp Network Service Driver"\r
167 },\r
168 {\r
169 NULL,\r
170 NULL\r
171 }\r
172};\r
173\r
216f7970 174GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gTcpControllerNameTable = NULL;\r
175\r
83cbd279 176/**\r
177 Retrieves a Unicode string that is the user readable name of the driver.\r
178\r
179 This function retrieves the user readable name of a driver in the form of a\r
180 Unicode string. If the driver specified by This has a user readable name in\r
181 the language specified by Language, then a pointer to the driver name is\r
182 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
183 by This does not support the language specified by Language,\r
184 then EFI_UNSUPPORTED is returned.\r
185\r
dfc1f033 186 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 187 EFI_COMPONENT_NAME_PROTOCOL instance.\r
188\r
dfc1f033 189 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 190 array indicating the language. This is the\r
191 language of the driver name that the caller is\r
192 requesting, and it must match one of the\r
193 languages specified in SupportedLanguages. The\r
194 number of languages supported by a driver is up\r
195 to the driver writer. Language is specified\r
0254efc0 196 in RFC 4646 or ISO 639-2 language code format.\r
83cbd279 197\r
dfc1f033 198 @param[out] DriverName A pointer to the Unicode string to return.\r
83cbd279 199 This Unicode string is the name of the\r
200 driver specified by This in the language\r
201 specified by Language.\r
202\r
203 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
204 This and the language specified by Language was\r
205 returned in DriverName.\r
206\r
207 @retval EFI_INVALID_PARAMETER Language is NULL.\r
208\r
209 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
210\r
211 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
212 the language specified by Language.\r
213\r
214**/\r
8a67d61d 215EFI_STATUS\r
216EFIAPI\r
217TcpComponentNameGetDriverName (\r
dfc1f033 218 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
219 IN CHAR8 *Language,\r
220 OUT CHAR16 **DriverName\r
8a67d61d 221 )\r
83cbd279 222{\r
223 return LookupUnicodeString2 (\r
224 Language,\r
225 This->SupportedLanguages,\r
226 mTcpDriverNameTable,\r
227 DriverName,\r
77f00155 228 (BOOLEAN) (This == &gTcp4ComponentName)\r
83cbd279 229 );\r
230}\r
8a67d61d 231\r
216f7970 232/**\r
233 Update the component name for the Tcp4 child handle.\r
234\r
235 @param Tcp4[in] A pointer to the EFI_TCP4_PROTOCOL.\r
236\r
237 \r
238 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
239 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
240 \r
241**/\r
242EFI_STATUS\r
243UpdateName (\r
244 IN EFI_TCP4_PROTOCOL *Tcp4\r
245 )\r
246{\r
247 EFI_STATUS Status;\r
248 CHAR16 HandleName[80];\r
249 EFI_TCP4_CONFIG_DATA Tcp4ConfigData;\r
250\r
251 if (Tcp4 == NULL) {\r
252 return EFI_INVALID_PARAMETER;\r
253 }\r
254\r
255 //\r
256 // Format the child name into the string buffer as:\r
257 // TCPv4 (SrcPort=59, DestPort=60, ActiveFlag=TRUE)\r
258 //\r
259 Status = Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, NULL);\r
260 if (!EFI_ERROR (Status)) {\r
261 UnicodeSPrint (HandleName, sizeof (HandleName),\r
c5fba0fe 262 L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",\r
216f7970 263 Tcp4ConfigData.AccessPoint.StationPort,\r
264 Tcp4ConfigData.AccessPoint.RemotePort,\r
265 (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")\r
266 );\r
267 } if (Status == EFI_NOT_STARTED) {\r
268 UnicodeSPrint (\r
269 HandleName,\r
270 sizeof (HandleName),\r
271 L"TCPv4 (Not started)"\r
272 );\r
273 } else {\r
274 return Status;\r
275 }\r
276\r
277 if (gTcpControllerNameTable != NULL) {\r
278 FreeUnicodeStringTable (gTcpControllerNameTable);\r
279 gTcpControllerNameTable = NULL;\r
280 }\r
281 \r
282 Status = AddUnicodeString2 (\r
283 "eng",\r
284 gTcp4ComponentName.SupportedLanguages,\r
285 &gTcpControllerNameTable,\r
286 HandleName,\r
287 TRUE\r
288 );\r
289 if (EFI_ERROR (Status)) {\r
290 return Status;\r
291 }\r
292 \r
293 return AddUnicodeString2 (\r
294 "en",\r
295 gTcp4ComponentName2.SupportedLanguages,\r
296 &gTcpControllerNameTable,\r
297 HandleName,\r
298 FALSE\r
299 );\r
300}\r
301\r
83cbd279 302/**\r
303 Retrieves a Unicode string that is the user readable name of the controller\r
304 that is being managed by a driver.\r
8a67d61d 305\r
83cbd279 306 This function retrieves the user readable name of the controller specified by\r
307 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
308 driver specified by This has a user readable name in the language specified by\r
309 Language, then a pointer to the controller name is returned in ControllerName,\r
310 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
311 managing the controller specified by ControllerHandle and ChildHandle,\r
312 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
313 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
8a67d61d 314\r
dfc1f033 315 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 316 EFI_COMPONENT_NAME_PROTOCOL instance.\r
8a67d61d 317\r
dfc1f033 318 @param[in] ControllerHandle The handle of a controller that the driver\r
83cbd279 319 specified by This is managing. This handle\r
320 specifies the controller whose name is to be\r
321 returned.\r
8a67d61d 322\r
dfc1f033 323 @param[in] ChildHandle The handle of the child controller to retrieve\r
83cbd279 324 the name of. This is an optional parameter that\r
325 may be NULL. It will be NULL for device\r
326 drivers. It will also be NULL for a bus drivers\r
327 that wish to retrieve the name of the bus\r
328 controller. It will not be NULL for a bus\r
329 driver that wishes to retrieve the name of a\r
330 child controller.\r
8a67d61d 331\r
dfc1f033 332 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 333 array indicating the language. This is the\r
334 language of the driver name that the caller is\r
335 requesting, and it must match one of the\r
336 languages specified in SupportedLanguages. The\r
337 number of languages supported by a driver is up\r
338 to the driver writer. Language is specified in\r
0254efc0 339 RFC 4646 or ISO 639-2 language code format.\r
8a67d61d 340\r
dfc1f033 341 @param[out] ControllerName A pointer to the Unicode string to return.\r
83cbd279 342 This Unicode string is the name of the\r
343 controller specified by ControllerHandle and\r
344 ChildHandle in the language specified by\r
345 Language from the point of view of the driver\r
346 specified by This.\r
347\r
348 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
349 the language specified by Language for the\r
350 driver specified by This was returned in\r
351 DriverName.\r
352\r
284ee2e8 353 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
83cbd279 354\r
355 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
356 EFI_HANDLE.\r
357\r
358 @retval EFI_INVALID_PARAMETER Language is NULL.\r
359\r
360 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
361\r
362 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
363 managing the controller specified by\r
364 ControllerHandle and ChildHandle.\r
8a67d61d 365\r
83cbd279 366 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
367 the language specified by Language.\r
368\r
369**/\r
8a67d61d 370EFI_STATUS\r
371EFIAPI\r
372TcpComponentNameGetControllerName (\r
dfc1f033 373 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
374 IN EFI_HANDLE ControllerHandle,\r
375 IN EFI_HANDLE ChildHandle OPTIONAL,\r
376 IN CHAR8 *Language,\r
377 OUT CHAR16 **ControllerName\r
8a67d61d 378 )\r
8a67d61d 379{\r
216f7970 380 EFI_STATUS Status;\r
381 EFI_TCP4_PROTOCOL *Tcp4;\r
382\r
383 //\r
384 // Only provide names for child handles.\r
385 //\r
386 if (ChildHandle == NULL) {\r
387 return EFI_UNSUPPORTED;\r
388 }\r
389 \r
390 // \r
391 // Make sure this driver produced ChildHandle \r
392 // \r
393 Status = EfiTestChildHandle (\r
394 ControllerHandle,\r
395 ChildHandle,\r
396 &gEfiIp4ProtocolGuid\r
397 );\r
398 if (EFI_ERROR (Status)) {\r
399 return Status;\r
400 }\r
401\r
402 // \r
403 // Retrieve an instance of a produced protocol from ChildHandle\r
404 // \r
405 Status = gBS->OpenProtocol (\r
406 ChildHandle,\r
407 &gEfiTcp4ProtocolGuid,\r
408 (VOID **)&Tcp4,\r
409 NULL,\r
410 NULL,\r
411 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
412 );\r
413 if (EFI_ERROR (Status)) {\r
414 return Status;\r
415 }\r
416\r
417 //\r
418 // Update the component name for this child handle.\r
419 //\r
420 Status = UpdateName (Tcp4);\r
421 if (EFI_ERROR (Status)) {\r
422 return Status;\r
423 }\r
424\r
425 return LookupUnicodeString2 (\r
426 Language,\r
427 This->SupportedLanguages,\r
428 gTcpControllerNameTable,\r
429 ControllerName,\r
430 (BOOLEAN)(This == &gTcp4ComponentName)\r
431 );\r
8a67d61d 432}\r