]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c
Initialize data and correct faulty logic in TcpComponentNameGetControllerName().
[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
35a26499 4Copyright (c) 2005 - 2015, 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
35a26499 259 ZeroMem (&Tcp4ConfigData, sizeof (Tcp4ConfigData));\r
216f7970 260 Status = Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, NULL);\r
261 if (!EFI_ERROR (Status)) {\r
262 UnicodeSPrint (HandleName, sizeof (HandleName),\r
c5fba0fe 263 L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",\r
216f7970 264 Tcp4ConfigData.AccessPoint.StationPort,\r
265 Tcp4ConfigData.AccessPoint.RemotePort,\r
266 (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")\r
267 );\r
35a26499 268 } else if (Status == EFI_NOT_STARTED) {\r
216f7970 269 UnicodeSPrint (\r
270 HandleName,\r
271 sizeof (HandleName),\r
272 L"TCPv4 (Not started)"\r
273 );\r
274 } else {\r
275 return Status;\r
276 }\r
277\r
278 if (gTcpControllerNameTable != NULL) {\r
279 FreeUnicodeStringTable (gTcpControllerNameTable);\r
280 gTcpControllerNameTable = NULL;\r
281 }\r
282 \r
283 Status = AddUnicodeString2 (\r
284 "eng",\r
285 gTcp4ComponentName.SupportedLanguages,\r
286 &gTcpControllerNameTable,\r
287 HandleName,\r
288 TRUE\r
289 );\r
290 if (EFI_ERROR (Status)) {\r
291 return Status;\r
292 }\r
293 \r
294 return AddUnicodeString2 (\r
295 "en",\r
296 gTcp4ComponentName2.SupportedLanguages,\r
297 &gTcpControllerNameTable,\r
298 HandleName,\r
299 FALSE\r
300 );\r
301}\r
302\r
83cbd279 303/**\r
304 Retrieves a Unicode string that is the user readable name of the controller\r
305 that is being managed by a driver.\r
8a67d61d 306\r
83cbd279 307 This function retrieves the user readable name of the controller specified by\r
308 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
309 driver specified by This has a user readable name in the language specified by\r
310 Language, then a pointer to the controller name is returned in ControllerName,\r
311 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
312 managing the controller specified by ControllerHandle and ChildHandle,\r
313 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
314 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
8a67d61d 315\r
dfc1f033 316 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 317 EFI_COMPONENT_NAME_PROTOCOL instance.\r
8a67d61d 318\r
dfc1f033 319 @param[in] ControllerHandle The handle of a controller that the driver\r
83cbd279 320 specified by This is managing. This handle\r
321 specifies the controller whose name is to be\r
322 returned.\r
8a67d61d 323\r
dfc1f033 324 @param[in] ChildHandle The handle of the child controller to retrieve\r
83cbd279 325 the name of. This is an optional parameter that\r
326 may be NULL. It will be NULL for device\r
327 drivers. It will also be NULL for a bus drivers\r
328 that wish to retrieve the name of the bus\r
329 controller. It will not be NULL for a bus\r
330 driver that wishes to retrieve the name of a\r
331 child controller.\r
8a67d61d 332\r
dfc1f033 333 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 334 array indicating the language. This is the\r
335 language of the driver name that the caller is\r
336 requesting, and it must match one of the\r
337 languages specified in SupportedLanguages. The\r
338 number of languages supported by a driver is up\r
339 to the driver writer. Language is specified in\r
0254efc0 340 RFC 4646 or ISO 639-2 language code format.\r
8a67d61d 341\r
dfc1f033 342 @param[out] ControllerName A pointer to the Unicode string to return.\r
83cbd279 343 This Unicode string is the name of the\r
344 controller specified by ControllerHandle and\r
345 ChildHandle in the language specified by\r
346 Language from the point of view of the driver\r
347 specified by This.\r
348\r
349 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
350 the language specified by Language for the\r
351 driver specified by This was returned in\r
352 DriverName.\r
353\r
284ee2e8 354 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
83cbd279 355\r
356 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
357 EFI_HANDLE.\r
358\r
359 @retval EFI_INVALID_PARAMETER Language is NULL.\r
360\r
361 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
362\r
363 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
364 managing the controller specified by\r
365 ControllerHandle and ChildHandle.\r
8a67d61d 366\r
83cbd279 367 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
368 the language specified by Language.\r
369\r
370**/\r
8a67d61d 371EFI_STATUS\r
372EFIAPI\r
373TcpComponentNameGetControllerName (\r
dfc1f033 374 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
375 IN EFI_HANDLE ControllerHandle,\r
376 IN EFI_HANDLE ChildHandle OPTIONAL,\r
377 IN CHAR8 *Language,\r
378 OUT CHAR16 **ControllerName\r
8a67d61d 379 )\r
8a67d61d 380{\r
216f7970 381 EFI_STATUS Status;\r
382 EFI_TCP4_PROTOCOL *Tcp4;\r
383\r
384 //\r
385 // Only provide names for child handles.\r
386 //\r
387 if (ChildHandle == NULL) {\r
388 return EFI_UNSUPPORTED;\r
389 }\r
390 \r
391 // \r
392 // Make sure this driver produced ChildHandle \r
393 // \r
394 Status = EfiTestChildHandle (\r
395 ControllerHandle,\r
396 ChildHandle,\r
397 &gEfiIp4ProtocolGuid\r
398 );\r
399 if (EFI_ERROR (Status)) {\r
400 return Status;\r
401 }\r
402\r
403 // \r
404 // Retrieve an instance of a produced protocol from ChildHandle\r
405 // \r
406 Status = gBS->OpenProtocol (\r
407 ChildHandle,\r
408 &gEfiTcp4ProtocolGuid,\r
409 (VOID **)&Tcp4,\r
410 NULL,\r
411 NULL,\r
412 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
413 );\r
414 if (EFI_ERROR (Status)) {\r
415 return Status;\r
416 }\r
417\r
418 //\r
419 // Update the component name for this child handle.\r
420 //\r
421 Status = UpdateName (Tcp4);\r
422 if (EFI_ERROR (Status)) {\r
423 return Status;\r
424 }\r
425\r
426 return LookupUnicodeString2 (\r
427 Language,\r
428 This->SupportedLanguages,\r
429 gTcpControllerNameTable,\r
430 ControllerName,\r
431 (BOOLEAN)(This == &gTcp4ComponentName)\r
432 );\r
8a67d61d 433}\r