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