VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip4Dxe/ComponentName.c

Last change on this file was 99404, checked in by vboxsync, 19 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 16.2 KB
Line 
1/** @file
2
3Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
4SPDX-License-Identifier: BSD-2-Clause-Patent
5
6**/
7
8#include "Ip4Impl.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**/
53EFI_STATUS
54EFIAPI
55Ip4ComponentNameGetDriverName (
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**/
129EFI_STATUS
130EFIAPI
131Ip4ComponentNameGetControllerName (
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//
142GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp4ComponentName = {
143 Ip4ComponentNameGetDriverName,
144 Ip4ComponentNameGetControllerName,
145 "eng"
146};
147
148//
149// EFI Component Name 2 Protocol
150//
151GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIp4ComponentName2 = {
152 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Ip4ComponentNameGetDriverName,
153 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Ip4ComponentNameGetControllerName,
154 "en"
155};
156
157GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp4DriverNameTable[] = {
158 {
159 "eng;en",
160 L"IP4 Network Service Driver"
161 },
162 {
163 NULL,
164 NULL
165 }
166};
167
168GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp4ControllerNameTable = 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**/
209EFI_STATUS
210EFIAPI
211Ip4ComponentNameGetDriverName (
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 mIp4DriverNameTable,
221 DriverName,
222 (BOOLEAN)(This == &gIp4ComponentName)
223 );
224}
225
226/**
227 Update the component name for the IP4 child handle.
228
229 @param Ip4[in] A pointer to the EFI_IP4_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**/
236EFI_STATUS
237UpdateName (
238 IN EFI_IP4_PROTOCOL *Ip4
239 )
240{
241 EFI_STATUS Status;
242 CHAR16 HandleName[80];
243 EFI_IP4_MODE_DATA Ip4ModeData;
244
245 if (Ip4 == NULL) {
246 return EFI_INVALID_PARAMETER;
247 }
248
249 //
250 // Format the child name into the string buffer as:
251 // IPv4 (SrcIP=127.0.0.1, DestIP=127.0.0.1)
252 //
253 Status = Ip4->GetModeData (Ip4, &Ip4ModeData, NULL, NULL);
254 if (EFI_ERROR (Status)) {
255 return Status;
256 }
257
258 if (!Ip4ModeData.IsStarted || !Ip4ModeData.IsConfigured) {
259 UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv4 (Not started)");
260 } else {
261 UnicodeSPrint (
262 HandleName,
263 sizeof (HandleName),
264 L"IPv4 (SrcIP=%d.%d.%d.%d)",
265 Ip4ModeData.ConfigData.StationAddress.Addr[0],
266 Ip4ModeData.ConfigData.StationAddress.Addr[1],
267 Ip4ModeData.ConfigData.StationAddress.Addr[2],
268 Ip4ModeData.ConfigData.StationAddress.Addr[3]
269 );
270 }
271
272 if (gIp4ControllerNameTable != NULL) {
273 FreeUnicodeStringTable (gIp4ControllerNameTable);
274 gIp4ControllerNameTable = NULL;
275 }
276
277 Status = AddUnicodeString2 (
278 "eng",
279 gIp4ComponentName.SupportedLanguages,
280 &gIp4ControllerNameTable,
281 HandleName,
282 TRUE
283 );
284 if (EFI_ERROR (Status)) {
285 return Status;
286 }
287
288 return AddUnicodeString2 (
289 "en",
290 gIp4ComponentName2.SupportedLanguages,
291 &gIp4ControllerNameTable,
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**/
365EFI_STATUS
366EFIAPI
367Ip4ComponentNameGetControllerName (
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_IP4_PROTOCOL *Ip4;
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 &gEfiManagedNetworkProtocolGuid
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 &gEfiIp4ProtocolGuid,
403 (VOID **)&Ip4,
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 (Ip4);
416 if (EFI_ERROR (Status)) {
417 return Status;
418 }
419
420 return LookupUnicodeString2 (
421 Language,
422 This->SupportedLanguages,
423 gIp4ControllerNameTable,
424 ControllerName,
425 (BOOLEAN)(This == &gIp4ComponentName)
426 );
427}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette