2 UEFI Component Name(2) protocol implementation for iSCSI.
4 Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "IScsiImpl.h"
18 // EFI Component Name Protocol
20 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName
= {
21 IScsiComponentNameGetDriverName
,
22 IScsiComponentNameGetControllerName
,
27 // EFI Component Name 2 Protocol
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIScsiComponentName2
= {
30 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME
) IScsiComponentNameGetDriverName
,
31 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME
) IScsiComponentNameGetControllerName
,
35 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable
[] = {
36 {"eng;en", L
"iSCSI Driver"},
40 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
*mIScsiControllerNameTable
= NULL
;
43 Retrieves a Unicode string that is the user readable name of the EFI 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_NAME_PROTOCOL instance.
53 @param[in] Language A pointer to a three character ISO 639-2 language identifier.
54 This is the language of the driver name that that the caller
55 is requesting, and it must match one of the languages specified
56 in SupportedLanguages. The number of languages supported by a
57 driver is up to the driver writer.
58 @param[out] DriverName A pointer to the Unicode string to return. This Unicode string
59 is the name of the driver specified by This in the language
60 specified by Language.
62 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
63 and the language specified by Language was returned
65 @retval EFI_INVALID_PARAMETER Language is NULL.
66 @retval EFI_INVALID_PARAMETER DriverName is NULL.
67 @retval EFI_UNSUPPORTED The driver specified by This does not support the
68 language specified by Language.
72 IScsiComponentNameGetDriverName (
73 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
75 OUT CHAR16
**DriverName
78 return LookupUnicodeString2 (
80 This
->SupportedLanguages
,
81 mIScsiDriverNameTable
,
83 (BOOLEAN
)(This
== &gIScsiComponentName
)
88 Update the component name for the iSCSI instance.
90 @param[in] IScsiExtScsiPassThru A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
92 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
93 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
94 @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.
99 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*IScsiExtScsiPassThru
103 CHAR16 HandleName
[150];
104 ISCSI_DRIVER_DATA
*Private
;
105 EFI_MAC_ADDRESS MacAddress
;
108 CHAR16 MacString
[70];
110 if (IScsiExtScsiPassThru
== NULL
) {
111 return EFI_INVALID_PARAMETER
;
114 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPassThru
);
117 // Get the mac string, it's the name of various variable
119 Status
= NetLibGetMacAddress (Private
->Controller
, &MacAddress
, &HwAddressSize
);
120 if (EFI_ERROR (Status
)) {
123 VlanId
= NetLibGetVlanId (Private
->Controller
);
124 IScsiMacAddrToStr (&MacAddress
, (UINT32
) HwAddressSize
, VlanId
, MacString
);
129 L
"iSCSI IPv4 (MacString=%s)",
133 if (mIScsiControllerNameTable
!= NULL
) {
134 FreeUnicodeStringTable (mIScsiControllerNameTable
);
135 mIScsiControllerNameTable
= NULL
;
138 Status
= AddUnicodeString2 (
140 gIScsiComponentName
.SupportedLanguages
,
141 &mIScsiControllerNameTable
,
145 if (EFI_ERROR (Status
)) {
149 return AddUnicodeString2 (
151 gIScsiComponentName2
.SupportedLanguages
,
152 &mIScsiControllerNameTable
,
159 Retrieves a Unicode string that is the user readable name of the controller
160 that is being managed by an EFI Driver.Currently not implemented.
162 @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
163 @param[in] ControllerHandle The handle of a controller that the driver specified by
164 This is managing. This handle specifies the controller
165 whose name is to be returned.
166 @param[in] ChildHandle The handle of the child controller to retrieve the name
167 of. This is an optional parameter that may be NULL. It
168 will be NULL for device drivers. It will also be NULL
169 for a bus drivers that wish to retrieve the name of the
170 bus controller. It will not be NULL for a bus driver
171 that wishes to retrieve the name of a child controller.
172 @param[in] Language A pointer to a three character ISO 639-2 language
173 identifier. This is the language of the controller name
174 that that the caller is requesting, and it must match one
175 of the languages specified in SupportedLanguages. The
176 number of languages supported by a driver is up to the
178 @param[out] ControllerName A pointer to the Unicode string to return. This Unicode
179 string is the name of the controller specified by
180 ControllerHandle and ChildHandle in the language specified
181 by Language from the point of view of the driver specified
184 @retval EFI_SUCCESS The Unicode string for the user readable name in the
185 language specified by Language for the driver
186 specified by This was returned in DriverName.
187 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
188 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
189 @retval EFI_INVALID_PARAMETER Language is NULL.
190 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
191 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
192 the controller specified by ControllerHandle and
194 @retval EFI_UNSUPPORTED The driver specified by This does not support the
195 language specified by Language.
199 IScsiComponentNameGetControllerName (
200 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
201 IN EFI_HANDLE ControllerHandle
,
202 IN EFI_HANDLE ChildHandle OPTIONAL
,
204 OUT CHAR16
**ControllerName
209 EFI_HANDLE IScsiController
;
210 ISCSI_PRIVATE_PROTOCOL
*IScsiIdentifier
;
212 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*IScsiExtScsiPassThru
;
214 if (ControllerHandle
== NULL
) {
215 return EFI_UNSUPPORTED
;
219 // Get the handle of the controller we are controling.
221 IScsiController
= NetLibGetNicHandle (ControllerHandle
, &gEfiTcp4ProtocolGuid
);
222 if (IScsiController
== NULL
) {
223 return EFI_UNSUPPORTED
;
226 Status
= gBS
->OpenProtocol (
229 (VOID
**)&IScsiIdentifier
,
232 EFI_OPEN_PROTOCOL_GET_PROTOCOL
234 if (EFI_ERROR (Status
)) {
238 if (ChildHandle
!= NULL
) {
240 // Make sure this driver produced ChildHandle
242 Status
= EfiTestChildHandle (
245 &gEfiTcp4ProtocolGuid
247 if (!EFI_ERROR (Status
)) {
249 // Retrieve an instance of a produced protocol from ChildHandle
251 Status
= gBS
->OpenProtocol (
253 &gEfiExtScsiPassThruProtocolGuid
,
254 (VOID
**)&IScsiExtScsiPassThru
,
257 EFI_OPEN_PROTOCOL_GET_PROTOCOL
259 if (EFI_ERROR (Status
)) {
264 // Update the component name for this child handle.
266 Status
= UpdateName (IScsiExtScsiPassThru
);
267 if (EFI_ERROR (Status
)) {
275 return LookupUnicodeString2 (
277 This
->SupportedLanguages
,
278 mIScsiControllerNameTable
,
280 (BOOLEAN
)(This
== &gIScsiComponentName
)