VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/Ip4Dxe/ComponentName.c@ 80721

Last change on this file since 80721 was 80721, checked in by vboxsync, 5 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • Property svn:eol-style set to native
File size: 16.5 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 Retrieves a Unicode string that is the user readable name of the driver.
15
16 This function retrieves the user readable name of a driver in the form of a
17 Unicode string. If the driver specified by This has a user readable name in
18 the language specified by Language, then a pointer to the driver name is
19 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
20 by This does not support the language specified by Language,
21 then EFI_UNSUPPORTED is returned.
22
23 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
24 EFI_COMPONENT_NAME_PROTOCOL instance.
25
26 @param[in] Language A pointer to a Null-terminated ASCII string
27 array indicating the language. This is the
28 language of the driver name that the caller is
29 requesting, and it must match one of the
30 languages specified in SupportedLanguages. The
31 number of languages supported by a driver is up
32 to the driver writer. Language is specified
33 in RFC 4646 or ISO 639-2 language code format.
34
35 @param[out] DriverName A pointer to the Unicode string to return.
36 This Unicode string is the name of the
37 driver specified by This in the language
38 specified by Language.
39
40 @retval EFI_SUCCESS The Unicode string for the Driver specified by
41 This and the language specified by Language was
42 returned in DriverName.
43
44 @retval EFI_INVALID_PARAMETER Language is NULL.
45
46 @retval EFI_INVALID_PARAMETER DriverName is NULL.
47
48 @retval EFI_UNSUPPORTED The driver specified by This does not support
49 the language specified by Language.
50
51**/
52EFI_STATUS
53EFIAPI
54Ip4ComponentNameGetDriverName (
55 IN EFI_COMPONENT_NAME_PROTOCOL *This,
56 IN CHAR8 *Language,
57 OUT CHAR16 **DriverName
58 );
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//
141// EFI Component Name Protocol
142//
143GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp4ComponentName = {
144 Ip4ComponentNameGetDriverName,
145 Ip4ComponentNameGetControllerName,
146 "eng"
147};
148
149//
150// EFI Component Name 2 Protocol
151//
152GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIp4ComponentName2 = {
153 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Ip4ComponentNameGetDriverName,
154 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Ip4ComponentNameGetControllerName,
155 "en"
156};
157
158
159GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp4DriverNameTable[] = {
160 {
161 "eng;en",
162 L"IP4 Network Service Driver"
163 },
164 {
165 NULL,
166 NULL
167 }
168};
169
170GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp4ControllerNameTable = 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**/
211EFI_STATUS
212EFIAPI
213Ip4ComponentNameGetDriverName (
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 mIp4DriverNameTable,
223 DriverName,
224 (BOOLEAN)(This == &gIp4ComponentName)
225 );
226
227}
228
229/**
230 Update the component name for the IP4 child handle.
231
232 @param Ip4[in] A pointer to the EFI_IP4_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**/
239EFI_STATUS
240UpdateName (
241 IN EFI_IP4_PROTOCOL *Ip4
242 )
243{
244 EFI_STATUS Status;
245 CHAR16 HandleName[80];
246 EFI_IP4_MODE_DATA Ip4ModeData;
247
248 if (Ip4 == NULL) {
249 return EFI_INVALID_PARAMETER;
250 }
251
252 //
253 // Format the child name into the string buffer as:
254 // IPv4 (SrcIP=127.0.0.1, DestIP=127.0.0.1)
255 //
256 Status = Ip4->GetModeData (Ip4, &Ip4ModeData, NULL, NULL);
257 if (EFI_ERROR (Status)) {
258 return Status;
259 }
260
261 if (!Ip4ModeData.IsStarted || !Ip4ModeData.IsConfigured) {
262 UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv4 (Not started)");
263 } else {
264 UnicodeSPrint (HandleName, sizeof (HandleName),
265 L"IPv4 (SrcIP=%d.%d.%d.%d)",
266 Ip4ModeData.ConfigData.StationAddress.Addr[0],
267 Ip4ModeData.ConfigData.StationAddress.Addr[1],
268 Ip4ModeData.ConfigData.StationAddress.Addr[2],
269 Ip4ModeData.ConfigData.StationAddress.Addr[3]
270 );
271 }
272
273 if (gIp4ControllerNameTable != NULL) {
274 FreeUnicodeStringTable (gIp4ControllerNameTable);
275 gIp4ControllerNameTable = NULL;
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}
428
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