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