2 UEFI Component Name(2) protocol implementation for iSCSI.
4 Copyright (c) 2004 - 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 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
[] = {
46 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
*gIScsiControllerNameTable
= NULL
;
49 Retrieves a Unicode string that is the user readable name of the driver.
51 This function retrieves the user readable name of a driver in the form of a
52 Unicode string. If the driver specified by This has a user readable name in
53 the language specified by Language, then a pointer to the driver name is
54 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
55 by This does not support the language specified by Language,
56 then EFI_UNSUPPORTED is returned.
58 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
59 EFI_COMPONENT_NAME_PROTOCOL instance.
61 @param[in] Language A pointer to a Null-terminated ASCII string
62 array indicating the language. This is the
63 language of the driver name that the caller is
64 requesting, and it must match one of the
65 languages specified in SupportedLanguages. The
66 number of languages supported by a driver is up
67 to the driver writer. Language is specified
68 in RFC 4646 or ISO 639-2 language code format.
70 @param[out] DriverName A pointer to the Unicode string to return.
71 This Unicode string is the name of the
72 driver specified by This in the language
73 specified by Language.
75 @retval EFI_SUCCESS The Unicode string for the Driver specified by
76 This and the language specified by Language was
77 returned in DriverName.
79 @retval EFI_INVALID_PARAMETER Language is NULL.
81 @retval EFI_INVALID_PARAMETER DriverName is NULL.
83 @retval EFI_UNSUPPORTED The driver specified by This does not support
84 the language specified by Language.
89 IScsiComponentNameGetDriverName (
90 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
92 OUT CHAR16
**DriverName
95 return LookupUnicodeString2 (
97 This
->SupportedLanguages
,
98 mIScsiDriverNameTable
,
100 (BOOLEAN
) (This
== &gIScsiComponentName
)
105 Update the component name for the iSCSI NIC handle.
107 @param[in] Controller The handle of the NIC controller.
108 @param[in] Ipv6Flag TRUE if IP6 network stack is used.
110 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
111 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
112 @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.
117 IN EFI_HANDLE Controller
,
122 EFI_MAC_ADDRESS MacAddr
;
125 ISCSI_NIC_INFO
*ThisNic
;
126 ISCSI_NIC_INFO
*NicInfo
;
128 CHAR16 HandleName
[80];
131 // Get MAC address of this network device.
133 Status
= NetLibGetMacAddress (Controller
, &MacAddr
, &HwAddressSize
);
134 if (EFI_ERROR (Status
)) {
139 // Get VLAN ID of this network device.
141 VlanId
= NetLibGetVlanId (Controller
);
144 // Check whether the NIC information exists.
148 NET_LIST_FOR_EACH (Entry
, &mPrivate
->NicInfoList
) {
149 NicInfo
= NET_LIST_USER_STRUCT (Entry
, ISCSI_NIC_INFO
, Link
);
150 if (NicInfo
->HwAddressSize
== HwAddressSize
&&
151 CompareMem (&NicInfo
->PermanentAddress
, MacAddr
.Addr
, HwAddressSize
) == 0 &&
152 NicInfo
->VlanId
== VlanId
) {
159 if (ThisNic
== NULL
) {
160 return EFI_UNSUPPORTED
;
166 L
"iSCSI (%s, NicIndex=%d)",
167 Ipv6Flag
? L
"IPv6" : L
"IPv4",
171 if (gIScsiControllerNameTable
!= NULL
) {
172 FreeUnicodeStringTable (gIScsiControllerNameTable
);
173 gIScsiControllerNameTable
= NULL
;
176 Status
= AddUnicodeString2 (
178 gIScsiComponentName
.SupportedLanguages
,
179 &gIScsiControllerNameTable
,
183 if (EFI_ERROR (Status
)) {
187 return AddUnicodeString2 (
189 gIScsiComponentName2
.SupportedLanguages
,
190 &gIScsiControllerNameTable
,
198 Retrieves a Unicode string that is the user readable name of the controller
199 that is being managed by a driver.
201 This function retrieves the user readable name of the controller specified by
202 ControllerHandle and ChildHandle in the form of a Unicode string. If the
203 driver specified by This has a user readable name in the language specified by
204 Language, then a pointer to the controller name is returned in ControllerName,
205 and EFI_SUCCESS is returned. If the driver specified by This is not currently
206 managing the controller specified by ControllerHandle and ChildHandle,
207 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
208 support the language specified by Language, then EFI_UNSUPPORTED is returned.
210 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
211 EFI_COMPONENT_NAME_PROTOCOL instance.
213 @param[in] ControllerHandle The handle of a controller that the driver
214 specified by This is managing. This handle
215 specifies the controller whose name is to be
218 @param[in] ChildHandle The handle of the child controller to retrieve
219 the name of. This is an optional parameter that
220 may be NULL. It will be NULL for device
221 drivers. It will also be NULL for a bus drivers
222 that wish to retrieve the name of the bus
223 controller. It will not be NULL for a bus
224 driver that wishes to retrieve the name of a
227 @param[in] Language A pointer to a Null-terminated ASCII string
228 array indicating the language. This is the
229 language of the driver name that the caller is
230 requesting, and it must match one of the
231 languages specified in SupportedLanguages. The
232 number of languages supported by a driver is up
233 to the driver writer. Language is specified in
234 RFC 4646 or ISO 639-2 language code format.
236 @param[out] ControllerName A pointer to the Unicode string to return.
237 This Unicode string is the name of the
238 controller specified by ControllerHandle and
239 ChildHandle in the language specified by
240 Language, from the point of view of the driver
243 @retval EFI_SUCCESS The Unicode string for the user readable name in
244 the language specified by Language for the
245 driver specified by This was returned in
248 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
250 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
253 @retval EFI_INVALID_PARAMETER Language is NULL.
255 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
257 @retval EFI_UNSUPPORTED The driver specified by This is not currently
258 managing the controller specified by
259 ControllerHandle and ChildHandle.
261 @retval EFI_UNSUPPORTED The driver specified by This does not support
262 the language specified by Language.
267 IScsiComponentNameGetControllerName (
268 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
269 IN EFI_HANDLE ControllerHandle
,
270 IN EFI_HANDLE ChildHandle OPTIONAL
,
272 OUT CHAR16
**ControllerName
275 EFI_HANDLE IScsiController
;
278 EFI_GUID
*IScsiPrivateGuid
;
279 ISCSI_PRIVATE_PROTOCOL
*IScsiIdentifier
;
282 // Get the handle of the controller we are controling.
284 IScsiController
= NetLibGetNicHandle (ControllerHandle
, &gEfiTcp4ProtocolGuid
);
285 if (IScsiController
!= NULL
) {
286 IScsiPrivateGuid
= &gIScsiV4PrivateGuid
;
289 IScsiController
= NetLibGetNicHandle (ControllerHandle
, &gEfiTcp6ProtocolGuid
);
290 if (IScsiController
!= NULL
) {
291 IScsiPrivateGuid
= &gIScsiV6PrivateGuid
;
294 return EFI_UNSUPPORTED
;
299 // Retrieve an instance of a produced protocol from IScsiController
301 Status
= gBS
->OpenProtocol (
304 (VOID
**) &IScsiIdentifier
,
307 EFI_OPEN_PROTOCOL_GET_PROTOCOL
309 if (EFI_ERROR (Status
)) {
313 Status
= UpdateName(IScsiController
, Ipv6Flag
);
314 if (EFI_ERROR(Status
)) {
318 return LookupUnicodeString2 (
320 This
->SupportedLanguages
,
321 gIScsiControllerNameTable
,
323 (BOOLEAN
)(This
== &gIScsiComponentName
)