]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/Mtftp4Dxe/ComponentName.c
MdeModulePkg/Mtftp4Dxe: Fix invalid configuration of MTFTP local port.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / ComponentName.c
... / ...
CommitLineData
1/** @file\r
2 UEFI Component Name(2) protocol implementation for Mtftp4Dxe driver.\r
3\r
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
8http://opensource.org/licenses/bsd-license.php<BR>\r
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
13**/\r
14\r
15#include "Mtftp4Impl.h"\r
16\r
17//\r
18// EFI Component Name Functions\r
19//\r
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
30 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
31 EFI_COMPONENT_NAME_PROTOCOL instance.\r
32\r
33 @param[in] Language A pointer to a Null-terminated ASCII string\r
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
40 in RFC 4646 or ISO 639-2 language code format.\r
41\r
42 @param[out] DriverName A pointer to the Unicode string to return.\r
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
59EFI_STATUS\r
60EFIAPI\r
61Mtftp4ComponentNameGetDriverName (\r
62 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
63 IN CHAR8 *Language,\r
64 OUT CHAR16 **DriverName\r
65 );\r
66\r
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
81 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
82 EFI_COMPONENT_NAME_PROTOCOL instance.\r
83\r
84 @param[in] ControllerHandle The handle of a controller that the driver\r
85 specified by This is managing. This handle\r
86 specifies the controller whose name is to be\r
87 returned.\r
88\r
89 @param[in] ChildHandle The handle of the child controller to retrieve\r
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
98 @param[in] Language A pointer to a Null-terminated ASCII string\r
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
105 RFC 4646 or ISO 639-2 language code format.\r
106\r
107 @param[out] ControllerName A pointer to the Unicode string to return.\r
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
119 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
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
136EFI_STATUS\r
137EFIAPI\r
138Mtftp4ComponentNameGetControllerName (\r
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
144 );\r
145\r
146\r
147///\r
148/// EFI Component Name Protocol\r
149///\r
150GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp4ComponentName = {\r
151 Mtftp4ComponentNameGetDriverName,\r
152 Mtftp4ComponentNameGetControllerName,\r
153 "eng"\r
154};\r
155\r
156///\r
157/// EFI Component Name 2 Protocol\r
158///\r
159GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp4ComponentName2 = {\r
160 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Mtftp4ComponentNameGetDriverName,\r
161 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Mtftp4ComponentNameGetControllerName,\r
162 "en"\r
163};\r
164\r
165\r
166GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp4DriverNameTable[] = {\r
167 {\r
168 "eng;en",\r
169 L"MTFTP4 Network Service"\r
170 },\r
171 {\r
172 NULL,\r
173 NULL\r
174 }\r
175};\r
176\r
177GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp4ControllerNameTable = NULL;\r
178\r
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
189 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
190 EFI_COMPONENT_NAME_PROTOCOL instance.\r
191\r
192 @param[in] Language A pointer to a Null-terminated ASCII string\r
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
199 in RFC 4646 or ISO 639-2 language code format.\r
200\r
201 @param[out] DriverName A pointer to the Unicode string to return.\r
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
218EFI_STATUS\r
219EFIAPI\r
220Mtftp4ComponentNameGetDriverName (\r
221 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
222 IN CHAR8 *Language,\r
223 OUT CHAR16 **DriverName\r
224 )\r
225{\r
226 return LookupUnicodeString2 (\r
227 Language,\r
228 This->SupportedLanguages,\r
229 mMtftp4DriverNameTable,\r
230 DriverName,\r
231 (BOOLEAN)(This == &gMtftp4ComponentName)\r
232 );\r
233}\r
234\r
235/**\r
236 Update the component name for the Mtftp4 child handle.\r
237\r
238 @param Mtftp4[in] A pointer to the EFI_MTFTP4_PROTOCOL.\r
239\r
240\r
241 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
242 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
243\r
244**/\r
245EFI_STATUS\r
246UpdateName (\r
247 IN EFI_MTFTP4_PROTOCOL *Mtftp4\r
248 )\r
249{\r
250 EFI_STATUS Status;\r
251 CHAR16 HandleName[80];\r
252 EFI_MTFTP4_MODE_DATA ModeData;\r
253\r
254 if (Mtftp4 == 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 // MTFTPv4 (ServerIp=192.168.1.10, ServerPort=69)\r
261 //\r
262 Status = Mtftp4->GetModeData (Mtftp4, &ModeData);\r
263 if (EFI_ERROR (Status)) {\r
264 return Status;\r
265 }\r
266\r
267 UnicodeSPrint (HandleName, sizeof (HandleName),\r
268 L"MTFTPv4 (ServerIp=%d.%d.%d.%d, ServerPort=%d)",\r
269 ModeData.ConfigData.ServerIp.Addr[0],\r
270 ModeData.ConfigData.ServerIp.Addr[1],\r
271 ModeData.ConfigData.ServerIp.Addr[2],\r
272 ModeData.ConfigData.ServerIp.Addr[3],\r
273 ModeData.ConfigData.InitialServerPort\r
274 );\r
275\r
276 if (gMtftp4ControllerNameTable != NULL) {\r
277 FreeUnicodeStringTable (gMtftp4ControllerNameTable);\r
278 gMtftp4ControllerNameTable = NULL;\r
279 }\r
280\r
281 Status = AddUnicodeString2 (\r
282 "eng",\r
283 gMtftp4ComponentName.SupportedLanguages,\r
284 &gMtftp4ControllerNameTable,\r
285 HandleName,\r
286 TRUE\r
287 );\r
288 if (EFI_ERROR (Status)) {\r
289 return Status;\r
290 }\r
291\r
292 return AddUnicodeString2 (\r
293 "en",\r
294 gMtftp4ComponentName2.SupportedLanguages,\r
295 &gMtftp4ControllerNameTable,\r
296 HandleName,\r
297 FALSE\r
298 );\r
299}\r
300\r
301/**\r
302 Retrieves a Unicode string that is the user readable name of the controller\r
303 that is being managed by a driver.\r
304\r
305 This function retrieves the user readable name of the controller specified by\r
306 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
307 driver specified by This has a user readable name in the language specified by\r
308 Language, then a pointer to the controller name is returned in ControllerName,\r
309 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
310 managing the controller specified by ControllerHandle and ChildHandle,\r
311 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
312 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
313\r
314 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
315 EFI_COMPONENT_NAME_PROTOCOL instance.\r
316\r
317 @param[in] ControllerHandle The handle of a controller that the driver\r
318 specified by This is managing. This handle\r
319 specifies the controller whose name is to be\r
320 returned.\r
321\r
322 @param[in] ChildHandle The handle of the child controller to retrieve\r
323 the name of. This is an optional parameter that\r
324 may be NULL. It will be NULL for device\r
325 drivers. It will also be NULL for a bus drivers\r
326 that wish to retrieve the name of the bus\r
327 controller. It will not be NULL for a bus\r
328 driver that wishes to retrieve the name of a\r
329 child controller.\r
330\r
331 @param[in] Language A pointer to a Null-terminated ASCII string\r
332 array indicating the language. This is the\r
333 language of the driver name that the caller is\r
334 requesting, and it must match one of the\r
335 languages specified in SupportedLanguages. The\r
336 number of languages supported by a driver is up\r
337 to the driver writer. Language is specified in\r
338 RFC 4646 or ISO 639-2 language code format.\r
339\r
340 @param[out] ControllerName A pointer to the Unicode string to return.\r
341 This Unicode string is the name of the\r
342 controller specified by ControllerHandle and\r
343 ChildHandle in the language specified by\r
344 Language from the point of view of the driver\r
345 specified by This.\r
346\r
347 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
348 the language specified by Language for the\r
349 driver specified by This was returned in\r
350 DriverName.\r
351\r
352 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
353\r
354 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
355 EFI_HANDLE.\r
356\r
357 @retval EFI_INVALID_PARAMETER Language is NULL.\r
358\r
359 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
360\r
361 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
362 managing the controller specified by\r
363 ControllerHandle and ChildHandle.\r
364\r
365 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
366 the language specified by Language.\r
367\r
368**/\r
369EFI_STATUS\r
370EFIAPI\r
371Mtftp4ComponentNameGetControllerName (\r
372 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
373 IN EFI_HANDLE ControllerHandle,\r
374 IN EFI_HANDLE ChildHandle OPTIONAL,\r
375 IN CHAR8 *Language,\r
376 OUT CHAR16 **ControllerName\r
377 )\r
378{\r
379 EFI_STATUS Status;\r
380 EFI_MTFTP4_PROTOCOL *Mtftp4;\r
381\r
382 //\r
383 // Only provide names for child handles.\r
384 //\r
385 if (ChildHandle == NULL) {\r
386 return EFI_UNSUPPORTED;\r
387 }\r
388\r
389 //\r
390 // Make sure this driver produced ChildHandle\r
391 //\r
392 Status = EfiTestChildHandle (\r
393 ControllerHandle,\r
394 ChildHandle,\r
395 &gEfiUdp4ProtocolGuid\r
396 );\r
397 if (EFI_ERROR (Status)) {\r
398 return Status;\r
399 }\r
400\r
401 //\r
402 // Retrieve an instance of a produced protocol from ChildHandle\r
403 //\r
404 Status = gBS->OpenProtocol (\r
405 ChildHandle,\r
406 &gEfiMtftp4ProtocolGuid,\r
407 (VOID **)&Mtftp4,\r
408 NULL,\r
409 NULL,\r
410 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
411 );\r
412 if (EFI_ERROR (Status)) {\r
413 return Status;\r
414 }\r
415\r
416 //\r
417 // Update the component name for this child handle.\r
418 //\r
419 Status = UpdateName (Mtftp4);\r
420 if (EFI_ERROR (Status)) {\r
421 return Status;\r
422 }\r
423\r
424 return LookupUnicodeString2 (\r
425 Language,\r
426 This->SupportedLanguages,\r
427 gMtftp4ControllerNameTable,\r
428 ControllerName,\r
429 (BOOLEAN)(This == &gMtftp4ComponentName)\r
430 );\r
431}\r