]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.c
Verified ChildHandle, and correct the name for a child.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / ComponentName.c
CommitLineData
12618416 1/** @file\r
f69bf3f5 2 UEFI Component Name(2) protocol implementation for iSCSI.\r
6a690e23 3\r
c615a4bc 4Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
7a444476 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
6a690e23 12\r
12618416 13**/\r
6a690e23 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
12618416 36 {"eng;en", L"iSCSI Driver"}, \r
37 {NULL, NULL}\r
6a690e23 38};\r
39\r
c615a4bc 40GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *mIScsiControllerNameTable = NULL;\r
216f7970 41\r
12618416 42/**\r
43 Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
44\r
45 This function retrieves the user readable name of a driver in the form of a\r
46 Unicode string. If the driver specified by This has a user readable name in\r
47 the language specified by Language, then a pointer to the driver name is\r
48 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
49 by This does not support the language specified by Language,\r
50 then EFI_UNSUPPORTED is returned.\r
f69bf3f5 51 \r
52 @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
53 @param[in] Language A pointer to a three character ISO 639-2 language identifier.\r
54 This is the language of the driver name that that the caller\r
55 is requesting, and it must match one of the languages specified\r
56 in SupportedLanguages. The number of languages supported by a\r
57 driver is up to the driver writer.\r
58 @param[out] DriverName A pointer to the Unicode string to return. This Unicode string\r
59 is the name of the driver specified by This in the language\r
60 specified by Language.\r
61\r
62 @retval EFI_SUCCESS The Unicode string for the Driver specified by This\r
63 and the language specified by Language was returned\r
64 in DriverName.\r
12618416 65 @retval EFI_INVALID_PARAMETER Language is NULL.\r
12618416 66 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
f69bf3f5 67 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
68 language specified by Language.\r
12618416 69**/\r
6a690e23 70EFI_STATUS\r
71EFIAPI\r
72IScsiComponentNameGetDriverName (\r
73 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
74 IN CHAR8 *Language,\r
75 OUT CHAR16 **DriverName\r
76 )\r
6a690e23 77{\r
78 return LookupUnicodeString2 (\r
79 Language,\r
80 This->SupportedLanguages,\r
81 mIScsiDriverNameTable,\r
82 DriverName,\r
83 (BOOLEAN)(This == &gIScsiComponentName)\r
84 );\r
85}\r
86\r
c615a4bc
WJ
87/**\r
88 Update the component name for the iSCSI instance.\r
89\r
90 @param[in] IScsiExtScsiPassThru A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
91 \r
92 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
93 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
94 @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.\r
95 \r
96**/\r
97EFI_STATUS\r
98UpdateName (\r
99 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru\r
100 )\r
101{\r
102 EFI_STATUS Status;\r
103 CHAR16 HandleName[150];\r
104 ISCSI_DRIVER_DATA *Private;\r
105 EFI_MAC_ADDRESS MacAddress;\r
106 UINTN HwAddressSize;\r
107 UINT16 VlanId;\r
108 CHAR16 MacString[70];\r
109\r
110 if (IScsiExtScsiPassThru == NULL) {\r
111 return EFI_INVALID_PARAMETER;\r
112 }\r
113 \r
114 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPassThru);\r
115\r
116 //\r
117 // Get the mac string, it's the name of various variable\r
118 //\r
119 Status = NetLibGetMacAddress (Private->Controller, &MacAddress, &HwAddressSize);\r
120 if (EFI_ERROR (Status)) {\r
121 return Status;\r
122 }\r
123 VlanId = NetLibGetVlanId (Private->Controller);\r
124 IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacString);\r
125 \r
126 UnicodeSPrint (\r
127 HandleName,\r
128 sizeof (HandleName),\r
129 L"iSCSI IPv4 (MacString=%s)",\r
130 MacString\r
131 );\r
132\r
133 if (mIScsiControllerNameTable != NULL) {\r
134 FreeUnicodeStringTable (mIScsiControllerNameTable);\r
135 mIScsiControllerNameTable = NULL;\r
136 }\r
137\r
138 Status = AddUnicodeString2 (\r
139 "eng",\r
140 gIScsiComponentName.SupportedLanguages,\r
141 &mIScsiControllerNameTable,\r
142 HandleName,\r
143 TRUE\r
144 );\r
145 if (EFI_ERROR (Status)) {\r
146 return Status;\r
147 }\r
148\r
149 return AddUnicodeString2 (\r
150 "en",\r
151 gIScsiComponentName2.SupportedLanguages,\r
152 &mIScsiControllerNameTable,\r
153 HandleName,\r
154 FALSE\r
155 );\r
156}\r
157\r
12618416 158/**\r
159 Retrieves a Unicode string that is the user readable name of the controller\r
f69bf3f5 160 that is being managed by an EFI Driver.Currently not implemented.\r
161\r
162 @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
163 @param[in] ControllerHandle The handle of a controller that the driver specified by\r
164 This is managing. This handle specifies the controller\r
165 whose name is to be returned.\r
166 @param[in] ChildHandle The handle of the child controller to retrieve the name\r
167 of. This is an optional parameter that may be NULL. It\r
168 will be NULL for device drivers. It will also be NULL\r
169 for a bus drivers that wish to retrieve the name of the\r
170 bus controller. It will not be NULL for a bus driver\r
171 that wishes to retrieve the name of a child controller.\r
172 @param[in] Language A pointer to a three character ISO 639-2 language\r
173 identifier. This is the language of the controller name\r
174 that that the caller is requesting, and it must match one\r
175 of the languages specified in SupportedLanguages. The\r
176 number of languages supported by a driver is up to the\r
177 driver writer.\r
178 @param[out] ControllerName A pointer to the Unicode string to return. This Unicode\r
179 string is the name of the controller specified by\r
180 ControllerHandle and ChildHandle in the language specified\r
181 by Language from the point of view of the driver specified\r
182 by This.\r
183\r
184 @retval EFI_SUCCESS The Unicode string for the user readable name in the\r
185 language specified by Language for the driver\r
186 specified by This was returned in DriverName. \r
284ee2e8 187 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
12618416 188 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
12618416 189 @retval EFI_INVALID_PARAMETER Language is NULL.\r
12618416 190 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
12618416 191 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing\r
f69bf3f5 192 the controller specified by ControllerHandle and\r
193 ChildHandle.\r
194 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
12618416 195 language specified by Language.\r
12618416 196**/\r
6a690e23 197EFI_STATUS\r
198EFIAPI\r
199IScsiComponentNameGetControllerName (\r
200 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
201 IN EFI_HANDLE ControllerHandle,\r
202 IN EFI_HANDLE ChildHandle OPTIONAL,\r
203 IN CHAR8 *Language,\r
204 OUT CHAR16 **ControllerName\r
205 )\r
6a690e23 206{\r
c615a4bc
WJ
207 EFI_STATUS Status;\r
208\r
216f7970 209 EFI_HANDLE IScsiController;\r
210 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;\r
c615a4bc
WJ
211\r
212 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru;\r
213\r
214 if (ControllerHandle == NULL) {\r
215 return EFI_UNSUPPORTED;\r
216 }\r
217\r
216f7970 218 //\r
219 // Get the handle of the controller we are controling.\r
220 //\r
221 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
222 if (IScsiController == NULL) {\r
223 return EFI_UNSUPPORTED;\r
224 }\r
225\r
226 Status = gBS->OpenProtocol (\r
227 IScsiController,\r
228 &gEfiCallerIdGuid,\r
229 (VOID **)&IScsiIdentifier,\r
230 NULL,\r
231 NULL,\r
232 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
233 );\r
234 if (EFI_ERROR (Status)) {\r
235 return Status;\r
236 }\r
c615a4bc
WJ
237\r
238 if (ChildHandle != NULL) {\r
239 //\r
240 // Make sure this driver produced ChildHandle\r
241 //\r
242 Status = EfiTestChildHandle (\r
243 ControllerHandle,\r
244 ChildHandle,\r
245 &gEfiTcp4ProtocolGuid\r
246 );\r
247 if (!EFI_ERROR (Status)) {\r
248 //\r
249 // Retrieve an instance of a produced protocol from ChildHandle\r
250 //\r
251 Status = gBS->OpenProtocol (\r
252 ChildHandle,\r
253 &gEfiExtScsiPassThruProtocolGuid,\r
254 (VOID **)&IScsiExtScsiPassThru,\r
255 NULL,\r
256 NULL,\r
257 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
258 );\r
259 if (EFI_ERROR (Status)) {\r
260 return Status;\r
261 }\r
262\r
263 //\r
264 // Update the component name for this child handle.\r
265 //\r
266 Status = UpdateName (IScsiExtScsiPassThru);\r
267 if (EFI_ERROR (Status)) {\r
268 return Status;\r
269 }\r
270 } else {\r
271 return Status;\r
272 }\r
273 }\r
216f7970 274 \r
275 return LookupUnicodeString2 (\r
276 Language,\r
277 This->SupportedLanguages,\r
278 mIScsiControllerNameTable,\r
279 ControllerName,\r
280 (BOOLEAN)(This == &gIScsiComponentName)\r
281 );\r
6a690e23 282}\r
216f7970 283\r