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