]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Udp6Dxe/ComponentName.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Udp6Dxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for UDP6 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 "Udp6Impl.h"
11
12 //
13 // EFI Component Name Functions
14 //
15
16 /**
17 Retrieves a Unicode string that is the user-readable name of the driver.
18
19 This function retrieves the user-readable name of a driver in the form of a
20 Unicode string. If the driver specified by This has a user-readable name in
21 the language specified by Language, then a pointer to the driver name is
22 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
23 by This does not support the language specified by Language,
24 then EFI_UNSUPPORTED is returned.
25
26 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
27 EFI_COMPONENT_NAME_PROTOCOL instance.
28
29 @param[in] Language A pointer to a Null-terminated ASCII string
30 array indicating the language. This is the
31 language of the driver name that the caller is
32 requesting, and it must match one of the
33 languages specified in SupportedLanguages. The
34 number of languages supported by a driver is up
35 to the driver writer. Language is specified
36 in RFC 4646 or ISO 639-2 language code format.
37
38 @param[out] DriverName A pointer to the Unicode string to return.
39 This Unicode string is the name of the
40 driver specified by This in the language
41 specified by Language.
42
43 @retval EFI_SUCCESS The Unicode string for the Driver specified by
44 This and the language specified by Language was
45 returned in DriverName.
46
47 @retval EFI_INVALID_PARAMETER Language is NULL.
48
49 @retval EFI_INVALID_PARAMETER DriverName is NULL.
50
51 @retval EFI_UNSUPPORTED The driver specified by This does not support
52 the language specified by Language.
53
54 **/
55 EFI_STATUS
56 EFIAPI
57 Udp6ComponentNameGetDriverName (
58 IN EFI_COMPONENT_NAME_PROTOCOL *This,
59 IN CHAR8 *Language,
60 OUT CHAR16 **DriverName
61 );
62
63 /**
64 Retrieves a Unicode string that is the user-readable name of the controller
65 that is being managed by a driver.
66
67 This function retrieves the user-readable name of the controller specified by
68 ControllerHandle and ChildHandle in the form of a Unicode string. If the
69 driver specified by This has a user-readable name in the language specified by
70 Language, then a pointer to the controller name is returned in ControllerName,
71 and EFI_SUCCESS is returned. If the driver specified by This is not currently
72 managing the controller specified by ControllerHandle and ChildHandle,
73 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
74 support the language specified by Language, then EFI_UNSUPPORTED is returned.
75
76 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
77 EFI_COMPONENT_NAME_PROTOCOL instance.
78
79 @param[in] ControllerHandle The handle of a controller that the driver
80 specified by This is managing. This handle
81 specifies the controller whose name is to be
82 returned.
83
84 @param[in] ChildHandle The handle of the child controller to retrieve
85 the name of. This is an optional parameter that
86 may be NULL. It will be NULL for device
87 drivers. It will also be NULL for a bus drivers
88 that wish to retrieve the name of the bus
89 controller. It will not be NULL for a bus
90 driver that wishes to retrieve the name of a
91 child controller.
92
93 @param[in] Language A pointer to a Null-terminated ASCII string
94 array indicating the language. This is the
95 language of the driver name that the caller is
96 requesting, and it must match one of the
97 languages specified in SupportedLanguages. The
98 number of languages supported by a driver is up
99 to the driver writer. Language is specified in
100 RFC 4646 or ISO 639-2 language code format.
101
102 @param[out] ControllerName A pointer to the Unicode string to return.
103 This Unicode string is the name of the
104 controller specified by ControllerHandle and
105 ChildHandle in the language specified by
106 Language from the point of view of the driver
107 specified by This.
108
109 @retval EFI_SUCCESS The Unicode string for the user-readable name in
110 the language specified by Language for the
111 driver specified by This was returned in
112 DriverName.
113
114 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
115
116 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
117 EFI_HANDLE.
118
119 @retval EFI_INVALID_PARAMETER Language is NULL.
120
121 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
122
123 @retval EFI_UNSUPPORTED The driver specified by This is not currently
124 managing the controller specified by
125 ControllerHandle and ChildHandle.
126
127 @retval EFI_UNSUPPORTED The driver specified by This does not support
128 the language specified by Language.
129
130 **/
131 EFI_STATUS
132 EFIAPI
133 Udp6ComponentNameGetControllerName (
134 IN EFI_COMPONENT_NAME_PROTOCOL *This,
135 IN EFI_HANDLE ControllerHandle,
136 IN EFI_HANDLE ChildHandle OPTIONAL,
137 IN CHAR8 *Language,
138 OUT CHAR16 **ControllerName
139 );
140
141 //
142 // EFI Component Name Protocol
143 //
144 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUdp6ComponentName = {
145 Udp6ComponentNameGetDriverName,
146 Udp6ComponentNameGetControllerName,
147 "eng"
148 };
149
150 //
151 // EFI Component Name 2 Protocol
152 //
153 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUdp6ComponentName2 = {
154 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Udp6ComponentNameGetDriverName,
155 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Udp6ComponentNameGetControllerName,
156 "en"
157 };
158
159 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUdp6DriverNameTable[] = {
160 {
161 "eng;en",
162 L"UDP6 Network Service Driver"
163 },
164 {
165 NULL,
166 NULL
167 }
168 };
169
170 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gUdp6ControllerNameTable = NULL;
171
172 /**
173 Retrieves a Unicode string that is the user-readable name of the driver.
174
175 This function retrieves the user-readable name of a driver in the form of a
176 Unicode string. If the driver specified by This has a user-readable name in
177 the language specified by Language, then a pointer to the driver name is
178 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
179 by This does not support the language specified by Language,
180 then EFI_UNSUPPORTED is returned.
181
182 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
183 EFI_COMPONENT_NAME_PROTOCOL instance.
184
185 @param[in] Language A pointer to a Null-terminated ASCII string
186 array indicating the language. This is the
187 language of the driver name that the caller is
188 requesting, and it must match one of the
189 languages specified in SupportedLanguages. The
190 number of languages supported by a driver is up
191 to the driver writer. Language is specified
192 in RFC 4646 or ISO 639-2 language code format.
193
194 @param[out] DriverName A pointer to the Unicode string to return.
195 This Unicode string is the name of the
196 driver specified by This in the language
197 specified by Language.
198
199 @retval EFI_SUCCESS The Unicode string for the Driver specified by
200 This and the language specified by Language was
201 returned in DriverName.
202
203 @retval EFI_INVALID_PARAMETER Language is NULL.
204
205 @retval EFI_INVALID_PARAMETER DriverName is NULL.
206
207 @retval EFI_UNSUPPORTED The driver specified by This does not support
208 the language specified by Language.
209
210 **/
211 EFI_STATUS
212 EFIAPI
213 Udp6ComponentNameGetDriverName (
214 IN EFI_COMPONENT_NAME_PROTOCOL *This,
215 IN CHAR8 *Language,
216 OUT CHAR16 **DriverName
217 )
218 {
219 return LookupUnicodeString2 (
220 Language,
221 This->SupportedLanguages,
222 mUdp6DriverNameTable,
223 DriverName,
224 (BOOLEAN)(This == &gUdp6ComponentName)
225 );
226 }
227
228 /**
229 Update the component name for the Udp6 child handle.
230
231 @param Udp6[in] A pointer to the EFI_UDP6_PROTOCOL.
232
233
234 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
235 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
236
237 **/
238 EFI_STATUS
239 UpdateName (
240 IN EFI_UDP6_PROTOCOL *Udp6
241 )
242 {
243 EFI_STATUS Status;
244 CHAR16 HandleName[64];
245 EFI_UDP6_CONFIG_DATA Udp6ConfigData;
246
247 if (Udp6 == NULL) {
248 return EFI_INVALID_PARAMETER;
249 }
250
251 //
252 // Format the child name into the string buffer.
253 //
254 Status = Udp6->GetModeData (Udp6, &Udp6ConfigData, NULL, NULL, NULL);
255 if (!EFI_ERROR (Status)) {
256 UnicodeSPrint (
257 HandleName,
258 sizeof (HandleName),
259 L"UDPv6 (SrcPort=%d, DestPort=%d)",
260 Udp6ConfigData.StationPort,
261 Udp6ConfigData.RemotePort
262 );
263 } else if (Status == EFI_NOT_STARTED) {
264 UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (Not started)");
265 } else {
266 UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (%r)", Status);
267 }
268
269 if (gUdp6ControllerNameTable != NULL) {
270 FreeUnicodeStringTable (gUdp6ControllerNameTable);
271 gUdp6ControllerNameTable = NULL;
272 }
273
274 Status = AddUnicodeString2 (
275 "eng",
276 gUdp6ComponentName.SupportedLanguages,
277 &gUdp6ControllerNameTable,
278 HandleName,
279 TRUE
280 );
281 if (EFI_ERROR (Status)) {
282 return Status;
283 }
284
285 return AddUnicodeString2 (
286 "en",
287 gUdp6ComponentName2.SupportedLanguages,
288 &gUdp6ControllerNameTable,
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 that wish to retrieve the name of the bus
320 controller. It will not be NULL for a bus
321 driver that wishes 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 Udp6ComponentNameGetControllerName (
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_UDP6_PROTOCOL *Udp6;
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 &gEfiIp6ProtocolGuid
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 &gEfiUdp6ProtocolGuid,
400 (VOID **)&Udp6,
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 (Udp6);
413 if (EFI_ERROR (Status)) {
414 return Status;
415 }
416
417 return LookupUnicodeString2 (
418 Language,
419 This->SupportedLanguages,
420 gUdp6ControllerNameTable,
421 ControllerName,
422 (BOOLEAN)(This == &gUdp6ComponentName)
423 );
424 }