Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | UEFI Component Name(2) protocol implementation for UDP6 driver.\r | |
3 | \r | |
f75a7f56 | 4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
a3bcde70 | 5 | \r |
ecf98fbc | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a3bcde70 HT |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include "Udp6Impl.h"\r | |
11 | \r | |
12 | //\r | |
13 | // EFI Component Name Functions\r | |
14 | //\r | |
15 | /**\r | |
16 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
17 | \r | |
18 | This function retrieves the user-readable name of a driver in the form of a\r | |
19 | Unicode string. If the driver specified by This has a user-readable name in\r | |
20 | the language specified by Language, then a pointer to the driver name is\r | |
21 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
22 | by This does not support the language specified by Language,\r | |
23 | then EFI_UNSUPPORTED is returned.\r | |
24 | \r | |
25 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
26 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
27 | \r | |
28 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
29 | array indicating the language. This is the\r | |
30 | language of the driver name that the caller is\r | |
31 | requesting, and it must match one of the\r | |
32 | languages specified in SupportedLanguages. The\r | |
33 | number of languages supported by a driver is up\r | |
34 | to the driver writer. Language is specified\r | |
35 | in RFC 4646 or ISO 639-2 language code format.\r | |
36 | \r | |
37 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
38 | This Unicode string is the name of the\r | |
39 | driver specified by This in the language\r | |
40 | specified by Language.\r | |
41 | \r | |
42 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
43 | This and the language specified by Language was\r | |
44 | returned in DriverName.\r | |
45 | \r | |
46 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
47 | \r | |
48 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
49 | \r | |
50 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
51 | the language specified by Language.\r | |
52 | \r | |
53 | **/\r | |
54 | EFI_STATUS\r | |
55 | EFIAPI\r | |
56 | Udp6ComponentNameGetDriverName (\r | |
57 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
58 | IN CHAR8 *Language,\r | |
59 | OUT CHAR16 **DriverName\r | |
60 | );\r | |
61 | \r | |
62 | \r | |
63 | /**\r | |
64 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
65 | that is being managed by a driver.\r | |
66 | \r | |
67 | This function retrieves the user-readable name of the controller specified by\r | |
68 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
69 | driver specified by This has a user-readable name in the language specified by\r | |
70 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
71 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
72 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
73 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
74 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
75 | \r | |
76 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
77 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
78 | \r | |
79 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
80 | specified by This is managing. This handle\r | |
81 | specifies the controller whose name is to be\r | |
82 | returned.\r | |
83 | \r | |
84 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
85 | the name of. This is an optional parameter that\r | |
86 | may be NULL. It will be NULL for device\r | |
87 | drivers. It will also be NULL for a bus drivers\r | |
88 | that wish to retrieve the name of the bus\r | |
89 | controller. It will not be NULL for a bus\r | |
90 | driver that wishes to retrieve the name of a\r | |
91 | child controller.\r | |
92 | \r | |
93 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
94 | array indicating the language. This is the\r | |
95 | language of the driver name that the caller is\r | |
96 | requesting, and it must match one of the\r | |
97 | languages specified in SupportedLanguages. The\r | |
98 | number of languages supported by a driver is up\r | |
99 | to the driver writer. Language is specified in\r | |
100 | RFC 4646 or ISO 639-2 language code format.\r | |
101 | \r | |
102 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
103 | This Unicode string is the name of the\r | |
104 | controller specified by ControllerHandle and\r | |
105 | ChildHandle in the language specified by\r | |
106 | Language from the point of view of the driver\r | |
107 | specified by This.\r | |
108 | \r | |
109 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
110 | the language specified by Language for the\r | |
111 | driver specified by This was returned in\r | |
112 | DriverName.\r | |
113 | \r | |
15ee13fc | 114 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
115 | \r |
116 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
117 | EFI_HANDLE.\r | |
118 | \r | |
119 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
120 | \r | |
121 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
122 | \r | |
123 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
124 | managing the controller specified by\r | |
125 | ControllerHandle and ChildHandle.\r | |
126 | \r | |
127 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
128 | the language specified by Language.\r | |
129 | \r | |
130 | **/\r | |
131 | EFI_STATUS\r | |
132 | EFIAPI\r | |
133 | Udp6ComponentNameGetControllerName (\r | |
134 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
135 | IN EFI_HANDLE ControllerHandle,\r | |
136 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
137 | IN CHAR8 *Language,\r | |
138 | OUT CHAR16 **ControllerName\r | |
139 | );\r | |
140 | \r | |
141 | //\r | |
142 | // EFI Component Name Protocol\r | |
143 | //\r | |
144 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUdp6ComponentName = {\r | |
145 | Udp6ComponentNameGetDriverName,\r | |
146 | Udp6ComponentNameGetControllerName,\r | |
147 | "eng"\r | |
148 | };\r | |
149 | \r | |
150 | //\r | |
151 | // EFI Component Name 2 Protocol\r | |
152 | //\r | |
153 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUdp6ComponentName2 = {\r | |
154 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Udp6ComponentNameGetDriverName,\r | |
155 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Udp6ComponentNameGetControllerName,\r | |
156 | "en"\r | |
157 | };\r | |
158 | \r | |
159 | \r | |
160 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUdp6DriverNameTable[] = {\r | |
161 | {\r | |
162 | "eng;en",\r | |
163 | L"UDP6 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 *gUdp6ControllerNameTable = 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 | Udp6ComponentNameGetDriverName (\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 | mUdp6DriverNameTable,\r | |
224 | DriverName,\r | |
225 | (BOOLEAN) (This == &gUdp6ComponentName)\r | |
226 | );\r | |
227 | }\r | |
228 | \r | |
216f7970 | 229 | /**\r |
230 | Update the component name for the Udp6 child handle.\r | |
231 | \r | |
232 | @param Udp6[in] A pointer to the EFI_UDP6_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 | |
241 | IN EFI_UDP6_PROTOCOL *Udp6\r | |
242 | )\r | |
243 | {\r | |
244 | EFI_STATUS Status;\r | |
245 | CHAR16 HandleName[64];\r | |
246 | EFI_UDP6_CONFIG_DATA Udp6ConfigData;\r | |
247 | \r | |
248 | if (Udp6 == NULL) {\r | |
249 | return EFI_INVALID_PARAMETER;\r | |
250 | }\r | |
251 | \r | |
252 | //\r | |
253 | // Format the child name into the string buffer.\r | |
254 | //\r | |
255 | Status = Udp6->GetModeData (Udp6, &Udp6ConfigData, NULL, NULL, NULL);\r | |
256 | if (!EFI_ERROR (Status)) {\r | |
257 | UnicodeSPrint (HandleName, sizeof (HandleName),\r | |
258 | L"UDPv6 (SrcPort=%d, DestPort=%d)",\r | |
259 | Udp6ConfigData.StationPort,\r | |
260 | Udp6ConfigData.RemotePort\r | |
261 | );\r | |
262 | } else if (Status == EFI_NOT_STARTED) {\r | |
263 | UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (Not started)");\r | |
264 | } else {\r | |
265 | UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (%r)", Status);\r | |
266 | }\r | |
267 | \r | |
268 | if (gUdp6ControllerNameTable != NULL) {\r | |
269 | FreeUnicodeStringTable (gUdp6ControllerNameTable);\r | |
270 | gUdp6ControllerNameTable = NULL;\r | |
271 | }\r | |
272 | \r | |
273 | Status = AddUnicodeString2 (\r | |
274 | "eng",\r | |
275 | gUdp6ComponentName.SupportedLanguages,\r | |
276 | &gUdp6ControllerNameTable,\r | |
277 | HandleName,\r | |
278 | TRUE\r | |
279 | );\r | |
280 | if (EFI_ERROR (Status)) {\r | |
281 | return Status;\r | |
282 | }\r | |
283 | \r | |
284 | return AddUnicodeString2 (\r | |
285 | "en",\r | |
286 | gUdp6ComponentName2.SupportedLanguages,\r | |
287 | &gUdp6ControllerNameTable,\r | |
288 | HandleName,\r | |
289 | FALSE\r | |
290 | );\r | |
291 | }\r | |
292 | \r | |
a3bcde70 HT |
293 | /**\r |
294 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
295 | that is being managed by a driver.\r | |
296 | \r | |
297 | This function retrieves the user-readable name of the controller specified by\r | |
298 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
299 | driver specified by This has a user-readable name in the language specified by\r | |
300 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
301 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
302 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
303 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
304 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
305 | \r | |
306 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
307 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
308 | \r | |
309 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
310 | specified by This is managing. This handle\r | |
311 | specifies the controller whose name is to be\r | |
312 | returned.\r | |
313 | \r | |
314 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
315 | the name of. This is an optional parameter that\r | |
316 | may be NULL. It will be NULL for device\r | |
317 | drivers. It will also be NULL for a bus drivers\r | |
318 | that wish to retrieve the name of the bus\r | |
319 | controller. It will not be NULL for a bus\r | |
320 | driver that wishes to retrieve the name of a\r | |
321 | child controller.\r | |
322 | \r | |
323 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
324 | array indicating the language. This is the\r | |
325 | language of the driver name that the caller is\r | |
326 | requesting, and it must match one of the\r | |
327 | languages specified in SupportedLanguages. The\r | |
328 | number of languages supported by a driver is up\r | |
329 | to the driver writer. Language is specified in\r | |
330 | RFC 4646 or ISO 639-2 language code format.\r | |
331 | \r | |
332 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
333 | This Unicode string is the name of the\r | |
334 | controller specified by ControllerHandle and\r | |
335 | ChildHandle in the language specified by\r | |
336 | Language from the point of view of the driver\r | |
337 | specified by This.\r | |
338 | \r | |
339 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
340 | the language specified by Language for the\r | |
341 | driver specified by This was returned in\r | |
342 | DriverName.\r | |
343 | \r | |
15ee13fc | 344 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
345 | \r |
346 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
347 | EFI_HANDLE.\r | |
348 | \r | |
349 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
350 | \r | |
351 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
352 | \r | |
353 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
354 | managing the controller specified by\r | |
355 | ControllerHandle and ChildHandle.\r | |
356 | \r | |
357 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
358 | the language specified by Language.\r | |
359 | \r | |
360 | **/\r | |
361 | EFI_STATUS\r | |
362 | EFIAPI\r | |
363 | Udp6ComponentNameGetControllerName (\r | |
364 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
365 | IN EFI_HANDLE ControllerHandle,\r | |
366 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
367 | IN CHAR8 *Language,\r | |
368 | OUT CHAR16 **ControllerName\r | |
369 | )\r | |
370 | {\r | |
216f7970 | 371 | EFI_STATUS Status;\r |
372 | EFI_UDP6_PROTOCOL *Udp6;\r | |
373 | \r | |
374 | //\r | |
375 | // Only provide names for child handles.\r | |
376 | //\r | |
377 | if (ChildHandle == NULL) {\r | |
378 | return EFI_UNSUPPORTED;\r | |
379 | }\r | |
380 | \r | |
381 | //\r | |
382 | // Make sure this driver produced ChildHandle\r | |
383 | //\r | |
384 | Status = EfiTestChildHandle (\r | |
385 | ControllerHandle,\r | |
386 | ChildHandle,\r | |
387 | &gEfiIp6ProtocolGuid\r | |
388 | );\r | |
389 | if (EFI_ERROR (Status)) {\r | |
390 | return Status;\r | |
391 | }\r | |
392 | \r | |
393 | //\r | |
394 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
395 | //\r | |
396 | Status = gBS->OpenProtocol (\r | |
397 | ChildHandle,\r | |
398 | &gEfiUdp6ProtocolGuid,\r | |
399 | (VOID **)&Udp6,\r | |
400 | NULL,\r | |
401 | NULL,\r | |
402 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
403 | );\r | |
404 | if (EFI_ERROR (Status)) {\r | |
405 | return Status;\r | |
406 | }\r | |
407 | \r | |
408 | //\r | |
409 | // Update the component name for this child handle.\r | |
410 | //\r | |
411 | Status = UpdateName (Udp6);\r | |
412 | if (EFI_ERROR (Status)) {\r | |
413 | return Status;\r | |
414 | }\r | |
a3bcde70 | 415 | \r |
216f7970 | 416 | return LookupUnicodeString2 (\r |
417 | Language,\r | |
418 | This->SupportedLanguages,\r | |
419 | gUdp6ControllerNameTable,\r | |
420 | ControllerName,\r | |
421 | (BOOLEAN)(This == &gUdp6ComponentName)\r | |
422 | );\r | |
423 | }\r |