]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IScsiDxe/ComponentName.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for iSCSI.
3
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
9
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.
12
13 **/
14
15 #include "IScsiImpl.h"
16
17 //
18 // EFI Component Name Protocol
19 //
20 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName = {
21 IScsiComponentNameGetDriverName,
22 IScsiComponentNameGetControllerName,
23 "eng"
24 };
25
26 //
27 // EFI Component Name 2 Protocol
28 //
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,
32 "en"
33 };
34
35 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable[] = {
36 {
37 "eng;en",
38 L"iSCSI Driver"
39 },
40 {
41 NULL,
42 NULL
43 }
44 };
45
46 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIScsiControllerNameTable = NULL;
47
48 /**
49 Retrieves a Unicode string that is the user readable name of the driver.
50
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.
57
58 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
59 EFI_COMPONENT_NAME_PROTOCOL instance.
60
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.
69
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.
74
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.
78
79 @retval EFI_INVALID_PARAMETER Language is NULL.
80
81 @retval EFI_INVALID_PARAMETER DriverName is NULL.
82
83 @retval EFI_UNSUPPORTED The driver specified by This does not support
84 the language specified by Language.
85
86 **/
87 EFI_STATUS
88 EFIAPI
89 IScsiComponentNameGetDriverName (
90 IN EFI_COMPONENT_NAME_PROTOCOL *This,
91 IN CHAR8 *Language,
92 OUT CHAR16 **DriverName
93 )
94 {
95 return LookupUnicodeString2 (
96 Language,
97 This->SupportedLanguages,
98 mIScsiDriverNameTable,
99 DriverName,
100 (BOOLEAN) (This == &gIScsiComponentName)
101 );
102 }
103
104 /**
105 Update the component name for the iSCSI NIC handle.
106
107 @param[in] Controller The handle of the NIC controller.
108 @param[in] Ipv6Flag TRUE if IP6 network stack is used.
109
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.
113
114 **/
115 EFI_STATUS
116 UpdateName (
117 IN EFI_HANDLE Controller,
118 IN BOOLEAN Ipv6Flag
119 )
120 {
121 EFI_STATUS Status;
122 EFI_MAC_ADDRESS MacAddr;
123 UINTN HwAddressSize;
124 UINT16 VlanId;
125 ISCSI_NIC_INFO *ThisNic;
126 ISCSI_NIC_INFO *NicInfo;
127 LIST_ENTRY *Entry;
128 CHAR16 HandleName[80];
129
130 //
131 // Get MAC address of this network device.
132 //
133 Status = NetLibGetMacAddress (Controller, &MacAddr, &HwAddressSize);
134 if (EFI_ERROR (Status)) {
135 return Status;
136 }
137
138 //
139 // Get VLAN ID of this network device.
140 //
141 VlanId = NetLibGetVlanId (Controller);
142
143 //
144 // Check whether the NIC information exists.
145 //
146 ThisNic = NULL;
147
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) {
153
154 ThisNic = NicInfo;
155 break;
156 }
157 }
158
159 if (ThisNic == NULL) {
160 return EFI_UNSUPPORTED;
161 }
162
163 UnicodeSPrint (
164 HandleName,
165 sizeof (HandleName),
166 L"iSCSI (%s, NicIndex=%d)",
167 Ipv6Flag ? L"IPv6" : L"IPv4",
168 ThisNic->NicIndex
169 );
170
171 if (gIScsiControllerNameTable != NULL) {
172 FreeUnicodeStringTable (gIScsiControllerNameTable);
173 gIScsiControllerNameTable = NULL;
174 }
175
176 Status = AddUnicodeString2 (
177 "eng",
178 gIScsiComponentName.SupportedLanguages,
179 &gIScsiControllerNameTable,
180 HandleName,
181 TRUE
182 );
183 if (EFI_ERROR (Status)) {
184 return Status;
185 }
186
187 return AddUnicodeString2 (
188 "en",
189 gIScsiComponentName2.SupportedLanguages,
190 &gIScsiControllerNameTable,
191 HandleName,
192 FALSE
193 );
194 }
195
196
197 /**
198 Retrieves a Unicode string that is the user readable name of the controller
199 that is being managed by a driver.
200
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.
209
210 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
211 EFI_COMPONENT_NAME_PROTOCOL instance.
212
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
216 returned.
217
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
225 child controller.
226
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.
235
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
241 specified by This.
242
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
246 DriverName.
247
248 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
249
250 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
251 EFI_HANDLE.
252
253 @retval EFI_INVALID_PARAMETER Language is NULL.
254
255 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
256
257 @retval EFI_UNSUPPORTED The driver specified by This is not currently
258 managing the controller specified by
259 ControllerHandle and ChildHandle.
260
261 @retval EFI_UNSUPPORTED The driver specified by This does not support
262 the language specified by Language.
263
264 **/
265 EFI_STATUS
266 EFIAPI
267 IScsiComponentNameGetControllerName (
268 IN EFI_COMPONENT_NAME_PROTOCOL *This,
269 IN EFI_HANDLE ControllerHandle,
270 IN EFI_HANDLE ChildHandle OPTIONAL,
271 IN CHAR8 *Language,
272 OUT CHAR16 **ControllerName
273 )
274 {
275 EFI_HANDLE IScsiController;
276 BOOLEAN Ipv6Flag;
277 EFI_STATUS Status;
278 EFI_GUID *IScsiPrivateGuid;
279 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
280
281 //
282 // Get the handle of the controller we are controling.
283 //
284 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
285 if (IScsiController != NULL) {
286 IScsiPrivateGuid = &gIScsiV4PrivateGuid;
287 Ipv6Flag = FALSE;
288 } else {
289 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);
290 if (IScsiController != NULL) {
291 IScsiPrivateGuid = &gIScsiV6PrivateGuid;
292 Ipv6Flag = TRUE;
293 } else {
294 return EFI_UNSUPPORTED;
295 }
296 }
297
298 //
299 // Retrieve an instance of a produced protocol from IScsiController
300 //
301 Status = gBS->OpenProtocol (
302 IScsiController,
303 IScsiPrivateGuid,
304 (VOID **) &IScsiIdentifier,
305 NULL,
306 NULL,
307 EFI_OPEN_PROTOCOL_GET_PROTOCOL
308 );
309 if (EFI_ERROR (Status)) {
310 return Status;
311 }
312
313 Status = UpdateName(IScsiController, Ipv6Flag);
314 if (EFI_ERROR(Status)) {
315 return Status;
316 }
317
318 return LookupUnicodeString2 (
319 Language,
320 This->SupportedLanguages,
321 gIScsiControllerNameTable,
322 ControllerName,
323 (BOOLEAN)(This == &gIScsiComponentName)
324 );
325 }