]>
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 | |
d1050b9d MK |
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 | |
a3bcde70 HT |
140 | );\r |
141 | \r | |
142 | //\r | |
143 | // EFI Component Name Protocol.\r | |
144 | //\r | |
d1050b9d | 145 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp6ComponentName = {\r |
a3bcde70 HT |
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 | |
d1050b9d MK |
155 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Ip6ComponentNameGetDriverName,\r |
156 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Ip6ComponentNameGetControllerName,\r | |
a3bcde70 HT |
157 | "en"\r |
158 | };\r | |
159 | \r | |
d1050b9d | 160 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp6DriverNameTable[] = {\r |
a3bcde70 HT |
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 | |
d1050b9d | 171 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp6ControllerNameTable = NULL;\r |
216f7970 | 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 | |
d1050b9d MK |
221 | Language,\r |
222 | This->SupportedLanguages,\r | |
223 | mIp6DriverNameTable,\r | |
224 | DriverName,\r | |
225 | (BOOLEAN)(This == &gIp6ComponentName)\r | |
226 | );\r | |
a3bcde70 HT |
227 | }\r |
228 | \r | |
216f7970 | 229 | /**\r |
230 | Update the component name for the IP6 child handle.\r | |
231 | \r | |
232 | @param Ip6[in] A pointer to the EFI_IP6_PROTOCOL.\r | |
233 | \r | |
f75a7f56 | 234 | \r |
216f7970 | 235 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r |
236 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
f75a7f56 | 237 | \r |
216f7970 | 238 | **/\r |
239 | EFI_STATUS\r | |
240 | UpdateName (\r | |
d1050b9d | 241 | IN EFI_IP6_PROTOCOL *Ip6\r |
216f7970 | 242 | )\r |
243 | {\r | |
d1050b9d MK |
244 | EFI_STATUS Status;\r |
245 | CHAR16 HandleName[128];\r | |
246 | EFI_IP6_MODE_DATA Ip6ModeData;\r | |
247 | UINTN Offset;\r | |
248 | CHAR16 Address[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];\r | |
216f7970 | 249 | \r |
250 | if (Ip6 == NULL) {\r | |
251 | return EFI_INVALID_PARAMETER;\r | |
252 | }\r | |
253 | \r | |
254 | //\r | |
255 | // Format the child name into the string buffer.\r | |
256 | //\r | |
257 | Offset = 0;\r | |
258 | Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL);\r | |
ce22514e ZL |
259 | if (!EFI_ERROR (Status)) {\r |
260 | if (Ip6ModeData.AddressList != NULL) {\r | |
261 | FreePool (Ip6ModeData.AddressList);\r | |
262 | }\r | |
263 | \r | |
264 | if (Ip6ModeData.GroupTable != NULL) {\r | |
265 | FreePool (Ip6ModeData.GroupTable);\r | |
266 | }\r | |
267 | \r | |
268 | if (Ip6ModeData.RouteTable != NULL) {\r | |
269 | FreePool (Ip6ModeData.RouteTable);\r | |
270 | }\r | |
271 | \r | |
272 | if (Ip6ModeData.NeighborCache != NULL) {\r | |
273 | FreePool (Ip6ModeData.NeighborCache);\r | |
274 | }\r | |
275 | \r | |
276 | if (Ip6ModeData.PrefixTable != NULL) {\r | |
277 | FreePool (Ip6ModeData.PrefixTable);\r | |
278 | }\r | |
279 | \r | |
280 | if (Ip6ModeData.IcmpTypeList != NULL) {\r | |
281 | FreePool (Ip6ModeData.IcmpTypeList);\r | |
282 | }\r | |
283 | }\r | |
284 | \r | |
216f7970 | 285 | if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) {\r |
d1050b9d | 286 | Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof (Address));\r |
216f7970 | 287 | if (EFI_ERROR (Status)) {\r |
288 | return Status;\r | |
289 | }\r | |
d1050b9d | 290 | \r |
216f7970 | 291 | Offset += UnicodeSPrint (\r |
292 | HandleName,\r | |
d1050b9d | 293 | sizeof (HandleName),\r |
216f7970 | 294 | L"IPv6(StationAddress=%s, ",\r |
295 | Address\r | |
296 | );\r | |
d1050b9d | 297 | Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.DestinationAddress, Address, sizeof (Address));\r |
216f7970 | 298 | if (EFI_ERROR (Status)) {\r |
299 | return Status;\r | |
300 | }\r | |
d1050b9d | 301 | \r |
216f7970 | 302 | UnicodeSPrint (\r |
303 | HandleName + Offset,\r | |
d1050b9d | 304 | sizeof (HandleName) - Offset * sizeof (CHAR16),\r |
216f7970 | 305 | L"DestinationAddress=%s)",\r |
306 | Address\r | |
307 | );\r | |
308 | } else if (!Ip6ModeData.IsStarted) {\r | |
d1050b9d | 309 | UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv6(Not started)");\r |
216f7970 | 310 | } else {\r |
d1050b9d | 311 | UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv6(%r)", Status);\r |
216f7970 | 312 | }\r |
313 | \r | |
314 | if (gIp6ControllerNameTable != NULL) {\r | |
d1050b9d MK |
315 | FreeUnicodeStringTable (gIp6ControllerNameTable);\r |
316 | gIp6ControllerNameTable = NULL;\r | |
216f7970 | 317 | }\r |
f75a7f56 | 318 | \r |
216f7970 | 319 | Status = AddUnicodeString2 (\r |
320 | "eng",\r | |
321 | gIp6ComponentName.SupportedLanguages,\r | |
322 | &gIp6ControllerNameTable,\r | |
323 | HandleName,\r | |
324 | TRUE\r | |
325 | );\r | |
326 | if (EFI_ERROR (Status)) {\r | |
327 | return Status;\r | |
328 | }\r | |
f75a7f56 | 329 | \r |
216f7970 | 330 | return AddUnicodeString2 (\r |
331 | "en",\r | |
332 | gIp6ComponentName2.SupportedLanguages,\r | |
333 | &gIp6ControllerNameTable,\r | |
334 | HandleName,\r | |
335 | FALSE\r | |
336 | );\r | |
337 | }\r | |
338 | \r | |
a3bcde70 HT |
339 | /**\r |
340 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
341 | that is being managed by a driver.\r | |
342 | \r | |
343 | This function retrieves the user-readable name of the controller specified by\r | |
344 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
345 | driver specified by This has a user-readable name in the language specified by\r | |
346 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
347 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
348 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
349 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
350 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
351 | \r | |
352 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
353 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
354 | \r | |
355 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
356 | specified by This is managing. This handle\r | |
357 | specifies the controller whose name is to be\r | |
358 | returned.\r | |
359 | \r | |
360 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
361 | the name of. This is an optional parameter that\r | |
362 | may be NULL. It will be NULL for device\r | |
363 | drivers. It will also be NULL for a bus drivers\r | |
364 | that wish to retrieve the name of the bus\r | |
365 | controller. It will not be NULL for a bus\r | |
366 | driver that wishes to retrieve the name of a\r | |
367 | child controller.\r | |
368 | \r | |
369 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
370 | array indicating the language. This is the\r | |
371 | language of the driver name that the caller is\r | |
372 | requesting, and it must match one of the\r | |
373 | languages specified in SupportedLanguages. The\r | |
374 | number of languages supported by a driver is up\r | |
375 | to the driver writer. Language is specified in\r | |
376 | RFC 4646 or ISO 639-2 language code format.\r | |
377 | \r | |
378 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
379 | This Unicode string is the name of the\r | |
380 | controller specified by ControllerHandle and\r | |
381 | ChildHandle in the language specified by\r | |
382 | Language from the point of view of the driver\r | |
383 | specified by This.\r | |
384 | \r | |
385 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
386 | the language specified by Language for the\r | |
387 | driver specified by This was returned in\r | |
388 | DriverName.\r | |
389 | \r | |
15ee13fc | 390 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
391 | \r |
392 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
393 | EFI_HANDLE.\r | |
394 | \r | |
395 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
396 | \r | |
397 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
398 | \r | |
399 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
400 | managing the controller specified by\r | |
401 | ControllerHandle and ChildHandle.\r | |
402 | \r | |
403 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
404 | the language specified by Language.\r | |
405 | \r | |
406 | **/\r | |
407 | EFI_STATUS\r | |
408 | EFIAPI\r | |
409 | Ip6ComponentNameGetControllerName (\r | |
d1050b9d MK |
410 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
411 | IN EFI_HANDLE ControllerHandle,\r | |
412 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
413 | IN CHAR8 *Language,\r | |
414 | OUT CHAR16 **ControllerName\r | |
a3bcde70 HT |
415 | )\r |
416 | {\r | |
d1050b9d MK |
417 | EFI_STATUS Status;\r |
418 | EFI_IP6_PROTOCOL *Ip6;\r | |
f75a7f56 | 419 | \r |
216f7970 | 420 | //\r |
421 | // Only provide names for child handles.\r | |
422 | //\r | |
423 | if (ChildHandle == NULL) {\r | |
424 | return EFI_UNSUPPORTED;\r | |
425 | }\r | |
426 | \r | |
427 | //\r | |
f75a7f56 | 428 | // Make sure this driver produced ChildHandle\r |
216f7970 | 429 | //\r |
430 | Status = EfiTestChildHandle (\r | |
431 | ControllerHandle,\r | |
432 | ChildHandle,\r | |
433 | &gEfiManagedNetworkProtocolGuid\r | |
434 | );\r | |
435 | if (EFI_ERROR (Status)) {\r | |
436 | return Status;\r | |
437 | }\r | |
438 | \r | |
439 | //\r | |
440 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
441 | //\r | |
442 | Status = gBS->OpenProtocol (\r | |
443 | ChildHandle,\r | |
444 | &gEfiIp6ProtocolGuid,\r | |
445 | (VOID **)&Ip6,\r | |
446 | NULL,\r | |
447 | NULL,\r | |
448 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
449 | );\r | |
450 | if (EFI_ERROR (Status)) {\r | |
451 | return Status;\r | |
452 | }\r | |
453 | \r | |
454 | //\r | |
455 | // Update the component name for this child handle.\r | |
456 | //\r | |
457 | Status = UpdateName (Ip6);\r | |
458 | if (EFI_ERROR (Status)) {\r | |
459 | return Status;\r | |
460 | }\r | |
461 | \r | |
462 | return LookupUnicodeString2 (\r | |
463 | Language,\r | |
464 | This->SupportedLanguages,\r | |
465 | gIp6ControllerNameTable,\r | |
466 | ControllerName,\r | |
467 | (BOOLEAN)(This == &gIp6ComponentName)\r | |
468 | );\r | |
a3bcde70 | 469 | }\r |