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