2 UEFI Component Name(2) protocol implementation for MnpDxe driver.
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // EFI Component Name Protocol
14 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName
= {
15 MnpComponentNameGetDriverName
,
16 MnpComponentNameGetControllerName
,
21 // EFI Component Name 2 Protocol
23 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2
= {
24 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME
)MnpComponentNameGetDriverName
,
25 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME
)MnpComponentNameGetControllerName
,
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable
[] = {
32 L
"MNP Network Service Driver"
40 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
*gMnpControllerNameTable
= NULL
;
43 Retrieves a Unicode string that is the user readable name of the driver.
45 This function retrieves the user readable name of a driver in the form of a
46 Unicode string. If the driver specified by This has a user readable name in
47 the language specified by Language, then a pointer to the driver name is
48 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
49 by This does not support the language specified by Language,
50 then EFI_UNSUPPORTED is returned.
52 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
53 EFI_COMPONENT_NAME_PROTOCOL instance.
55 @param[in] Language A pointer to a Null-terminated ASCII string
56 array indicating the language. This is the
57 language of the driver name that the caller is
58 requesting, and it must match one of the
59 languages specified in SupportedLanguages. The
60 number of languages supported by a driver is up
61 to the driver writer. Language is specified
62 in RFC 4646 or ISO 639-2 language code format.
64 @param[out] DriverName A pointer to the Unicode string to return.
65 This Unicode string is the name of the
66 driver specified by This in the language
67 specified by Language.
69 @retval EFI_SUCCESS The Unicode string for the Driver specified by
70 This and the language specified by Language was
71 returned in DriverName.
73 @retval EFI_INVALID_PARAMETER Language is NULL.
75 @retval EFI_INVALID_PARAMETER DriverName is NULL.
77 @retval EFI_UNSUPPORTED The driver specified by This does not support
78 the language specified by Language.
83 MnpComponentNameGetDriverName (
84 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
86 OUT CHAR16
**DriverName
89 return LookupUnicodeString2 (
91 This
->SupportedLanguages
,
94 (BOOLEAN
)(This
== &gMnpComponentName
)
99 Update the component name for the MNP child handle.
101 @param Mnp[in] A pointer to the EFI_MANAGED_NETWORK_PROTOCOL.
104 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
105 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
110 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
114 MNP_INSTANCE_DATA
*Instance
;
115 CHAR16 HandleName
[80];
116 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData
;
117 EFI_SIMPLE_NETWORK_MODE SnpModeData
;
122 return EFI_INVALID_PARAMETER
;
125 Instance
= MNP_INSTANCE_DATA_FROM_THIS (Mnp
);
127 // Format the child name into the string buffer as:
128 // MNP (MAC=FF-FF-FF-FF-FF-FF, ProtocolType=0x0800, VlanId=0)
130 Status
= Mnp
->GetModeData (Mnp
, &MnpConfigData
, &SnpModeData
);
131 if (!EFI_ERROR (Status
)) {
134 // Print the MAC address.
136 OffSet
+= UnicodeSPrint (
141 for (Index
= 0; Index
< SnpModeData
.HwAddressSize
; Index
++) {
142 OffSet
+= UnicodeSPrint (
144 sizeof (HandleName
) - OffSet
* sizeof (CHAR16
),
146 SnpModeData
.CurrentAddress
.Addr
[Index
]
152 // Remove the last '-'
156 // Print the ProtocolType and VLAN ID for this instance.
158 OffSet
+= UnicodeSPrint (
160 sizeof (HandleName
) - OffSet
* sizeof (CHAR16
),
161 L
", ProtocolType=0x%X, VlanId=%d)",
162 MnpConfigData
.ProtocolTypeFilter
,
163 Instance
->MnpServiceData
->VlanId
165 } else if (Status
== EFI_NOT_STARTED
) {
175 if (gMnpControllerNameTable
!= NULL
) {
176 FreeUnicodeStringTable (gMnpControllerNameTable
);
177 gMnpControllerNameTable
= NULL
;
180 Status
= AddUnicodeString2 (
182 gMnpComponentName
.SupportedLanguages
,
183 &gMnpControllerNameTable
,
187 if (EFI_ERROR (Status
)) {
191 return AddUnicodeString2 (
193 gMnpComponentName2
.SupportedLanguages
,
194 &gMnpControllerNameTable
,
201 Retrieves a Unicode string that is the user readable name of the controller
202 that is being managed by a driver.
204 This function retrieves the user readable name of the controller specified by
205 ControllerHandle and ChildHandle in the form of a Unicode string. If the
206 driver specified by This has a user readable name in the language specified by
207 Language, then a pointer to the controller name is returned in ControllerName,
208 and EFI_SUCCESS is returned. If the driver specified by This is not currently
209 managing the controller specified by ControllerHandle and ChildHandle,
210 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
211 support the language specified by Language, then EFI_UNSUPPORTED is returned.
212 Currently not implemented.
214 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
215 EFI_COMPONENT_NAME_PROTOCOL instance.
217 @param[in] ControllerHandle The handle of a controller that the driver
218 specified by This is managing. This handle
219 specifies the controller whose name is to be
222 @param[in] ChildHandle The handle of the child controller to retrieve
223 the name of. This is an optional parameter that
224 may be NULL. It will be NULL for device
225 drivers. It will also be NULL for a bus drivers
226 that wish to retrieve the name of the bus
227 controller. It will not be NULL for a bus
228 driver that wishes to retrieve the name of a
231 @param[in] Language A pointer to a Null-terminated ASCII string
232 array indicating the language. This is the
233 language of the driver name that the caller is
234 requesting, and it must match one of the
235 languages specified in SupportedLanguages. The
236 number of languages supported by a driver is up
237 to the driver writer. Language is specified in
238 RFC 4646 or ISO 639-2 language code format.
240 @param[out] ControllerName A pointer to the Unicode string to return.
241 This Unicode string is the name of the
242 controller specified by ControllerHandle and
243 ChildHandle in the language specified by
244 Language from the point of view of the driver
247 @retval EFI_SUCCESS The Unicode string for the user readable name
248 specified by This, ControllerHandle, ChildHandle,
249 and Language was returned in ControllerName.
251 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
253 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
256 @retval EFI_INVALID_PARAMETER Language is NULL.
258 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
260 @retval EFI_UNSUPPORTED The driver specified by This is not currently
261 managing the controller specified by
262 ControllerHandle and ChildHandle.
264 @retval EFI_UNSUPPORTED The driver specified by This does not support
265 the language specified by Language.
270 MnpComponentNameGetControllerName (
271 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
272 IN EFI_HANDLE ControllerHandle
,
273 IN EFI_HANDLE ChildHandle OPTIONAL
,
275 OUT CHAR16
**ControllerName
279 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
282 // Only provide names for MNP child handles.
284 if (ChildHandle
== NULL
) {
285 return EFI_UNSUPPORTED
;
289 // Make sure this driver is currently managing ControllerHandle
291 Status
= EfiTestManagedDevice (
293 gMnpDriverBinding
.DriverBindingHandle
,
294 &gEfiSimpleNetworkProtocolGuid
296 if (EFI_ERROR (Status
)) {
301 // Make sure this driver produced ChildHandle
303 Status
= EfiTestChildHandle (
306 &gEfiManagedNetworkServiceBindingProtocolGuid
308 if (EFI_ERROR (Status
)) {
313 // Retrieve an instance of a produced protocol from ChildHandle
315 Status
= gBS
->OpenProtocol (
317 &gEfiManagedNetworkProtocolGuid
,
321 EFI_OPEN_PROTOCOL_GET_PROTOCOL
323 if (EFI_ERROR (Status
)) {
328 // Update the component name for this child handle.
330 Status
= UpdateName (Mnp
);
331 if (EFI_ERROR (Status
)) {
335 return LookupUnicodeString2 (
337 This
->SupportedLanguages
,
338 gMnpControllerNameTable
,
340 (BOOLEAN
)(This
== &gMnpComponentName
)