]>
Commit | Line | Data |
---|---|---|
4c5a5e0c | 1 | /** @file\r |
2 | UEFI Component Name(2) protocol implementation for iSCSI.\r | |
3 | \r | |
f75a7f56 | 4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r |
ecf98fbc | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4c5a5e0c | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "IScsiImpl.h"\r | |
10 | \r | |
11 | //\r | |
12 | // EFI Component Name Protocol\r | |
13 | //\r | |
d1050b9d | 14 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName = {\r |
4c5a5e0c | 15 | IScsiComponentNameGetDriverName,\r |
16 | IScsiComponentNameGetControllerName,\r | |
17 | "eng"\r | |
18 | };\r | |
19 | \r | |
20 | //\r | |
21 | // EFI Component Name 2 Protocol\r | |
22 | //\r | |
d1050b9d MK |
23 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIScsiComponentName2 = {\r |
24 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)IScsiComponentNameGetDriverName,\r | |
25 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)IScsiComponentNameGetControllerName,\r | |
4c5a5e0c | 26 | "en"\r |
27 | };\r | |
28 | \r | |
d1050b9d | 29 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable[] = {\r |
4c5a5e0c | 30 | {\r |
31 | "eng;en",\r | |
32 | L"iSCSI Driver"\r | |
33 | },\r | |
34 | {\r | |
35 | NULL,\r | |
36 | NULL\r | |
37 | }\r | |
38 | };\r | |
39 | \r | |
216f7970 | 40 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIScsiControllerNameTable = NULL;\r |
41 | \r | |
4c5a5e0c | 42 | /**\r |
43 | Retrieves a Unicode string that is the user readable name of the 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 | |
51 | \r | |
52 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
53 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
54 | \r | |
55 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
56 | array indicating the language. This is the\r | |
57 | language of the driver name that the caller is\r | |
58 | requesting, and it must match one of the\r | |
59 | languages specified in SupportedLanguages. The\r | |
60 | number of languages supported by a driver is up\r | |
61 | to the driver writer. Language is specified\r | |
62 | in RFC 4646 or ISO 639-2 language code format.\r | |
63 | \r | |
64 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
65 | This Unicode string is the name of the\r | |
66 | driver specified by This in the language\r | |
67 | specified by Language.\r | |
68 | \r | |
69 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
70 | This and the language specified by Language was\r | |
71 | returned in DriverName.\r | |
72 | \r | |
73 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
74 | \r | |
75 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
76 | \r | |
77 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
78 | the language specified by Language.\r | |
79 | \r | |
80 | **/\r | |
81 | EFI_STATUS\r | |
82 | EFIAPI\r | |
83 | IScsiComponentNameGetDriverName (\r | |
d1050b9d MK |
84 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
85 | IN CHAR8 *Language,\r | |
86 | OUT CHAR16 **DriverName\r | |
4c5a5e0c | 87 | )\r |
88 | {\r | |
89 | return LookupUnicodeString2 (\r | |
90 | Language,\r | |
91 | This->SupportedLanguages,\r | |
92 | mIScsiDriverNameTable,\r | |
93 | DriverName,\r | |
d1050b9d | 94 | (BOOLEAN)(This == &gIScsiComponentName)\r |
4c5a5e0c | 95 | );\r |
96 | }\r | |
97 | \r | |
216f7970 | 98 | /**\r |
2709d2fb | 99 | Update the component name for the iSCSI instance.\r |
216f7970 | 100 | \r |
2709d2fb | 101 | @param[in] IScsiExtScsiPassThru A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r |
216f7970 | 102 | @param[in] Ipv6Flag TRUE if IP6 network stack is used.\r |
f75a7f56 | 103 | \r |
216f7970 | 104 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r |
105 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
106 | @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.\r | |
f75a7f56 | 107 | \r |
216f7970 | 108 | **/\r |
109 | EFI_STATUS\r | |
110 | UpdateName (\r | |
d1050b9d MK |
111 | IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru,\r |
112 | IN BOOLEAN Ipv6Flag\r | |
216f7970 | 113 | )\r |
114 | {\r | |
d1050b9d MK |
115 | EFI_STATUS Status;\r |
116 | CHAR16 HandleName[80];\r | |
117 | ISCSI_DRIVER_DATA *Private;\r | |
118 | UINT8 NicIndex;\r | |
216f7970 | 119 | \r |
2709d2fb WJ |
120 | if (IScsiExtScsiPassThru == NULL) {\r |
121 | return EFI_INVALID_PARAMETER;\r | |
216f7970 | 122 | }\r |
f75a7f56 | 123 | \r |
2709d2fb WJ |
124 | Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPassThru);\r |
125 | NicIndex = Private->Session->ConfigData->NicIndex;\r | |
f75a7f56 | 126 | \r |
216f7970 | 127 | UnicodeSPrint (\r |
128 | HandleName,\r | |
129 | sizeof (HandleName),\r | |
130 | L"iSCSI (%s, NicIndex=%d)",\r | |
131 | Ipv6Flag ? L"IPv6" : L"IPv4",\r | |
2709d2fb | 132 | NicIndex\r |
d1050b9d | 133 | );\r |
216f7970 | 134 | \r |
135 | if (gIScsiControllerNameTable != NULL) {\r | |
136 | FreeUnicodeStringTable (gIScsiControllerNameTable);\r | |
137 | gIScsiControllerNameTable = NULL;\r | |
138 | }\r | |
139 | \r | |
140 | Status = AddUnicodeString2 (\r | |
141 | "eng",\r | |
142 | gIScsiComponentName.SupportedLanguages,\r | |
143 | &gIScsiControllerNameTable,\r | |
144 | HandleName,\r | |
145 | TRUE\r | |
146 | );\r | |
147 | if (EFI_ERROR (Status)) {\r | |
148 | return Status;\r | |
149 | }\r | |
150 | \r | |
151 | return AddUnicodeString2 (\r | |
152 | "en",\r | |
153 | gIScsiComponentName2.SupportedLanguages,\r | |
154 | &gIScsiControllerNameTable,\r | |
155 | HandleName,\r | |
156 | FALSE\r | |
157 | );\r | |
158 | }\r | |
159 | \r | |
4c5a5e0c | 160 | /**\r |
161 | Retrieves a Unicode string that is the user readable name of the controller\r | |
162 | that is being managed by a driver.\r | |
163 | \r | |
164 | This function retrieves the user readable name of the controller specified by\r | |
165 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
166 | driver specified by This has a user readable name in the language specified by\r | |
167 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
168 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
169 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
170 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
171 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
172 | \r | |
173 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
174 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
175 | \r | |
176 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
177 | specified by This is managing. This handle\r | |
178 | specifies the controller whose name is to be\r | |
179 | returned.\r | |
180 | \r | |
181 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
182 | the name of. This is an optional parameter that\r | |
183 | may be NULL. It will be NULL for device\r | |
184 | drivers. It will also be NULL for a bus drivers\r | |
185 | that wish to retrieve the name of the bus\r | |
186 | controller. It will not be NULL for a bus\r | |
187 | driver that wishes to retrieve the name of a\r | |
188 | child controller.\r | |
189 | \r | |
190 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
191 | array indicating the language. This is the\r | |
192 | language of the driver name that the caller is\r | |
193 | requesting, and it must match one of the\r | |
194 | languages specified in SupportedLanguages. The\r | |
195 | number of languages supported by a driver is up\r | |
196 | to the driver writer. Language is specified in\r | |
197 | RFC 4646 or ISO 639-2 language code format.\r | |
198 | \r | |
199 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
200 | This Unicode string is the name of the\r | |
201 | controller specified by ControllerHandle and\r | |
202 | ChildHandle in the language specified by\r | |
203 | Language, from the point of view of the driver\r | |
204 | specified by This.\r | |
205 | \r | |
206 | @retval EFI_SUCCESS The Unicode string for the user readable name in\r | |
207 | the language specified by Language for the\r | |
208 | driver specified by This was returned in\r | |
209 | DriverName.\r | |
210 | \r | |
211 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r | |
212 | \r | |
213 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
214 | EFI_HANDLE.\r | |
215 | \r | |
216 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
217 | \r | |
218 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
219 | \r | |
220 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
221 | managing the controller specified by\r | |
222 | ControllerHandle and ChildHandle.\r | |
223 | \r | |
224 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
225 | the language specified by Language.\r | |
226 | \r | |
227 | **/\r | |
228 | EFI_STATUS\r | |
229 | EFIAPI\r | |
230 | IScsiComponentNameGetControllerName (\r | |
d1050b9d MK |
231 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
232 | IN EFI_HANDLE ControllerHandle,\r | |
233 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
234 | IN CHAR8 *Language,\r | |
235 | OUT CHAR16 **ControllerName\r | |
4c5a5e0c | 236 | )\r |
237 | {\r | |
d1050b9d | 238 | EFI_STATUS Status;\r |
f75a7f56 | 239 | \r |
d1050b9d MK |
240 | EFI_HANDLE IScsiController;\r |
241 | BOOLEAN Ipv6Flag;\r | |
242 | EFI_GUID *IScsiPrivateGuid;\r | |
243 | ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;\r | |
f75a7f56 | 244 | \r |
d1050b9d | 245 | EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru;\r |
f75a7f56 | 246 | \r |
2709d2fb WJ |
247 | if (ControllerHandle == NULL) {\r |
248 | return EFI_UNSUPPORTED;\r | |
249 | }\r | |
216f7970 | 250 | \r |
251 | //\r | |
efb56593 | 252 | // Get the handle of the controller we are controlling.\r |
216f7970 | 253 | //\r |
254 | IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r | |
255 | if (IScsiController != NULL) {\r | |
256 | IScsiPrivateGuid = &gIScsiV4PrivateGuid;\r | |
d1050b9d | 257 | Ipv6Flag = FALSE;\r |
216f7970 | 258 | } else {\r |
259 | IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);\r | |
260 | if (IScsiController != NULL) {\r | |
261 | IScsiPrivateGuid = &gIScsiV6PrivateGuid;\r | |
d1050b9d | 262 | Ipv6Flag = TRUE;\r |
216f7970 | 263 | } else {\r |
264 | return EFI_UNSUPPORTED;\r | |
265 | }\r | |
266 | }\r | |
267 | \r | |
216f7970 | 268 | Status = gBS->OpenProtocol (\r |
269 | IScsiController,\r | |
270 | IScsiPrivateGuid,\r | |
d1050b9d | 271 | (VOID **)&IScsiIdentifier,\r |
216f7970 | 272 | NULL,\r |
273 | NULL,\r | |
274 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
275 | );\r | |
276 | if (EFI_ERROR (Status)) {\r | |
277 | return Status;\r | |
278 | }\r | |
279 | \r | |
d1050b9d MK |
280 | if (ChildHandle != NULL) {\r |
281 | if (!Ipv6Flag) {\r | |
2709d2fb WJ |
282 | //\r |
283 | // Make sure this driver produced ChildHandle\r | |
284 | //\r | |
285 | Status = EfiTestChildHandle (\r | |
286 | ControllerHandle,\r | |
287 | ChildHandle,\r | |
288 | &gEfiTcp4ProtocolGuid\r | |
289 | );\r | |
290 | if (EFI_ERROR (Status)) {\r | |
291 | return Status;\r | |
292 | }\r | |
293 | } else {\r | |
294 | //\r | |
295 | // Make sure this driver produced ChildHandle\r | |
296 | //\r | |
297 | Status = EfiTestChildHandle (\r | |
298 | ControllerHandle,\r | |
299 | ChildHandle,\r | |
300 | &gEfiTcp6ProtocolGuid\r | |
301 | );\r | |
302 | if (EFI_ERROR (Status)) {\r | |
303 | return Status;\r | |
304 | }\r | |
305 | }\r | |
f75a7f56 | 306 | \r |
2709d2fb WJ |
307 | //\r |
308 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
309 | //\r | |
310 | Status = gBS->OpenProtocol (\r | |
311 | ChildHandle,\r | |
312 | &gEfiExtScsiPassThruProtocolGuid,\r | |
d1050b9d | 313 | (VOID **)&IScsiExtScsiPassThru,\r |
2709d2fb WJ |
314 | NULL,\r |
315 | NULL,\r | |
316 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
317 | );\r | |
318 | if (EFI_ERROR (Status)) {\r | |
319 | return Status;\r | |
320 | }\r | |
f75a7f56 | 321 | \r |
2709d2fb WJ |
322 | //\r |
323 | // Update the component name for this child handle.\r | |
324 | //\r | |
325 | Status = UpdateName (IScsiExtScsiPassThru, Ipv6Flag);\r | |
326 | if (EFI_ERROR (Status)) {\r | |
327 | return Status;\r | |
328 | }\r | |
216f7970 | 329 | }\r |
330 | \r | |
331 | return LookupUnicodeString2 (\r | |
332 | Language,\r | |
333 | This->SupportedLanguages,\r | |
334 | gIScsiControllerNameTable,\r | |
335 | ControllerName,\r | |
336 | (BOOLEAN)(This == &gIScsiComponentName)\r | |
337 | );\r | |
4c5a5e0c | 338 | }\r |