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