]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | Implementation of EFI_COMPONENT_NAME_PROTOCOL and\r | |
3 | EFI_COMPONENT_NAME2_PROTOCOL protocol.\r | |
4 | \r | |
f75a7f56 | 5 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
a3bcde70 | 6 | \r |
ecf98fbc | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a3bcde70 HT |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include "Ip6Impl.h"\r | |
12 | \r | |
13 | //\r | |
14 | // EFI Component Name Functions\r | |
15 | //\r | |
16 | \r | |
17 | /**\r | |
18 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
19 | \r | |
20 | This function retrieves the user-readable name of a driver in the form of a\r | |
21 | Unicode string. If the driver specified by This has a user-readable name in\r | |
22 | the language specified by Language, then a pointer to the driver name is\r | |
23 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
24 | by This does not support the language specified by Language,\r | |
25 | then EFI_UNSUPPORTED is returned.\r | |
26 | \r | |
27 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
28 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
29 | \r | |
30 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
31 | array indicating the language. This is the\r | |
32 | language of the driver name that the caller is\r | |
33 | requesting, and it must match one of the\r | |
34 | languages specified in SupportedLanguages. The\r | |
35 | number of languages supported by a driver is up\r | |
36 | to the driver writer. Language is specified\r | |
37 | in RFC 4646 or ISO 639-2 language code format.\r | |
38 | \r | |
39 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
40 | This Unicode string is the name of the\r | |
41 | driver specified by This in the language\r | |
42 | specified by Language.\r | |
43 | \r | |
44 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
45 | This and the language specified by Language was\r | |
46 | returned in DriverName.\r | |
47 | \r | |
48 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
49 | \r | |
50 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
51 | \r | |
52 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
53 | the language specified by Language.\r | |
54 | \r | |
55 | **/\r | |
56 | EFI_STATUS\r | |
57 | EFIAPI\r | |
58 | Ip6ComponentNameGetDriverName (\r | |
59 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
60 | IN CHAR8 *Language,\r | |
61 | OUT CHAR16 **DriverName\r | |
62 | );\r | |
63 | \r | |
64 | /**\r | |
65 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
66 | that is managed by a driver.\r | |
67 | \r | |
68 | This function retrieves the user-readable name of the controller specified by\r | |
69 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
70 | driver specified by This has a user-readable name in the language specified by\r | |
71 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
72 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
73 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
74 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
75 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
76 | \r | |
77 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
78 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
79 | \r | |
80 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
81 | specified by This is managing. This handle\r | |
82 | specifies the controller whose name is to be\r | |
83 | returned.\r | |
84 | \r | |
85 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
86 | the name of. This is an optional parameter that\r | |
87 | may be NULL. It will be NULL for device\r | |
88 | drivers. It will also be NULL for a bus drivers\r | |
89 | that wish to retrieve the name of the bus\r | |
90 | controller. It will not be NULL for a bus\r | |
91 | driver that wishes to retrieve the name of a\r | |
92 | child controller.\r | |
93 | \r | |
94 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
95 | array indicating the language. This is the\r | |
96 | language of the driver name that the caller is\r | |
97 | requesting, and it must match one of the\r | |
98 | languages specified in SupportedLanguages. The\r | |
99 | number of languages supported by a driver is up\r | |
100 | to the driver writer. Language is specified in\r | |
101 | RFC 4646 or ISO 639-2 language code format.\r | |
102 | \r | |
103 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
104 | This Unicode string is the name of the\r | |
105 | controller specified by ControllerHandle and\r | |
106 | ChildHandle in the language specified by\r | |
107 | Language from the point of view of the driver\r | |
108 | specified by This.\r | |
109 | \r | |
110 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
111 | the language specified by Language for the\r | |
112 | driver specified by This was returned in\r | |
113 | DriverName.\r | |
114 | \r | |
15ee13fc | 115 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
116 | \r |
117 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
118 | EFI_HANDLE.\r | |
119 | \r | |
120 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
121 | \r | |
122 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
123 | \r | |
124 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
125 | managing the controller specified by\r | |
126 | ControllerHandle and ChildHandle.\r | |
127 | \r | |
128 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
129 | the language specified by Language.\r | |
130 | \r | |
131 | **/\r | |
132 | EFI_STATUS\r | |
133 | EFIAPI\r | |
134 | Ip6ComponentNameGetControllerName (\r | |
135 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
136 | IN EFI_HANDLE ControllerHandle,\r | |
137 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
138 | IN CHAR8 *Language,\r | |
139 | OUT CHAR16 **ControllerName\r | |
140 | );\r | |
141 | \r | |
142 | //\r | |
143 | // EFI Component Name Protocol.\r | |
144 | //\r | |
145 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp6ComponentName = {\r | |
146 | Ip6ComponentNameGetDriverName,\r | |
147 | Ip6ComponentNameGetControllerName,\r | |
148 | "eng"\r | |
149 | };\r | |
150 | \r | |
151 | //\r | |
152 | // EFI Component Name 2 Protocol.\r | |
153 | //\r | |
154 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIp6ComponentName2 = {\r | |
155 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Ip6ComponentNameGetDriverName,\r | |
156 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Ip6ComponentNameGetControllerName,\r | |
157 | "en"\r | |
158 | };\r | |
159 | \r | |
160 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp6DriverNameTable[] = {\r | |
161 | {\r | |
162 | "eng;en",\r | |
163 | L"IP6 Network Service Driver"\r | |
164 | },\r | |
165 | {\r | |
166 | NULL,\r | |
167 | NULL\r | |
168 | }\r | |
169 | };\r | |
170 | \r | |
216f7970 | 171 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp6ControllerNameTable = NULL;\r |
172 | \r | |
a3bcde70 HT |
173 | /**\r |
174 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
175 | \r | |
176 | This function retrieves the user-readable name of a driver in the form of a\r | |
177 | Unicode string. If the driver specified by This has a user-readable name in\r | |
178 | the language specified by Language, then a pointer to the driver name is\r | |
179 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
180 | by This does not support the language specified by Language,\r | |
181 | then EFI_UNSUPPORTED is returned.\r | |
182 | \r | |
183 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
184 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
185 | \r | |
186 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
187 | array indicating the language. This is the\r | |
188 | language of the driver name that the caller is\r | |
189 | requesting, and it must match one of the\r | |
190 | languages specified in SupportedLanguages. The\r | |
191 | number of languages supported by a driver is up\r | |
192 | to the driver writer. Language is specified\r | |
193 | in RFC 4646 or ISO 639-2 language code format.\r | |
194 | \r | |
195 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
196 | This Unicode string is the name of the\r | |
197 | driver specified by This in the language\r | |
198 | specified by Language.\r | |
199 | \r | |
200 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
201 | This and the language specified by Language was\r | |
202 | returned in DriverName.\r | |
203 | \r | |
204 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
205 | \r | |
206 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
207 | \r | |
208 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
209 | the language specified by Language.\r | |
210 | \r | |
211 | **/\r | |
212 | EFI_STATUS\r | |
213 | EFIAPI\r | |
214 | Ip6ComponentNameGetDriverName (\r | |
215 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
216 | IN CHAR8 *Language,\r | |
217 | OUT CHAR16 **DriverName\r | |
218 | )\r | |
219 | {\r | |
220 | return LookupUnicodeString2 (\r | |
221 | Language,\r | |
222 | This->SupportedLanguages,\r | |
223 | mIp6DriverNameTable,\r | |
224 | DriverName,\r | |
225 | (BOOLEAN) (This == &gIp6ComponentName)\r | |
226 | );\r | |
227 | \r | |
228 | }\r | |
229 | \r | |
216f7970 | 230 | /**\r |
231 | Update the component name for the IP6 child handle.\r | |
232 | \r | |
233 | @param Ip6[in] A pointer to the EFI_IP6_PROTOCOL.\r | |
234 | \r | |
f75a7f56 | 235 | \r |
216f7970 | 236 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r |
237 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
f75a7f56 | 238 | \r |
216f7970 | 239 | **/\r |
240 | EFI_STATUS\r | |
241 | UpdateName (\r | |
242 | IN EFI_IP6_PROTOCOL *Ip6\r | |
243 | )\r | |
244 | {\r | |
245 | EFI_STATUS Status;\r | |
246 | CHAR16 HandleName[128];\r | |
247 | EFI_IP6_MODE_DATA Ip6ModeData;\r | |
248 | UINTN Offset;\r | |
249 | CHAR16 Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];\r | |
250 | \r | |
251 | if (Ip6 == NULL) {\r | |
252 | return EFI_INVALID_PARAMETER;\r | |
253 | }\r | |
254 | \r | |
255 | //\r | |
256 | // Format the child name into the string buffer.\r | |
257 | //\r | |
258 | Offset = 0;\r | |
259 | Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL);\r | |
ce22514e ZL |
260 | if (!EFI_ERROR (Status)) {\r |
261 | if (Ip6ModeData.AddressList != NULL) {\r | |
262 | FreePool (Ip6ModeData.AddressList);\r | |
263 | }\r | |
264 | \r | |
265 | if (Ip6ModeData.GroupTable != NULL) {\r | |
266 | FreePool (Ip6ModeData.GroupTable);\r | |
267 | }\r | |
268 | \r | |
269 | if (Ip6ModeData.RouteTable != NULL) {\r | |
270 | FreePool (Ip6ModeData.RouteTable);\r | |
271 | }\r | |
272 | \r | |
273 | if (Ip6ModeData.NeighborCache != NULL) {\r | |
274 | FreePool (Ip6ModeData.NeighborCache);\r | |
275 | }\r | |
276 | \r | |
277 | if (Ip6ModeData.PrefixTable != NULL) {\r | |
278 | FreePool (Ip6ModeData.PrefixTable);\r | |
279 | }\r | |
280 | \r | |
281 | if (Ip6ModeData.IcmpTypeList != NULL) {\r | |
282 | FreePool (Ip6ModeData.IcmpTypeList);\r | |
283 | }\r | |
284 | }\r | |
285 | \r | |
216f7970 | 286 | if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) {\r |
287 | Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof(Address));\r | |
288 | if (EFI_ERROR (Status)) {\r | |
289 | return Status;\r | |
290 | }\r | |
291 | Offset += UnicodeSPrint (\r | |
292 | HandleName,\r | |
293 | sizeof(HandleName),\r | |
294 | L"IPv6(StationAddress=%s, ",\r | |
295 | Address\r | |
296 | );\r | |
297 | Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.DestinationAddress, Address, sizeof(Address));\r | |
298 | if (EFI_ERROR (Status)) {\r | |
299 | return Status;\r | |
300 | }\r | |
301 | UnicodeSPrint (\r | |
302 | HandleName + Offset,\r | |
f8c075d1 | 303 | sizeof(HandleName) - Offset * sizeof (CHAR16),\r |
216f7970 | 304 | L"DestinationAddress=%s)",\r |
305 | Address\r | |
306 | );\r | |
307 | } else if (!Ip6ModeData.IsStarted) {\r | |
308 | UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(Not started)");\r | |
309 | } else {\r | |
310 | UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(%r)", Status);\r | |
311 | }\r | |
312 | \r | |
313 | if (gIp6ControllerNameTable != NULL) {\r | |
314 | FreeUnicodeStringTable (gIp6ControllerNameTable);\r | |
315 | gIp6ControllerNameTable = NULL;\r | |
316 | }\r | |
f75a7f56 | 317 | \r |
216f7970 | 318 | Status = AddUnicodeString2 (\r |
319 | "eng",\r | |
320 | gIp6ComponentName.SupportedLanguages,\r | |
321 | &gIp6ControllerNameTable,\r | |
322 | HandleName,\r | |
323 | TRUE\r | |
324 | );\r | |
325 | if (EFI_ERROR (Status)) {\r | |
326 | return Status;\r | |
327 | }\r | |
f75a7f56 | 328 | \r |
216f7970 | 329 | return AddUnicodeString2 (\r |
330 | "en",\r | |
331 | gIp6ComponentName2.SupportedLanguages,\r | |
332 | &gIp6ControllerNameTable,\r | |
333 | HandleName,\r | |
334 | FALSE\r | |
335 | );\r | |
336 | }\r | |
337 | \r | |
a3bcde70 HT |
338 | /**\r |
339 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
340 | that is being managed by a driver.\r | |
341 | \r | |
342 | This function retrieves the user-readable name of the controller specified by\r | |
343 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
344 | driver specified by This has a user-readable name in the language specified by\r | |
345 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
346 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
347 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
348 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
349 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
350 | \r | |
351 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
352 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
353 | \r | |
354 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
355 | specified by This is managing. This handle\r | |
356 | specifies the controller whose name is to be\r | |
357 | returned.\r | |
358 | \r | |
359 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
360 | the name of. This is an optional parameter that\r | |
361 | may be NULL. It will be NULL for device\r | |
362 | drivers. It will also be NULL for a bus drivers\r | |
363 | that wish to retrieve the name of the bus\r | |
364 | controller. It will not be NULL for a bus\r | |
365 | driver that wishes to retrieve the name of a\r | |
366 | child controller.\r | |
367 | \r | |
368 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
369 | array indicating the language. This is the\r | |
370 | language of the driver name that the caller is\r | |
371 | requesting, and it must match one of the\r | |
372 | languages specified in SupportedLanguages. The\r | |
373 | number of languages supported by a driver is up\r | |
374 | to the driver writer. Language is specified in\r | |
375 | RFC 4646 or ISO 639-2 language code format.\r | |
376 | \r | |
377 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
378 | This Unicode string is the name of the\r | |
379 | controller specified by ControllerHandle and\r | |
380 | ChildHandle in the language specified by\r | |
381 | Language from the point of view of the driver\r | |
382 | specified by This.\r | |
383 | \r | |
384 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
385 | the language specified by Language for the\r | |
386 | driver specified by This was returned in\r | |
387 | DriverName.\r | |
388 | \r | |
15ee13fc | 389 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
390 | \r |
391 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
392 | EFI_HANDLE.\r | |
393 | \r | |
394 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
395 | \r | |
396 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
397 | \r | |
398 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
399 | managing the controller specified by\r | |
400 | ControllerHandle and ChildHandle.\r | |
401 | \r | |
402 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
403 | the language specified by Language.\r | |
404 | \r | |
405 | **/\r | |
406 | EFI_STATUS\r | |
407 | EFIAPI\r | |
408 | Ip6ComponentNameGetControllerName (\r | |
409 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
410 | IN EFI_HANDLE ControllerHandle,\r | |
411 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
412 | IN CHAR8 *Language,\r | |
413 | OUT CHAR16 **ControllerName\r | |
414 | )\r | |
415 | {\r | |
216f7970 | 416 | EFI_STATUS Status;\r |
417 | EFI_IP6_PROTOCOL *Ip6;\r | |
f75a7f56 | 418 | \r |
216f7970 | 419 | //\r |
420 | // Only provide names for child handles.\r | |
421 | //\r | |
422 | if (ChildHandle == NULL) {\r | |
423 | return EFI_UNSUPPORTED;\r | |
424 | }\r | |
425 | \r | |
426 | //\r | |
f75a7f56 | 427 | // Make sure this driver produced ChildHandle\r |
216f7970 | 428 | //\r |
429 | Status = EfiTestChildHandle (\r | |
430 | ControllerHandle,\r | |
431 | ChildHandle,\r | |
432 | &gEfiManagedNetworkProtocolGuid\r | |
433 | );\r | |
434 | if (EFI_ERROR (Status)) {\r | |
435 | return Status;\r | |
436 | }\r | |
437 | \r | |
438 | //\r | |
439 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
440 | //\r | |
441 | Status = gBS->OpenProtocol (\r | |
442 | ChildHandle,\r | |
443 | &gEfiIp6ProtocolGuid,\r | |
444 | (VOID **)&Ip6,\r | |
445 | NULL,\r | |
446 | NULL,\r | |
447 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
448 | );\r | |
449 | if (EFI_ERROR (Status)) {\r | |
450 | return Status;\r | |
451 | }\r | |
452 | \r | |
453 | //\r | |
454 | // Update the component name for this child handle.\r | |
455 | //\r | |
456 | Status = UpdateName (Ip6);\r | |
457 | if (EFI_ERROR (Status)) {\r | |
458 | return Status;\r | |
459 | }\r | |
460 | \r | |
461 | return LookupUnicodeString2 (\r | |
462 | Language,\r | |
463 | This->SupportedLanguages,\r | |
464 | gIp6ControllerNameTable,\r | |
465 | ControllerName,\r | |
466 | (BOOLEAN)(This == &gIp6ComponentName)\r | |
467 | );\r | |
a3bcde70 | 468 | }\r |