]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for SnpDxe driver.
3
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9
10 #include "Snp.h"
11
12 //
13 // EFI Component Name Functions
14 //
15 /**
16 Retrieves a Unicode string that is the user readable name of the driver.
17
18 This function retrieves the user readable name of a driver in the form of a
19 Unicode string. If the driver specified by This has a user readable name in
20 the language specified by Language, then a pointer to the driver name is
21 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
22 by This does not support the language specified by Language,
23 then EFI_UNSUPPORTED is returned.
24
25 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
26 EFI_COMPONENT_NAME_PROTOCOL instance.
27
28 @param Language[in] A pointer to a Null-terminated ASCII string
29 array indicating the language. This is the
30 language of the driver name that the caller is
31 requesting, and it must match one of the
32 languages specified in SupportedLanguages. The
33 number of languages supported by a driver is up
34 to the driver writer. Language is specified
35 in RFC 4646 or ISO 639-2 language code format.
36
37 @param DriverName[out] A pointer to the Unicode string to return.
38 This Unicode string is the name of the
39 driver specified by This in the language
40 specified by Language.
41
42 @retval EFI_SUCCESS The Unicode string for the Driver specified by
43 This and the language specified by Language was
44 returned in DriverName.
45
46 @retval EFI_INVALID_PARAMETER Language is NULL.
47
48 @retval EFI_INVALID_PARAMETER DriverName is NULL.
49
50 @retval EFI_UNSUPPORTED The driver specified by This does not support
51 the language specified by Language.
52
53 **/
54 EFI_STATUS
55 EFIAPI
56 SimpleNetworkComponentNameGetDriverName (
57 IN EFI_COMPONENT_NAME_PROTOCOL *This,
58 IN CHAR8 *Language,
59 OUT CHAR16 **DriverName
60 );
61
62
63 /**
64 Retrieves a Unicode string that is the user readable name of the controller
65 that is being managed by a driver.
66
67 This function retrieves the user readable name of the controller specified by
68 ControllerHandle and ChildHandle in the form of a Unicode string. If the
69 driver specified by This has a user readable name in the language specified by
70 Language, then a pointer to the controller name is returned in ControllerName,
71 and EFI_SUCCESS is returned. If the driver specified by This is not currently
72 managing the controller specified by ControllerHandle and ChildHandle,
73 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
74 support the language specified by Language, then EFI_UNSUPPORTED is returned.
75
76 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
77 EFI_COMPONENT_NAME_PROTOCOL instance.
78
79 @param ControllerHandle[in] The handle of a controller that the driver
80 specified by This is managing. This handle
81 specifies the controller whose name is to be
82 returned.
83
84 @param ChildHandle[in] The handle of the child controller to retrieve
85 the name of. This is an optional parameter that
86 may be NULL. It will be NULL for device
87 drivers. It will also be NULL for a bus drivers
88 that wish to retrieve the name of the bus
89 controller. It will not be NULL for a bus
90 driver that wishes to retrieve the name of a
91 child controller.
92
93 @param Language[in] A pointer to a Null-terminated ASCII string
94 array indicating the language. This is the
95 language of the driver name that the caller is
96 requesting, and it must match one of the
97 languages specified in SupportedLanguages. The
98 number of languages supported by a driver is up
99 to the driver writer. Language is specified in
100 RFC 4646 or ISO 639-2 language code format.
101
102 @param ControllerName[out] A pointer to the Unicode string to return.
103 This Unicode string is the name of the
104 controller specified by ControllerHandle and
105 ChildHandle in the language specified by
106 Language from the point of view of the driver
107 specified by This.
108
109 @retval EFI_SUCCESS The Unicode string for the user readable name in
110 the language specified by Language for the
111 driver specified by This was returned in
112 DriverName.
113
114 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
115
116 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
117 EFI_HANDLE.
118
119 @retval EFI_INVALID_PARAMETER Language is NULL.
120
121 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
122
123 @retval EFI_UNSUPPORTED The driver specified by This is not currently
124 managing the controller specified by
125 ControllerHandle and ChildHandle.
126
127 @retval EFI_UNSUPPORTED The driver specified by This does not support
128 the language specified by Language.
129
130 **/
131 EFI_STATUS
132 EFIAPI
133 SimpleNetworkComponentNameGetControllerName (
134 IN EFI_COMPONENT_NAME_PROTOCOL *This,
135 IN EFI_HANDLE ControllerHandle,
136 IN EFI_HANDLE ChildHandle OPTIONAL,
137 IN CHAR8 *Language,
138 OUT CHAR16 **ControllerName
139 );
140
141
142 //
143 // EFI Component Name Protocol
144 //
145 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gSimpleNetworkComponentName = {
146 SimpleNetworkComponentNameGetDriverName,
147 SimpleNetworkComponentNameGetControllerName,
148 "eng"
149 };
150
151 //
152 // EFI Component Name 2 Protocol
153 //
154 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gSimpleNetworkComponentName2 = {
155 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) SimpleNetworkComponentNameGetDriverName,
156 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) SimpleNetworkComponentNameGetControllerName,
157 "en"
158 };
159
160
161 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSimpleNetworkDriverNameTable[] = {
162 {
163 "eng;en",
164 L"Simple Network Protocol Driver"
165 },
166 {
167 NULL,
168 NULL
169 }
170 };
171
172 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gSimpleNetworkControllerNameTable = NULL;
173
174 /**
175 Retrieves a Unicode string that is the user readable name of the driver.
176
177 This function retrieves the user readable name of a driver in the form of a
178 Unicode string. If the driver specified by This has a user readable name in
179 the language specified by Language, then a pointer to the driver name is
180 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
181 by This does not support the language specified by Language,
182 then EFI_UNSUPPORTED is returned.
183
184 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
185 EFI_COMPONENT_NAME_PROTOCOL instance.
186
187 @param Language[in] A pointer to a Null-terminated ASCII string
188 array indicating the language. This is the
189 language of the driver name that the caller is
190 requesting, and it must match one of the
191 languages specified in SupportedLanguages. The
192 number of languages supported by a driver is up
193 to the driver writer. Language is specified
194 in RFC 4646 or ISO 639-2 language code format.
195
196 @param DriverName[out] A pointer to the Unicode string to return.
197 This Unicode string is the name of the
198 driver specified by This in the language
199 specified by Language.
200
201 @retval EFI_SUCCESS The Unicode string for the Driver specified by
202 This and the language specified by Language was
203 returned in DriverName.
204
205 @retval EFI_INVALID_PARAMETER Language is NULL.
206
207 @retval EFI_INVALID_PARAMETER DriverName is NULL.
208
209 @retval EFI_UNSUPPORTED The driver specified by This does not support
210 the language specified by Language.
211
212 **/
213 EFI_STATUS
214 EFIAPI
215 SimpleNetworkComponentNameGetDriverName (
216 IN EFI_COMPONENT_NAME_PROTOCOL *This,
217 IN CHAR8 *Language,
218 OUT CHAR16 **DriverName
219 )
220 {
221 return LookupUnicodeString2 (
222 Language,
223 This->SupportedLanguages,
224 mSimpleNetworkDriverNameTable,
225 DriverName,
226 (BOOLEAN)(This == &gSimpleNetworkComponentName)
227 );
228 }
229
230 /**
231 Update the component name for the Snp child handle.
232
233 @param Snp[in] A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL.
234
235
236 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
237 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
238
239 **/
240 EFI_STATUS
241 UpdateName (
242 IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp
243 )
244 {
245 EFI_STATUS Status;
246 CHAR16 HandleName[80];
247 UINTN OffSet;
248 UINTN Index;
249
250 if (Snp == NULL) {
251 return EFI_INVALID_PARAMETER;
252 }
253
254 OffSet = 0;
255 OffSet += UnicodeSPrint (
256 HandleName,
257 sizeof (HandleName),
258 L"SNP (MAC="
259 );
260 for (Index = 0; Index < Snp->Mode->HwAddressSize; Index++) {
261 OffSet += UnicodeSPrint (
262 HandleName + OffSet,
263 sizeof (HandleName) - OffSet * sizeof (CHAR16),
264 L"%02X-",
265 Snp->Mode->CurrentAddress.Addr[Index]
266 );
267 }
268 ASSERT (OffSet > 0);
269 //
270 // Remove the last '-'
271 //
272 OffSet--;
273 OffSet += UnicodeSPrint (
274 HandleName + OffSet,
275 sizeof (HandleName) - OffSet * sizeof (CHAR16),
276 L")"
277 );
278 if (gSimpleNetworkControllerNameTable != NULL) {
279 FreeUnicodeStringTable (gSimpleNetworkControllerNameTable);
280 gSimpleNetworkControllerNameTable = NULL;
281 }
282
283 Status = AddUnicodeString2 (
284 "eng",
285 gSimpleNetworkComponentName.SupportedLanguages,
286 &gSimpleNetworkControllerNameTable,
287 HandleName,
288 TRUE
289 );
290 if (EFI_ERROR (Status)) {
291 return Status;
292 }
293
294 return AddUnicodeString2 (
295 "en",
296 gSimpleNetworkComponentName2.SupportedLanguages,
297 &gSimpleNetworkControllerNameTable,
298 HandleName,
299 FALSE
300 );
301 }
302
303 /**
304 Retrieves a Unicode string that is the user readable name of the controller
305 that is being managed by a driver.
306
307 This function retrieves the user readable name of the controller specified by
308 ControllerHandle and ChildHandle in the form of a Unicode string. If the
309 driver specified by This has a user readable name in the language specified by
310 Language, then a pointer to the controller name is returned in ControllerName,
311 and EFI_SUCCESS is returned. If the driver specified by This is not currently
312 managing the controller specified by ControllerHandle and ChildHandle,
313 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
314 support the language specified by Language, then EFI_UNSUPPORTED is returned.
315 Currently not implemented.
316
317 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
318 EFI_COMPONENT_NAME_PROTOCOL instance.
319
320 @param ControllerHandle[in] 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 ChildHandle[in] 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 Language[in] 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 ControllerName[out] 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 SimpleNetworkComponentNameGetControllerName (
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_SIMPLE_NETWORK_PROTOCOL *Snp;
384
385 if (ChildHandle != NULL) {
386 return EFI_UNSUPPORTED;
387 }
388
389 //
390 // Make sure this driver is currently managing ControllHandle
391 //
392 Status = EfiTestManagedDevice (
393 ControllerHandle,
394 gSimpleNetworkDriverBinding.DriverBindingHandle,
395 &gEfiSimpleNetworkProtocolGuid
396 );
397 if (EFI_ERROR (Status)) {
398 return Status;
399 }
400
401 //
402 // Retrieve an instance of a produced protocol from ControllerHandle
403 //
404 Status = gBS->OpenProtocol (
405 ControllerHandle,
406 &gEfiSimpleNetworkProtocolGuid,
407 (VOID **)&Snp,
408 NULL,
409 NULL,
410 EFI_OPEN_PROTOCOL_GET_PROTOCOL
411 );
412 if (EFI_ERROR (Status)) {
413 return Status;
414 }
415 //
416 // Update the component name for this child handle.
417 //
418 Status = UpdateName (Snp);
419 if (EFI_ERROR (Status)) {
420 return Status;
421 }
422
423 return LookupUnicodeString2 (
424 Language,
425 This->SupportedLanguages,
426 gSimpleNetworkControllerNameTable,
427 ControllerName,
428 (BOOLEAN)(This == &gSimpleNetworkComponentName)
429 );
430 }