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