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
]
151 // Remove the last '-'
155 // Print the ProtocolType and VLAN ID for this instance.
157 OffSet
+= UnicodeSPrint (
159 sizeof (HandleName
) - OffSet
* sizeof (CHAR16
),
160 L
", ProtocolType=0x%X, VlanId=%d)",
161 MnpConfigData
.ProtocolTypeFilter
,
162 Instance
->MnpServiceData
->VlanId
164 } else if (Status
== EFI_NOT_STARTED
) {
174 if (gMnpControllerNameTable
!= NULL
) {
175 FreeUnicodeStringTable (gMnpControllerNameTable
);
176 gMnpControllerNameTable
= NULL
;
179 Status
= AddUnicodeString2 (
181 gMnpComponentName
.SupportedLanguages
,
182 &gMnpControllerNameTable
,
186 if (EFI_ERROR (Status
)) {
190 return AddUnicodeString2 (
192 gMnpComponentName2
.SupportedLanguages
,
193 &gMnpControllerNameTable
,
200 Retrieves a Unicode string that is the user readable name of the controller
201 that is being managed by a driver.
203 This function retrieves the user readable name of the controller specified by
204 ControllerHandle and ChildHandle in the form of a Unicode string. If the
205 driver specified by This has a user readable name in the language specified by
206 Language, then a pointer to the controller name is returned in ControllerName,
207 and EFI_SUCCESS is returned. If the driver specified by This is not currently
208 managing the controller specified by ControllerHandle and ChildHandle,
209 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
210 support the language specified by Language, then EFI_UNSUPPORTED is returned.
211 Currently not implemented.
213 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
214 EFI_COMPONENT_NAME_PROTOCOL instance.
216 @param[in] ControllerHandle The handle of a controller that the driver
217 specified by This is managing. This handle
218 specifies the controller whose name is to be
221 @param[in] ChildHandle The handle of the child controller to retrieve
222 the name of. This is an optional parameter that
223 may be NULL. It will be NULL for device
224 drivers. It will also be NULL for a bus drivers
225 that wish to retrieve the name of the bus
226 controller. It will not be NULL for a bus
227 driver that wishes to retrieve the name of a
230 @param[in] Language A pointer to a Null-terminated ASCII string
231 array indicating the language. This is the
232 language of the driver name that the caller is
233 requesting, and it must match one of the
234 languages specified in SupportedLanguages. The
235 number of languages supported by a driver is up
236 to the driver writer. Language is specified in
237 RFC 4646 or ISO 639-2 language code format.
239 @param[out] ControllerName A pointer to the Unicode string to return.
240 This Unicode string is the name of the
241 controller specified by ControllerHandle and
242 ChildHandle in the language specified by
243 Language from the point of view of the driver
246 @retval EFI_SUCCESS The Unicode string for the user readable name
247 specified by This, ControllerHandle, ChildHandle,
248 and Language was returned in ControllerName.
250 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
252 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
255 @retval EFI_INVALID_PARAMETER Language is NULL.
257 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
259 @retval EFI_UNSUPPORTED The driver specified by This is not currently
260 managing the controller specified by
261 ControllerHandle and ChildHandle.
263 @retval EFI_UNSUPPORTED The driver specified by This does not support
264 the language specified by Language.
269 MnpComponentNameGetControllerName (
270 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
271 IN EFI_HANDLE ControllerHandle
,
272 IN EFI_HANDLE ChildHandle OPTIONAL
,
274 OUT CHAR16
**ControllerName
278 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
281 // Only provide names for MNP child handles.
283 if (ChildHandle
== NULL
) {
284 return EFI_UNSUPPORTED
;
288 // Make sure this driver is currently managing ControllerHandle
290 Status
= EfiTestManagedDevice (
292 gMnpDriverBinding
.DriverBindingHandle
,
293 &gEfiSimpleNetworkProtocolGuid
295 if (EFI_ERROR (Status
)) {
300 // Make sure this driver produced ChildHandle
302 Status
= EfiTestChildHandle (
305 &gEfiManagedNetworkServiceBindingProtocolGuid
307 if (EFI_ERROR (Status
)) {
312 // Retrieve an instance of a produced protocol from ChildHandle
314 Status
= gBS
->OpenProtocol (
316 &gEfiManagedNetworkProtocolGuid
,
320 EFI_OPEN_PROTOCOL_GET_PROTOCOL
322 if (EFI_ERROR (Status
)) {
327 // Update the component name for this child handle.
329 Status
= UpdateName (Mnp
);
330 if (EFI_ERROR (Status
)) {
334 return LookupUnicodeString2 (
336 This
->SupportedLanguages
,
337 gMnpControllerNameTable
,
339 (BOOLEAN
)(This
== &gMnpComponentName
)