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