2 UEFI Component Name(2) protocol implementation for MnpDxe driver.
4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The full
8 text of the license may be found at<BR>
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // EFI Component Name Protocol
21 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName
= {
22 MnpComponentNameGetDriverName
,
23 MnpComponentNameGetControllerName
,
28 // EFI Component Name 2 Protocol
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2
= {
31 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME
) MnpComponentNameGetDriverName
,
32 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME
) MnpComponentNameGetControllerName
,
36 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable
[] = {
39 L
"MNP Network Service Driver"
47 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
*gMnpControllerNameTable
= NULL
;
50 Retrieves a Unicode string that is the user readable name of the driver.
52 This function retrieves the user readable name of a driver in the form of a
53 Unicode string. If the driver specified by This has a user readable name in
54 the language specified by Language, then a pointer to the driver name is
55 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
56 by This does not support the language specified by Language,
57 then EFI_UNSUPPORTED is returned.
59 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
60 EFI_COMPONENT_NAME_PROTOCOL instance.
62 @param[in] Language A pointer to a Null-terminated ASCII string
63 array indicating the language. This is the
64 language of the driver name that the caller is
65 requesting, and it must match one of the
66 languages specified in SupportedLanguages. The
67 number of languages supported by a driver is up
68 to the driver writer. Language is specified
69 in RFC 4646 or ISO 639-2 language code format.
71 @param[out] DriverName A pointer to the Unicode string to return.
72 This Unicode string is the name of the
73 driver specified by This in the language
74 specified by Language.
76 @retval EFI_SUCCESS The Unicode string for the Driver specified by
77 This and the language specified by Language was
78 returned in DriverName.
80 @retval EFI_INVALID_PARAMETER Language is NULL.
82 @retval EFI_INVALID_PARAMETER DriverName is NULL.
84 @retval EFI_UNSUPPORTED The driver specified by This does not support
85 the language specified by Language.
90 MnpComponentNameGetDriverName (
91 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
93 OUT CHAR16
**DriverName
96 return LookupUnicodeString2 (
98 This
->SupportedLanguages
,
101 (BOOLEAN
) (This
== &gMnpComponentName
)
106 Update the component name for the MNP child handle.
108 @param Mnp[in] A pointer to the EFI_MANAGED_NETWORK_PROTOCOL.
111 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
112 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
117 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
121 MNP_INSTANCE_DATA
*Instance
;
122 CHAR16 HandleName
[80];
123 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData
;
124 EFI_SIMPLE_NETWORK_MODE SnpModeData
;
129 return EFI_INVALID_PARAMETER
;
132 Instance
= MNP_INSTANCE_DATA_FROM_THIS (Mnp
);
134 // Format the child name into the string buffer as:
135 // MNP (MAC=FF-FF-FF-FF-FF-FF, ProtocolType=0x0800, VlanId=0)
137 Status
= Mnp
->GetModeData (Mnp
, &MnpConfigData
, &SnpModeData
);
138 if (!EFI_ERROR (Status
)) {
141 // Print the MAC address.
143 OffSet
+= UnicodeSPrint (
148 for (Index
= 0; Index
< SnpModeData
.HwAddressSize
; Index
++) {
149 OffSet
+= UnicodeSPrint (
151 sizeof (HandleName
) - OffSet
* sizeof (CHAR16
),
153 SnpModeData
.CurrentAddress
.Addr
[Index
]
157 // Remove the last '-'
161 // Print the ProtocolType and VLAN ID for this instance.
163 OffSet
+= UnicodeSPrint (
165 sizeof (HandleName
) - OffSet
* sizeof (CHAR16
),
166 L
", ProtocolType=0x%X, VlanId=%d)",
167 MnpConfigData
.ProtocolTypeFilter
,
168 Instance
->MnpServiceData
->VlanId
170 } else if (Status
== EFI_NOT_STARTED
) {
180 if (gMnpControllerNameTable
!= NULL
) {
181 FreeUnicodeStringTable (gMnpControllerNameTable
);
182 gMnpControllerNameTable
= NULL
;
185 Status
= AddUnicodeString2 (
187 gMnpComponentName
.SupportedLanguages
,
188 &gMnpControllerNameTable
,
192 if (EFI_ERROR (Status
)) {
196 return AddUnicodeString2 (
198 gMnpComponentName2
.SupportedLanguages
,
199 &gMnpControllerNameTable
,
206 Retrieves a Unicode string that is the user readable name of the controller
207 that is being managed by a driver.
209 This function retrieves the user readable name of the controller specified by
210 ControllerHandle and ChildHandle in the form of a Unicode string. If the
211 driver specified by This has a user readable name in the language specified by
212 Language, then a pointer to the controller name is returned in ControllerName,
213 and EFI_SUCCESS is returned. If the driver specified by This is not currently
214 managing the controller specified by ControllerHandle and ChildHandle,
215 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
216 support the language specified by Language, then EFI_UNSUPPORTED is returned.
217 Currently not implemented.
219 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
220 EFI_COMPONENT_NAME_PROTOCOL instance.
222 @param[in] ControllerHandle The handle of a controller that the driver
223 specified by This is managing. This handle
224 specifies the controller whose name is to be
227 @param[in] ChildHandle The handle of the child controller to retrieve
228 the name of. This is an optional parameter that
229 may be NULL. It will be NULL for device
230 drivers. It will also be NULL for a bus drivers
231 that wish to retrieve the name of the bus
232 controller. It will not be NULL for a bus
233 driver that wishes to retrieve the name of a
236 @param[in] Language A pointer to a Null-terminated ASCII string
237 array indicating the language. This is the
238 language of the driver name that the caller is
239 requesting, and it must match one of the
240 languages specified in SupportedLanguages. The
241 number of languages supported by a driver is up
242 to the driver writer. Language is specified in
243 RFC 4646 or ISO 639-2 language code format.
245 @param[out] ControllerName A pointer to the Unicode string to return.
246 This Unicode string is the name of the
247 controller specified by ControllerHandle and
248 ChildHandle in the language specified by
249 Language from the point of view of the driver
252 @retval EFI_SUCCESS The Unicode string for the user readable name
253 specified by This, ControllerHandle, ChildHandle,
254 and Language was returned in ControllerName.
256 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
258 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
261 @retval EFI_INVALID_PARAMETER Language is NULL.
263 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
265 @retval EFI_UNSUPPORTED The driver specified by This is not currently
266 managing the controller specified by
267 ControllerHandle and ChildHandle.
269 @retval EFI_UNSUPPORTED The driver specified by This does not support
270 the language specified by Language.
275 MnpComponentNameGetControllerName (
276 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
277 IN EFI_HANDLE ControllerHandle
,
278 IN EFI_HANDLE ChildHandle OPTIONAL
,
280 OUT CHAR16
**ControllerName
284 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
287 // Only provide names for MNP child handles.
289 if (ChildHandle
== NULL
) {
290 return EFI_UNSUPPORTED
;
294 // Make sure this driver is currently managing ControllerHandle
296 Status
= EfiTestManagedDevice (
298 gMnpDriverBinding
.DriverBindingHandle
,
299 &gEfiSimpleNetworkProtocolGuid
301 if (EFI_ERROR (Status
)) {
306 // Make sure this driver produced ChildHandle
308 Status
= EfiTestChildHandle (
311 &gEfiManagedNetworkServiceBindingProtocolGuid
313 if (EFI_ERROR (Status
)) {
318 // Retrieve an instance of a produced protocol from ChildHandle
320 Status
= gBS
->OpenProtocol (
322 &gEfiManagedNetworkProtocolGuid
,
326 EFI_OPEN_PROTOCOL_GET_PROTOCOL
328 if (EFI_ERROR (Status
)) {
333 // Update the component name for this child handle.
335 Status
= UpdateName (Mnp
);
336 if (EFI_ERROR (Status
)) {
340 return LookupUnicodeString2 (
342 This
->SupportedLanguages
,
343 gMnpControllerNameTable
,
345 (BOOLEAN
)(This
== &gMnpComponentName
)