]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IScsiDxe/ComponentName.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / ComponentName.c
CommitLineData
4c5a5e0c 1/** @file\r
2 UEFI Component Name(2) protocol implementation for iSCSI.\r
3\r
216f7970 4Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
4c5a5e0c 5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "IScsiImpl.h"\r
16\r
17//\r
18// EFI Component Name Protocol\r
19//\r
20GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName = {\r
21 IScsiComponentNameGetDriverName,\r
22 IScsiComponentNameGetControllerName,\r
23 "eng"\r
24};\r
25\r
26//\r
27// EFI Component Name 2 Protocol\r
28//\r
29GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIScsiComponentName2 = {\r
30 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IScsiComponentNameGetDriverName,\r
31 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IScsiComponentNameGetControllerName,\r
32 "en"\r
33};\r
34\r
35GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable[] = {\r
36 {\r
37 "eng;en",\r
38 L"iSCSI Driver"\r
39 },\r
40 {\r
41 NULL,\r
42 NULL\r
43 }\r
44};\r
45\r
216f7970 46GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIScsiControllerNameTable = NULL;\r
47\r
4c5a5e0c 48/**\r
49 Retrieves a Unicode string that is the user readable name of the driver.\r
50\r
51 This function retrieves the user readable name of a driver in the form of a\r
52 Unicode string. If the driver specified by This has a user readable name in\r
53 the language specified by Language, then a pointer to the driver name is\r
54 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
55 by This does not support the language specified by Language,\r
56 then EFI_UNSUPPORTED is returned.\r
57\r
58 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
59 EFI_COMPONENT_NAME_PROTOCOL instance.\r
60\r
61 @param[in] Language A pointer to a Null-terminated ASCII string\r
62 array indicating the language. This is the\r
63 language of the driver name that the caller is\r
64 requesting, and it must match one of the\r
65 languages specified in SupportedLanguages. The\r
66 number of languages supported by a driver is up\r
67 to the driver writer. Language is specified\r
68 in RFC 4646 or ISO 639-2 language code format.\r
69\r
70 @param[out] DriverName A pointer to the Unicode string to return.\r
71 This Unicode string is the name of the\r
72 driver specified by This in the language\r
73 specified by Language.\r
74\r
75 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
76 This and the language specified by Language was\r
77 returned in DriverName.\r
78\r
79 @retval EFI_INVALID_PARAMETER Language is NULL.\r
80\r
81 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
82\r
83 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
84 the language specified by Language.\r
85\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89IScsiComponentNameGetDriverName (\r
90 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
91 IN CHAR8 *Language,\r
92 OUT CHAR16 **DriverName\r
93 )\r
94{\r
95 return LookupUnicodeString2 (\r
96 Language,\r
97 This->SupportedLanguages,\r
98 mIScsiDriverNameTable,\r
99 DriverName,\r
100 (BOOLEAN) (This == &gIScsiComponentName)\r
101 );\r
102}\r
103\r
216f7970 104/**\r
105 Update the component name for the iSCSI NIC handle.\r
106\r
107 @param[in] Controller The handle of the NIC controller.\r
108 @param[in] Ipv6Flag TRUE if IP6 network stack is used.\r
109 \r
110 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
111 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
112 @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.\r
113 \r
114**/\r
115EFI_STATUS\r
116UpdateName (\r
117 IN EFI_HANDLE Controller,\r
118 IN BOOLEAN Ipv6Flag\r
119 )\r
120{\r
121 EFI_STATUS Status;\r
122 EFI_MAC_ADDRESS MacAddr;\r
123 UINTN HwAddressSize;\r
124 UINT16 VlanId;\r
125 ISCSI_NIC_INFO *ThisNic;\r
126 ISCSI_NIC_INFO *NicInfo;\r
127 LIST_ENTRY *Entry;\r
128 CHAR16 HandleName[80];\r
129\r
130 //\r
131 // Get MAC address of this network device.\r
132 //\r
133 Status = NetLibGetMacAddress (Controller, &MacAddr, &HwAddressSize);\r
134 if (EFI_ERROR (Status)) {\r
135 return Status;\r
136 }\r
137\r
138 //\r
139 // Get VLAN ID of this network device.\r
140 //\r
141 VlanId = NetLibGetVlanId (Controller);\r
142\r
143 //\r
144 // Check whether the NIC information exists.\r
145 //\r
146 ThisNic = NULL;\r
147\r
148 NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {\r
149 NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);\r
150 if (NicInfo->HwAddressSize == HwAddressSize &&\r
151 CompareMem (&NicInfo->PermanentAddress, MacAddr.Addr, HwAddressSize) == 0 &&\r
152 NicInfo->VlanId == VlanId) {\r
153\r
154 ThisNic = NicInfo;\r
155 break;\r
156 }\r
157 }\r
158\r
159 if (ThisNic == NULL) {\r
160 return EFI_UNSUPPORTED;\r
161 }\r
162\r
163 UnicodeSPrint (\r
164 HandleName,\r
165 sizeof (HandleName),\r
166 L"iSCSI (%s, NicIndex=%d)",\r
167 Ipv6Flag ? L"IPv6" : L"IPv4",\r
168 ThisNic->NicIndex\r
169 );\r
170\r
171 if (gIScsiControllerNameTable != NULL) {\r
172 FreeUnicodeStringTable (gIScsiControllerNameTable);\r
173 gIScsiControllerNameTable = NULL;\r
174 }\r
175\r
176 Status = AddUnicodeString2 (\r
177 "eng",\r
178 gIScsiComponentName.SupportedLanguages,\r
179 &gIScsiControllerNameTable,\r
180 HandleName,\r
181 TRUE\r
182 );\r
183 if (EFI_ERROR (Status)) {\r
184 return Status;\r
185 }\r
186\r
187 return AddUnicodeString2 (\r
188 "en",\r
189 gIScsiComponentName2.SupportedLanguages,\r
190 &gIScsiControllerNameTable,\r
191 HandleName,\r
192 FALSE\r
193 );\r
194}\r
195\r
196\r
4c5a5e0c 197/**\r
198 Retrieves a Unicode string that is the user readable name of the controller\r
199 that is being managed by a driver.\r
200\r
201 This function retrieves the user readable name of the controller specified by\r
202 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
203 driver specified by This has a user readable name in the language specified by\r
204 Language, then a pointer to the controller name is returned in ControllerName,\r
205 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
206 managing the controller specified by ControllerHandle and ChildHandle,\r
207 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
208 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
209\r
210 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
211 EFI_COMPONENT_NAME_PROTOCOL instance.\r
212\r
213 @param[in] ControllerHandle The handle of a controller that the driver\r
214 specified by This is managing. This handle\r
215 specifies the controller whose name is to be\r
216 returned.\r
217\r
218 @param[in] ChildHandle The handle of the child controller to retrieve\r
219 the name of. This is an optional parameter that\r
220 may be NULL. It will be NULL for device\r
221 drivers. It will also be NULL for a bus drivers\r
222 that wish to retrieve the name of the bus\r
223 controller. It will not be NULL for a bus\r
224 driver that wishes to retrieve the name of a\r
225 child controller.\r
226\r
227 @param[in] Language A pointer to a Null-terminated ASCII string\r
228 array indicating the language. This is the\r
229 language of the driver name that the caller is\r
230 requesting, and it must match one of the\r
231 languages specified in SupportedLanguages. The\r
232 number of languages supported by a driver is up\r
233 to the driver writer. Language is specified in\r
234 RFC 4646 or ISO 639-2 language code format.\r
235\r
236 @param[out] ControllerName A pointer to the Unicode string to return.\r
237 This Unicode string is the name of the\r
238 controller specified by ControllerHandle and\r
239 ChildHandle in the language specified by\r
240 Language, from the point of view of the driver\r
241 specified by This.\r
242\r
243 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
244 the language specified by Language for the\r
245 driver specified by This was returned in\r
246 DriverName.\r
247\r
248 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
249\r
250 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
251 EFI_HANDLE.\r
252\r
253 @retval EFI_INVALID_PARAMETER Language is NULL.\r
254\r
255 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
256\r
257 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
258 managing the controller specified by\r
259 ControllerHandle and ChildHandle.\r
260\r
261 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
262 the language specified by Language.\r
263\r
264**/\r
265EFI_STATUS\r
266EFIAPI\r
267IScsiComponentNameGetControllerName (\r
268 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
269 IN EFI_HANDLE ControllerHandle,\r
270 IN EFI_HANDLE ChildHandle OPTIONAL,\r
271 IN CHAR8 *Language,\r
272 OUT CHAR16 **ControllerName\r
273 )\r
274{\r
216f7970 275 EFI_HANDLE IScsiController;\r
276 BOOLEAN Ipv6Flag;\r
277 EFI_STATUS Status;\r
278 EFI_GUID *IScsiPrivateGuid;\r
279 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;\r
280\r
281 //\r
282 // Get the handle of the controller we are controling.\r
283 //\r
284 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
285 if (IScsiController != NULL) {\r
286 IScsiPrivateGuid = &gIScsiV4PrivateGuid;\r
287 Ipv6Flag = FALSE;\r
288 } else {\r
289 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);\r
290 if (IScsiController != NULL) {\r
291 IScsiPrivateGuid = &gIScsiV6PrivateGuid;\r
292 Ipv6Flag = TRUE;\r
293 } else {\r
294 return EFI_UNSUPPORTED;\r
295 }\r
296 }\r
297\r
298 // \r
299 // Retrieve an instance of a produced protocol from IScsiController \r
300 // \r
301 Status = gBS->OpenProtocol (\r
302 IScsiController,\r
303 IScsiPrivateGuid,\r
304 (VOID **) &IScsiIdentifier,\r
305 NULL,\r
306 NULL,\r
307 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
308 );\r
309 if (EFI_ERROR (Status)) {\r
310 return Status;\r
311 }\r
312\r
313 Status = UpdateName(IScsiController, Ipv6Flag);\r
314 if (EFI_ERROR(Status)) {\r
315 return Status;\r
316 }\r
317\r
318 return LookupUnicodeString2 (\r
319 Language,\r
320 This->SupportedLanguages,\r
321 gIScsiControllerNameTable,\r
322 ControllerName,\r
323 (BOOLEAN)(This == &gIScsiComponentName)\r
324 );\r
4c5a5e0c 325}\r