]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Mtftp4Dxe/ComponentName.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Mtftp4Dxe / ComponentName.c
CommitLineData
772db4bb 1/** @file\r
dab714aa 2 UEFI Component Name(2) protocol implementation for Mtftp4Dxe driver.\r
d1102dba
LG
3\r
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
772db4bb 6\r
772db4bb 7**/\r
8\r
216f7970 9#include "Mtftp4Impl.h"\r
772db4bb 10\r
11//\r
12// EFI Component Name Functions\r
13//\r
d1050b9d 14\r
83cbd279 15/**\r
16 Retrieves a Unicode string that is the user readable name of the driver.\r
17\r
18 This function retrieves the user readable name of a driver in the form of a\r
19 Unicode string. If the driver specified by This has a user readable name in\r
20 the language specified by Language, then a pointer to the driver name is\r
21 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
22 by This does not support the language specified by Language,\r
23 then EFI_UNSUPPORTED is returned.\r
24\r
dab714aa 25 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 26 EFI_COMPONENT_NAME_PROTOCOL instance.\r
27\r
dab714aa 28 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 29 array indicating the language. This is the\r
30 language of the driver name that the caller is\r
31 requesting, and it must match one of the\r
32 languages specified in SupportedLanguages. The\r
33 number of languages supported by a driver is up\r
34 to the driver writer. Language is specified\r
0254efc0 35 in RFC 4646 or ISO 639-2 language code format.\r
83cbd279 36\r
dab714aa 37 @param[out] DriverName A pointer to the Unicode string to return.\r
83cbd279 38 This Unicode string is the name of the\r
39 driver specified by This in the language\r
40 specified by Language.\r
41\r
42 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
43 This and the language specified by Language was\r
44 returned in DriverName.\r
45\r
46 @retval EFI_INVALID_PARAMETER Language is NULL.\r
47\r
48 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
49\r
50 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
51 the language specified by Language.\r
52\r
53**/\r
772db4bb 54EFI_STATUS\r
55EFIAPI\r
56Mtftp4ComponentNameGetDriverName (\r
dab714aa 57 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
58 IN CHAR8 *Language,\r
d1050b9d 59 OUT CHAR16 **DriverName\r
772db4bb 60 );\r
61\r
83cbd279 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
dab714aa 75 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 76 EFI_COMPONENT_NAME_PROTOCOL instance.\r
77\r
dab714aa 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
dab714aa 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
dab714aa 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
dab714aa 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
772db4bb 130EFI_STATUS\r
131EFIAPI\r
132Mtftp4ComponentNameGetControllerName (\r
d1050b9d
MK
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
772db4bb 138 );\r
139\r
dab714aa 140///\r
141/// EFI Component Name Protocol\r
142///\r
1307dcd7 143GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp4ComponentName = {\r
772db4bb 144 Mtftp4ComponentNameGetDriverName,\r
145 Mtftp4ComponentNameGetControllerName,\r
146 "eng"\r
1307dcd7 147};\r
83cbd279 148\r
dab714aa 149///\r
150/// EFI Component Name 2 Protocol\r
151///\r
d1050b9d
MK
152GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp4ComponentName2 = {\r
153 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Mtftp4ComponentNameGetDriverName,\r
154 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Mtftp4ComponentNameGetControllerName,\r
83cbd279 155 "en"\r
1307dcd7 156};\r
83cbd279 157\r
d1050b9d 158GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp4DriverNameTable[] = {\r
772db4bb 159 {\r
83cbd279 160 "eng;en",\r
772db4bb 161 L"MTFTP4 Network Service"\r
162 },\r
163 {\r
164 NULL,\r
165 NULL\r
166 }\r
167};\r
168\r
d1050b9d 169GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp4ControllerNameTable = NULL;\r
216f7970 170\r
83cbd279 171/**\r
172 Retrieves a Unicode string that is the user readable name of the driver.\r
173\r
174 This function retrieves the user readable name of a driver in the form of a\r
175 Unicode string. If the driver specified by This has a user readable name in\r
176 the language specified by Language, then a pointer to the driver name is\r
177 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
178 by This does not support the language specified by Language,\r
179 then EFI_UNSUPPORTED is returned.\r
180\r
dab714aa 181 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 182 EFI_COMPONENT_NAME_PROTOCOL instance.\r
183\r
dab714aa 184 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 185 array indicating the language. This is the\r
186 language of the driver name that the caller is\r
187 requesting, and it must match one of the\r
188 languages specified in SupportedLanguages. The\r
189 number of languages supported by a driver is up\r
190 to the driver writer. Language is specified\r
0254efc0 191 in RFC 4646 or ISO 639-2 language code format.\r
83cbd279 192\r
dab714aa 193 @param[out] DriverName A pointer to the Unicode string to return.\r
83cbd279 194 This Unicode string is the name of the\r
195 driver specified by This in the language\r
196 specified by Language.\r
197\r
198 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
199 This and the language specified by Language was\r
200 returned in DriverName.\r
201\r
202 @retval EFI_INVALID_PARAMETER Language is NULL.\r
203\r
204 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
205\r
206 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
207 the language specified by Language.\r
208\r
209**/\r
772db4bb 210EFI_STATUS\r
211EFIAPI\r
212Mtftp4ComponentNameGetDriverName (\r
dab714aa 213 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
214 IN CHAR8 *Language,\r
d1050b9d 215 OUT CHAR16 **DriverName\r
772db4bb 216 )\r
772db4bb 217{\r
83cbd279 218 return LookupUnicodeString2 (\r
219 Language,\r
220 This->SupportedLanguages,\r
221 mMtftp4DriverNameTable,\r
222 DriverName,\r
223 (BOOLEAN)(This == &gMtftp4ComponentName)\r
224 );\r
772db4bb 225}\r
226\r
216f7970 227/**\r
228 Update the component name for the Mtftp4 child handle.\r
229\r
230 @param Mtftp4[in] A pointer to the EFI_MTFTP4_PROTOCOL.\r
231\r
d1102dba 232\r
216f7970 233 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
234 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
d1102dba 235\r
216f7970 236**/\r
237EFI_STATUS\r
238UpdateName (\r
d1050b9d 239 IN EFI_MTFTP4_PROTOCOL *Mtftp4\r
216f7970 240 )\r
241{\r
d1050b9d
MK
242 EFI_STATUS Status;\r
243 CHAR16 HandleName[80];\r
244 EFI_MTFTP4_MODE_DATA ModeData;\r
216f7970 245\r
246 if (Mtftp4 == NULL) {\r
247 return EFI_INVALID_PARAMETER;\r
248 }\r
249\r
250 //\r
251 // Format the child name into the string buffer as:\r
252 // MTFTPv4 (ServerIp=192.168.1.10, ServerPort=69)\r
253 //\r
254 Status = Mtftp4->GetModeData (Mtftp4, &ModeData);\r
255 if (EFI_ERROR (Status)) {\r
256 return Status;\r
257 }\r
258\r
d1050b9d
MK
259 UnicodeSPrint (\r
260 HandleName,\r
261 sizeof (HandleName),\r
216f7970 262 L"MTFTPv4 (ServerIp=%d.%d.%d.%d, ServerPort=%d)",\r
263 ModeData.ConfigData.ServerIp.Addr[0],\r
264 ModeData.ConfigData.ServerIp.Addr[1],\r
265 ModeData.ConfigData.ServerIp.Addr[2],\r
266 ModeData.ConfigData.ServerIp.Addr[3],\r
267 ModeData.ConfigData.InitialServerPort\r
268 );\r
269\r
270 if (gMtftp4ControllerNameTable != NULL) {\r
271 FreeUnicodeStringTable (gMtftp4ControllerNameTable);\r
272 gMtftp4ControllerNameTable = NULL;\r
273 }\r
d1102dba 274\r
216f7970 275 Status = AddUnicodeString2 (\r
276 "eng",\r
277 gMtftp4ComponentName.SupportedLanguages,\r
278 &gMtftp4ControllerNameTable,\r
279 HandleName,\r
280 TRUE\r
281 );\r
282 if (EFI_ERROR (Status)) {\r
283 return Status;\r
284 }\r
d1102dba 285\r
216f7970 286 return AddUnicodeString2 (\r
287 "en",\r
288 gMtftp4ComponentName2.SupportedLanguages,\r
289 &gMtftp4ControllerNameTable,\r
290 HandleName,\r
291 FALSE\r
292 );\r
293}\r
294\r
83cbd279 295/**\r
296 Retrieves a Unicode string that is the user readable name of the controller\r
297 that is being managed by a driver.\r
298\r
299 This function retrieves the user readable name of the controller specified by\r
300 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
301 driver specified by This has a user readable name in the language specified by\r
302 Language, then a pointer to the controller name is returned in ControllerName,\r
303 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
304 managing the controller specified by ControllerHandle and ChildHandle,\r
305 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
306 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
307\r
dab714aa 308 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83cbd279 309 EFI_COMPONENT_NAME_PROTOCOL instance.\r
310\r
dab714aa 311 @param[in] ControllerHandle The handle of a controller that the driver\r
83cbd279 312 specified by This is managing. This handle\r
313 specifies the controller whose name is to be\r
314 returned.\r
315\r
dab714aa 316 @param[in] ChildHandle The handle of the child controller to retrieve\r
83cbd279 317 the name of. This is an optional parameter that\r
318 may be NULL. It will be NULL for device\r
319 drivers. It will also be NULL for a bus drivers\r
320 that wish to retrieve the name of the bus\r
321 controller. It will not be NULL for a bus\r
322 driver that wishes to retrieve the name of a\r
323 child controller.\r
324\r
dab714aa 325 @param[in] Language A pointer to a Null-terminated ASCII string\r
83cbd279 326 array indicating the language. This is the\r
327 language of the driver name that the caller is\r
328 requesting, and it must match one of the\r
329 languages specified in SupportedLanguages. The\r
330 number of languages supported by a driver is up\r
331 to the driver writer. Language is specified in\r
0254efc0 332 RFC 4646 or ISO 639-2 language code format.\r
83cbd279 333\r
dab714aa 334 @param[out] ControllerName A pointer to the Unicode string to return.\r
83cbd279 335 This Unicode string is the name of the\r
336 controller specified by ControllerHandle and\r
337 ChildHandle in the language specified by\r
338 Language from the point of view of the driver\r
339 specified by This.\r
340\r
341 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
342 the language specified by Language for the\r
343 driver specified by This was returned in\r
344 DriverName.\r
345\r
284ee2e8 346 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
83cbd279 347\r
348 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
349 EFI_HANDLE.\r
350\r
351 @retval EFI_INVALID_PARAMETER Language is NULL.\r
352\r
353 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
354\r
355 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
356 managing the controller specified by\r
357 ControllerHandle and ChildHandle.\r
358\r
359 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
360 the language specified by Language.\r
361\r
362**/\r
772db4bb 363EFI_STATUS\r
364EFIAPI\r
365Mtftp4ComponentNameGetControllerName (\r
d1050b9d
MK
366 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
367 IN EFI_HANDLE ControllerHandle,\r
368 IN EFI_HANDLE ChildHandle OPTIONAL,\r
369 IN CHAR8 *Language,\r
370 OUT CHAR16 **ControllerName\r
772db4bb 371 )\r
772db4bb 372{\r
d1050b9d
MK
373 EFI_STATUS Status;\r
374 EFI_MTFTP4_PROTOCOL *Mtftp4;\r
216f7970 375\r
376 //\r
377 // Only provide names for child handles.\r
378 //\r
379 if (ChildHandle == NULL) {\r
380 return EFI_UNSUPPORTED;\r
381 }\r
d1102dba
LG
382\r
383 //\r
384 // Make sure this driver produced ChildHandle\r
385 //\r
216f7970 386 Status = EfiTestChildHandle (\r
387 ControllerHandle,\r
388 ChildHandle,\r
389 &gEfiUdp4ProtocolGuid\r
390 );\r
391 if (EFI_ERROR (Status)) {\r
392 return Status;\r
393 }\r
394\r
d1102dba 395 //\r
216f7970 396 // Retrieve an instance of a produced protocol from ChildHandle\r
d1102dba 397 //\r
216f7970 398 Status = gBS->OpenProtocol (\r
399 ChildHandle,\r
400 &gEfiMtftp4ProtocolGuid,\r
401 (VOID **)&Mtftp4,\r
402 NULL,\r
403 NULL,\r
404 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
405 );\r
406 if (EFI_ERROR (Status)) {\r
407 return Status;\r
408 }\r
409\r
410 //\r
411 // Update the component name for this child handle.\r
412 //\r
413 Status = UpdateName (Mtftp4);\r
414 if (EFI_ERROR (Status)) {\r
415 return Status;\r
416 }\r
417\r
418 return LookupUnicodeString2 (\r
419 Language,\r
420 This->SupportedLanguages,\r
421 gMtftp4ControllerNameTable,\r
422 ControllerName,\r
423 (BOOLEAN)(This == &gMtftp4ComponentName)\r
424 );\r
772db4bb 425}\r