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