2 UEFI Component Name(2) protocol implementation for MnpDxe driver.
4 Copyright (c) 2005 - 2018, 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
]
158 // Remove the last '-'
162 // Print the ProtocolType and VLAN ID for this instance.
164 OffSet
+= UnicodeSPrint (
166 sizeof (HandleName
) - OffSet
* sizeof (CHAR16
),
167 L
", ProtocolType=0x%X, VlanId=%d)",
168 MnpConfigData
.ProtocolTypeFilter
,
169 Instance
->MnpServiceData
->VlanId
171 } else if (Status
== EFI_NOT_STARTED
) {
181 if (gMnpControllerNameTable
!= NULL
) {
182 FreeUnicodeStringTable (gMnpControllerNameTable
);
183 gMnpControllerNameTable
= NULL
;
186 Status
= AddUnicodeString2 (
188 gMnpComponentName
.SupportedLanguages
,
189 &gMnpControllerNameTable
,
193 if (EFI_ERROR (Status
)) {
197 return AddUnicodeString2 (
199 gMnpComponentName2
.SupportedLanguages
,
200 &gMnpControllerNameTable
,
207 Retrieves a Unicode string that is the user readable name of the controller
208 that is being managed by a driver.
210 This function retrieves the user readable name of the controller specified by
211 ControllerHandle and ChildHandle in the form of a Unicode string. If the
212 driver specified by This has a user readable name in the language specified by
213 Language, then a pointer to the controller name is returned in ControllerName,
214 and EFI_SUCCESS is returned. If the driver specified by This is not currently
215 managing the controller specified by ControllerHandle and ChildHandle,
216 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
217 support the language specified by Language, then EFI_UNSUPPORTED is returned.
218 Currently not implemented.
220 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
221 EFI_COMPONENT_NAME_PROTOCOL instance.
223 @param[in] ControllerHandle The handle of a controller that the driver
224 specified by This is managing. This handle
225 specifies the controller whose name is to be
228 @param[in] ChildHandle The handle of the child controller to retrieve
229 the name of. This is an optional parameter that
230 may be NULL. It will be NULL for device
231 drivers. It will also be NULL for a bus drivers
232 that wish to retrieve the name of the bus
233 controller. It will not be NULL for a bus
234 driver that wishes to retrieve the name of a
237 @param[in] Language A pointer to a Null-terminated ASCII string
238 array indicating the language. This is the
239 language of the driver name that the caller is
240 requesting, and it must match one of the
241 languages specified in SupportedLanguages. The
242 number of languages supported by a driver is up
243 to the driver writer. Language is specified in
244 RFC 4646 or ISO 639-2 language code format.
246 @param[out] ControllerName A pointer to the Unicode string to return.
247 This Unicode string is the name of the
248 controller specified by ControllerHandle and
249 ChildHandle in the language specified by
250 Language from the point of view of the driver
253 @retval EFI_SUCCESS The Unicode string for the user readable name
254 specified by This, ControllerHandle, ChildHandle,
255 and Language was returned in ControllerName.
257 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
259 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
262 @retval EFI_INVALID_PARAMETER Language is NULL.
264 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
266 @retval EFI_UNSUPPORTED The driver specified by This is not currently
267 managing the controller specified by
268 ControllerHandle and ChildHandle.
270 @retval EFI_UNSUPPORTED The driver specified by This does not support
271 the language specified by Language.
276 MnpComponentNameGetControllerName (
277 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
278 IN EFI_HANDLE ControllerHandle
,
279 IN EFI_HANDLE ChildHandle OPTIONAL
,
281 OUT CHAR16
**ControllerName
285 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
288 // Only provide names for MNP child handles.
290 if (ChildHandle
== NULL
) {
291 return EFI_UNSUPPORTED
;
295 // Make sure this driver is currently managing ControllerHandle
297 Status
= EfiTestManagedDevice (
299 gMnpDriverBinding
.DriverBindingHandle
,
300 &gEfiSimpleNetworkProtocolGuid
302 if (EFI_ERROR (Status
)) {
307 // Make sure this driver produced ChildHandle
309 Status
= EfiTestChildHandle (
312 &gEfiManagedNetworkServiceBindingProtocolGuid
314 if (EFI_ERROR (Status
)) {
319 // Retrieve an instance of a produced protocol from ChildHandle
321 Status
= gBS
->OpenProtocol (
323 &gEfiManagedNetworkProtocolGuid
,
327 EFI_OPEN_PROTOCOL_GET_PROTOCOL
329 if (EFI_ERROR (Status
)) {
334 // Update the component name for this child handle.
336 Status
= UpdateName (Mnp
);
337 if (EFI_ERROR (Status
)) {
341 return LookupUnicodeString2 (
343 This
->SupportedLanguages
,
344 gMnpControllerNameTable
,
346 (BOOLEAN
)(This
== &gMnpComponentName
)