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