]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Udp6Dxe/ComponentName.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / NetworkPkg / Udp6Dxe / ComponentName.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 UEFI Component Name(2) protocol implementation for UDP6 driver.\r
3\r
216f7970 4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "Udp6Impl.h"\r
17\r
18//\r
19// EFI Component Name Functions\r
20//\r
21/**\r
22 Retrieves a Unicode string that is the user-readable name of the driver.\r
23\r
24 This function retrieves the user-readable name of a driver in the form of a\r
25 Unicode string. If the driver specified by This has a user-readable name in\r
26 the language specified by Language, then a pointer to the driver name is\r
27 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
28 by This does not support the language specified by Language,\r
29 then EFI_UNSUPPORTED is returned.\r
30\r
31 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
32 EFI_COMPONENT_NAME_PROTOCOL instance.\r
33\r
34 @param[in] Language A pointer to a Null-terminated ASCII string\r
35 array indicating the language. This is the\r
36 language of the driver name that the caller is\r
37 requesting, and it must match one of the\r
38 languages specified in SupportedLanguages. The\r
39 number of languages supported by a driver is up\r
40 to the driver writer. Language is specified\r
41 in RFC 4646 or ISO 639-2 language code format.\r
42\r
43 @param[out] DriverName A pointer to the Unicode string to return.\r
44 This Unicode string is the name of the\r
45 driver specified by This in the language\r
46 specified by Language.\r
47\r
48 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
49 This and the language specified by Language was\r
50 returned in DriverName.\r
51\r
52 @retval EFI_INVALID_PARAMETER Language is NULL.\r
53\r
54 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
55\r
56 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
57 the language specified by Language.\r
58\r
59**/\r
60EFI_STATUS\r
61EFIAPI\r
62Udp6ComponentNameGetDriverName (\r
63 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
64 IN CHAR8 *Language,\r
65 OUT CHAR16 **DriverName\r
66 );\r
67\r
68\r
69/**\r
70 Retrieves a Unicode string that is the user-readable name of the controller\r
71 that is being managed by a driver.\r
72\r
73 This function retrieves the user-readable name of the controller specified by\r
74 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
75 driver specified by This has a user-readable name in the language specified by\r
76 Language, then a pointer to the controller name is returned in ControllerName,\r
77 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
78 managing the controller specified by ControllerHandle and ChildHandle,\r
79 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
80 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
81\r
82 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
83 EFI_COMPONENT_NAME_PROTOCOL instance.\r
84\r
85 @param[in] ControllerHandle The handle of a controller that the driver\r
86 specified by This is managing. This handle\r
87 specifies the controller whose name is to be\r
88 returned.\r
89\r
90 @param[in] ChildHandle The handle of the child controller to retrieve\r
91 the name of. This is an optional parameter that\r
92 may be NULL. It will be NULL for device\r
93 drivers. It will also be NULL for a bus drivers\r
94 that wish to retrieve the name of the bus\r
95 controller. It will not be NULL for a bus\r
96 driver that wishes to retrieve the name of a\r
97 child controller.\r
98\r
99 @param[in] Language A pointer to a Null-terminated ASCII string\r
100 array indicating the language. This is the\r
101 language of the driver name that the caller is\r
102 requesting, and it must match one of the\r
103 languages specified in SupportedLanguages. The\r
104 number of languages supported by a driver is up\r
105 to the driver writer. Language is specified in\r
106 RFC 4646 or ISO 639-2 language code format.\r
107\r
108 @param[out] ControllerName A pointer to the Unicode string to return.\r
109 This Unicode string is the name of the\r
110 controller specified by ControllerHandle and\r
111 ChildHandle in the language specified by\r
112 Language from the point of view of the driver\r
113 specified by This.\r
114\r
115 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
116 the language specified by Language for the\r
117 driver specified by This was returned in\r
118 DriverName.\r
119\r
15ee13fc 120 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
121\r
122 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
123 EFI_HANDLE.\r
124\r
125 @retval EFI_INVALID_PARAMETER Language is NULL.\r
126\r
127 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
128\r
129 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
130 managing the controller specified by\r
131 ControllerHandle and ChildHandle.\r
132\r
133 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
134 the language specified by Language.\r
135\r
136**/\r
137EFI_STATUS\r
138EFIAPI\r
139Udp6ComponentNameGetControllerName (\r
140 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
141 IN EFI_HANDLE ControllerHandle,\r
142 IN EFI_HANDLE ChildHandle OPTIONAL,\r
143 IN CHAR8 *Language,\r
144 OUT CHAR16 **ControllerName\r
145 );\r
146\r
147//\r
148// EFI Component Name Protocol\r
149//\r
150GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUdp6ComponentName = {\r
151 Udp6ComponentNameGetDriverName,\r
152 Udp6ComponentNameGetControllerName,\r
153 "eng"\r
154};\r
155\r
156//\r
157// EFI Component Name 2 Protocol\r
158//\r
159GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUdp6ComponentName2 = {\r
160 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Udp6ComponentNameGetDriverName,\r
161 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Udp6ComponentNameGetControllerName,\r
162 "en"\r
163};\r
164\r
165\r
166GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUdp6DriverNameTable[] = {\r
167 {\r
168 "eng;en",\r
169 L"UDP6 Network Service Driver"\r
170 },\r
171 {\r
172 NULL,\r
173 NULL\r
174 }\r
175};\r
176\r
216f7970 177GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gUdp6ControllerNameTable = NULL;\r
178\r
a3bcde70
HT
179/**\r
180 Retrieves a Unicode string that is the user-readable name of the driver.\r
181\r
182 This function retrieves the user-readable name of a driver in the form of a\r
183 Unicode string. If the driver specified by This has a user-readable name in\r
184 the language specified by Language, then a pointer to the driver name is\r
185 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
186 by This does not support the language specified by Language,\r
187 then EFI_UNSUPPORTED is returned.\r
188\r
189 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
190 EFI_COMPONENT_NAME_PROTOCOL instance.\r
191\r
192 @param[in] Language A pointer to a Null-terminated ASCII string\r
193 array indicating the language. This is the\r
194 language of the driver name that the caller is\r
195 requesting, and it must match one of the\r
196 languages specified in SupportedLanguages. The\r
197 number of languages supported by a driver is up\r
198 to the driver writer. Language is specified\r
199 in RFC 4646 or ISO 639-2 language code format.\r
200\r
201 @param[out] DriverName A pointer to the Unicode string to return.\r
202 This Unicode string is the name of the\r
203 driver specified by This in the language\r
204 specified by Language.\r
205\r
206 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
207 This and the language specified by Language was\r
208 returned in DriverName.\r
209\r
210 @retval EFI_INVALID_PARAMETER Language is NULL.\r
211\r
212 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
213\r
214 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
215 the language specified by Language.\r
216\r
217**/\r
218EFI_STATUS\r
219EFIAPI\r
220Udp6ComponentNameGetDriverName (\r
221 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
222 IN CHAR8 *Language,\r
223 OUT CHAR16 **DriverName\r
224 )\r
225{\r
226 return LookupUnicodeString2 (\r
227 Language,\r
228 This->SupportedLanguages,\r
229 mUdp6DriverNameTable,\r
230 DriverName,\r
231 (BOOLEAN) (This == &gUdp6ComponentName)\r
232 );\r
233}\r
234\r
216f7970 235/**\r
236 Update the component name for the Udp6 child handle.\r
237\r
238 @param Udp6[in] A pointer to the EFI_UDP6_PROTOCOL.\r
239\r
240 \r
241 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
242 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
243 \r
244**/\r
245EFI_STATUS\r
246UpdateName (\r
247 IN EFI_UDP6_PROTOCOL *Udp6\r
248 )\r
249{\r
250 EFI_STATUS Status;\r
251 CHAR16 HandleName[64];\r
252 EFI_UDP6_CONFIG_DATA Udp6ConfigData;\r
253\r
254 if (Udp6 == NULL) {\r
255 return EFI_INVALID_PARAMETER;\r
256 }\r
257\r
258 //\r
259 // Format the child name into the string buffer.\r
260 //\r
261 Status = Udp6->GetModeData (Udp6, &Udp6ConfigData, NULL, NULL, NULL);\r
262 if (!EFI_ERROR (Status)) {\r
263 UnicodeSPrint (HandleName, sizeof (HandleName),\r
264 L"UDPv6 (SrcPort=%d, DestPort=%d)",\r
265 Udp6ConfigData.StationPort,\r
266 Udp6ConfigData.RemotePort\r
267 );\r
268 } else if (Status == EFI_NOT_STARTED) {\r
269 UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (Not started)");\r
270 } else {\r
271 UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (%r)", Status);\r
272 }\r
273\r
274 if (gUdp6ControllerNameTable != NULL) {\r
275 FreeUnicodeStringTable (gUdp6ControllerNameTable);\r
276 gUdp6ControllerNameTable = NULL;\r
277 }\r
278\r
279 Status = AddUnicodeString2 (\r
280 "eng",\r
281 gUdp6ComponentName.SupportedLanguages,\r
282 &gUdp6ControllerNameTable,\r
283 HandleName,\r
284 TRUE\r
285 );\r
286 if (EFI_ERROR (Status)) {\r
287 return Status;\r
288 }\r
289\r
290 return AddUnicodeString2 (\r
291 "en",\r
292 gUdp6ComponentName2.SupportedLanguages,\r
293 &gUdp6ControllerNameTable,\r
294 HandleName,\r
295 FALSE\r
296 );\r
297}\r
298\r
a3bcde70
HT
299/**\r
300 Retrieves a Unicode string that is the user-readable name of the controller\r
301 that is being managed by a driver.\r
302\r
303 This function retrieves the user-readable name of the controller specified by\r
304 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
305 driver specified by This has a user-readable name in the language specified by\r
306 Language, then a pointer to the controller name is returned in ControllerName,\r
307 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
308 managing the controller specified by ControllerHandle and ChildHandle,\r
309 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
310 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
311\r
312 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
313 EFI_COMPONENT_NAME_PROTOCOL instance.\r
314\r
315 @param[in] ControllerHandle The handle of a controller that the driver\r
316 specified by This is managing. This handle\r
317 specifies the controller whose name is to be\r
318 returned.\r
319\r
320 @param[in] ChildHandle The handle of the child controller to retrieve\r
321 the name of. This is an optional parameter that\r
322 may be NULL. It will be NULL for device\r
323 drivers. It will also be NULL for a bus drivers\r
324 that wish to retrieve the name of the bus\r
325 controller. It will not be NULL for a bus\r
326 driver that wishes to retrieve the name of a\r
327 child controller.\r
328\r
329 @param[in] Language A pointer to a Null-terminated ASCII string\r
330 array indicating the language. This is the\r
331 language of the driver name that the caller is\r
332 requesting, and it must match one of the\r
333 languages specified in SupportedLanguages. The\r
334 number of languages supported by a driver is up\r
335 to the driver writer. Language is specified in\r
336 RFC 4646 or ISO 639-2 language code format.\r
337\r
338 @param[out] ControllerName A pointer to the Unicode string to return.\r
339 This Unicode string is the name of the\r
340 controller specified by ControllerHandle and\r
341 ChildHandle in the language specified by\r
342 Language from the point of view of the driver\r
343 specified by This.\r
344\r
345 @retval EFI_SUCCESS The Unicode string for the user-readable name in\r
346 the language specified by Language for the\r
347 driver specified by This was returned in\r
348 DriverName.\r
349\r
15ee13fc 350 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
a3bcde70
HT
351\r
352 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
353 EFI_HANDLE.\r
354\r
355 @retval EFI_INVALID_PARAMETER Language is NULL.\r
356\r
357 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
358\r
359 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
360 managing the controller specified by\r
361 ControllerHandle and ChildHandle.\r
362\r
363 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
364 the language specified by Language.\r
365\r
366**/\r
367EFI_STATUS\r
368EFIAPI\r
369Udp6ComponentNameGetControllerName (\r
370 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
371 IN EFI_HANDLE ControllerHandle,\r
372 IN EFI_HANDLE ChildHandle OPTIONAL,\r
373 IN CHAR8 *Language,\r
374 OUT CHAR16 **ControllerName\r
375 )\r
376{\r
216f7970 377 EFI_STATUS Status;\r
378 EFI_UDP6_PROTOCOL *Udp6;\r
379\r
380 //\r
381 // Only provide names for child handles.\r
382 //\r
383 if (ChildHandle == NULL) {\r
384 return EFI_UNSUPPORTED;\r
385 }\r
386\r
387 //\r
388 // Make sure this driver produced ChildHandle\r
389 //\r
390 Status = EfiTestChildHandle (\r
391 ControllerHandle,\r
392 ChildHandle,\r
393 &gEfiIp6ProtocolGuid\r
394 );\r
395 if (EFI_ERROR (Status)) {\r
396 return Status;\r
397 }\r
398\r
399 //\r
400 // Retrieve an instance of a produced protocol from ChildHandle\r
401 //\r
402 Status = gBS->OpenProtocol (\r
403 ChildHandle,\r
404 &gEfiUdp6ProtocolGuid,\r
405 (VOID **)&Udp6,\r
406 NULL,\r
407 NULL,\r
408 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
409 );\r
410 if (EFI_ERROR (Status)) {\r
411 return Status;\r
412 }\r
413\r
414 //\r
415 // Update the component name for this child handle.\r
416 //\r
417 Status = UpdateName (Udp6);\r
418 if (EFI_ERROR (Status)) {\r
419 return Status;\r
420 }\r
a3bcde70 421\r
216f7970 422 return LookupUnicodeString2 (\r
423 Language,\r
424 This->SupportedLanguages,\r
425 gUdp6ControllerNameTable,\r
426 ControllerName,\r
427 (BOOLEAN)(This == &gUdp6ComponentName)\r
428 );\r
429}\r