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 | |
d1050b9d | 15 | \r |
a3bcde70 HT |
16 | /**\r |
17 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
18 | \r | |
19 | This function retrieves the user-readable name of a driver in the form of a\r | |
20 | Unicode string. If the driver specified by This has a user-readable name in\r | |
21 | the language specified by Language, then a pointer to the driver name is\r | |
22 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
23 | by This does not support the language specified by Language,\r | |
24 | then EFI_UNSUPPORTED is returned.\r | |
25 | \r | |
26 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
27 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
28 | \r | |
29 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
30 | array indicating the language. This is the\r | |
31 | language of the driver name that the caller is\r | |
32 | requesting, and it must match one of the\r | |
33 | languages specified in SupportedLanguages. The\r | |
34 | number of languages supported by a driver is up\r | |
35 | to the driver writer. Language is specified\r | |
36 | in RFC 4646 or ISO 639-2 language code format.\r | |
37 | \r | |
38 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
39 | This Unicode string is the name of the\r | |
40 | driver specified by This in the language\r | |
41 | specified by Language.\r | |
42 | \r | |
43 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
44 | This and the language specified by Language was\r | |
45 | returned in DriverName.\r | |
46 | \r | |
47 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
48 | \r | |
49 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
50 | \r | |
51 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
52 | the language specified by Language.\r | |
53 | \r | |
54 | **/\r | |
55 | EFI_STATUS\r | |
56 | EFIAPI\r | |
57 | Udp6ComponentNameGetDriverName (\r | |
58 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
59 | IN CHAR8 *Language,\r | |
60 | OUT CHAR16 **DriverName\r | |
61 | );\r | |
62 | \r | |
a3bcde70 HT |
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 | |
d1050b9d MK |
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 | |
a3bcde70 HT |
156 | "en"\r |
157 | };\r | |
158 | \r | |
d1050b9d | 159 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUdp6DriverNameTable[] = {\r |
a3bcde70 HT |
160 | {\r |
161 | "eng;en",\r | |
162 | L"UDP6 Network Service Driver"\r | |
163 | },\r | |
164 | {\r | |
165 | NULL,\r | |
166 | NULL\r | |
167 | }\r | |
168 | };\r | |
169 | \r | |
216f7970 | 170 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gUdp6ControllerNameTable = NULL;\r |
171 | \r | |
a3bcde70 HT |
172 | /**\r |
173 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
174 | \r | |
175 | This function retrieves the user-readable name of a driver in the form of a\r | |
176 | Unicode string. If the driver specified by This has a user-readable name in\r | |
177 | the language specified by Language, then a pointer to the driver name is\r | |
178 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
179 | by This does not support the language specified by Language,\r | |
180 | then EFI_UNSUPPORTED is returned.\r | |
181 | \r | |
182 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
183 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
184 | \r | |
185 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
186 | array indicating the language. This is the\r | |
187 | language of the driver name that the caller is\r | |
188 | requesting, and it must match one of the\r | |
189 | languages specified in SupportedLanguages. The\r | |
190 | number of languages supported by a driver is up\r | |
191 | to the driver writer. Language is specified\r | |
192 | in RFC 4646 or ISO 639-2 language code format.\r | |
193 | \r | |
194 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
195 | This Unicode string is the name of the\r | |
196 | driver specified by This in the language\r | |
197 | specified by Language.\r | |
198 | \r | |
199 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
200 | This and the language specified by Language was\r | |
201 | returned in DriverName.\r | |
202 | \r | |
203 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
204 | \r | |
205 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
206 | \r | |
207 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
208 | the language specified by Language.\r | |
209 | \r | |
210 | **/\r | |
211 | EFI_STATUS\r | |
212 | EFIAPI\r | |
213 | Udp6ComponentNameGetDriverName (\r | |
214 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
215 | IN CHAR8 *Language,\r | |
216 | OUT CHAR16 **DriverName\r | |
217 | )\r | |
218 | {\r | |
219 | return LookupUnicodeString2 (\r | |
220 | Language,\r | |
221 | This->SupportedLanguages,\r | |
222 | mUdp6DriverNameTable,\r | |
223 | DriverName,\r | |
d1050b9d | 224 | (BOOLEAN)(This == &gUdp6ComponentName)\r |
a3bcde70 HT |
225 | );\r |
226 | }\r | |
227 | \r | |
216f7970 | 228 | /**\r |
229 | Update the component name for the Udp6 child handle.\r | |
230 | \r | |
231 | @param Udp6[in] A pointer to the EFI_UDP6_PROTOCOL.\r | |
232 | \r | |
f75a7f56 | 233 | \r |
216f7970 | 234 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r |
235 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
f75a7f56 | 236 | \r |
216f7970 | 237 | **/\r |
238 | EFI_STATUS\r | |
239 | UpdateName (\r | |
d1050b9d | 240 | IN EFI_UDP6_PROTOCOL *Udp6\r |
216f7970 | 241 | )\r |
242 | {\r | |
d1050b9d MK |
243 | EFI_STATUS Status;\r |
244 | CHAR16 HandleName[64];\r | |
245 | EFI_UDP6_CONFIG_DATA Udp6ConfigData;\r | |
216f7970 | 246 | \r |
247 | if (Udp6 == NULL) {\r | |
248 | return EFI_INVALID_PARAMETER;\r | |
249 | }\r | |
250 | \r | |
251 | //\r | |
252 | // Format the child name into the string buffer.\r | |
253 | //\r | |
254 | Status = Udp6->GetModeData (Udp6, &Udp6ConfigData, NULL, NULL, NULL);\r | |
255 | if (!EFI_ERROR (Status)) {\r | |
d1050b9d MK |
256 | UnicodeSPrint (\r |
257 | HandleName,\r | |
258 | sizeof (HandleName),\r | |
216f7970 | 259 | L"UDPv6 (SrcPort=%d, DestPort=%d)",\r |
260 | Udp6ConfigData.StationPort,\r | |
261 | Udp6ConfigData.RemotePort\r | |
262 | );\r | |
263 | } else if (Status == EFI_NOT_STARTED) {\r | |
264 | UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (Not started)");\r | |
265 | } else {\r | |
266 | UnicodeSPrint (HandleName, sizeof (HandleName), L"UDPv6 (%r)", Status);\r | |
267 | }\r | |
268 | \r | |
269 | if (gUdp6ControllerNameTable != NULL) {\r | |
270 | FreeUnicodeStringTable (gUdp6ControllerNameTable);\r | |
271 | gUdp6ControllerNameTable = NULL;\r | |
272 | }\r | |
273 | \r | |
274 | Status = AddUnicodeString2 (\r | |
275 | "eng",\r | |
276 | gUdp6ComponentName.SupportedLanguages,\r | |
277 | &gUdp6ControllerNameTable,\r | |
278 | HandleName,\r | |
279 | TRUE\r | |
280 | );\r | |
281 | if (EFI_ERROR (Status)) {\r | |
282 | return Status;\r | |
283 | }\r | |
284 | \r | |
285 | return AddUnicodeString2 (\r | |
286 | "en",\r | |
287 | gUdp6ComponentName2.SupportedLanguages,\r | |
288 | &gUdp6ControllerNameTable,\r | |
289 | HandleName,\r | |
290 | FALSE\r | |
291 | );\r | |
292 | }\r | |
293 | \r | |
a3bcde70 HT |
294 | /**\r |
295 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
296 | that is being managed by a driver.\r | |
297 | \r | |
298 | This function retrieves the user-readable name of the controller specified by\r | |
299 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
300 | driver specified by This has a user-readable name in the language specified by\r | |
301 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
302 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
303 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
304 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
305 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
306 | \r | |
307 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
308 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
309 | \r | |
310 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
311 | specified by This is managing. This handle\r | |
312 | specifies the controller whose name is to be\r | |
313 | returned.\r | |
314 | \r | |
315 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
316 | the name of. This is an optional parameter that\r | |
317 | may be NULL. It will be NULL for device\r | |
318 | drivers. It will also be NULL for a bus drivers\r | |
319 | that wish to retrieve the name of the bus\r | |
320 | controller. It will not be NULL for a bus\r | |
321 | driver that wishes to retrieve the name of a\r | |
322 | child controller.\r | |
323 | \r | |
324 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
325 | array indicating the language. This is the\r | |
326 | language of the driver name that the caller is\r | |
327 | requesting, and it must match one of the\r | |
328 | languages specified in SupportedLanguages. The\r | |
329 | number of languages supported by a driver is up\r | |
330 | to the driver writer. Language is specified in\r | |
331 | RFC 4646 or ISO 639-2 language code format.\r | |
332 | \r | |
333 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
334 | This Unicode string is the name of the\r | |
335 | controller specified by ControllerHandle and\r | |
336 | ChildHandle in the language specified by\r | |
337 | Language from the point of view of the driver\r | |
338 | specified by This.\r | |
339 | \r | |
340 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
341 | the language specified by Language for the\r | |
342 | driver specified by This was returned in\r | |
343 | DriverName.\r | |
344 | \r | |
15ee13fc | 345 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
346 | \r |
347 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
348 | EFI_HANDLE.\r | |
349 | \r | |
350 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
351 | \r | |
352 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
353 | \r | |
354 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
355 | managing the controller specified by\r | |
356 | ControllerHandle and ChildHandle.\r | |
357 | \r | |
358 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
359 | the language specified by Language.\r | |
360 | \r | |
361 | **/\r | |
362 | EFI_STATUS\r | |
363 | EFIAPI\r | |
364 | Udp6ComponentNameGetControllerName (\r | |
365 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
366 | IN EFI_HANDLE ControllerHandle,\r | |
367 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
368 | IN CHAR8 *Language,\r | |
369 | OUT CHAR16 **ControllerName\r | |
370 | )\r | |
371 | {\r | |
d1050b9d MK |
372 | EFI_STATUS Status;\r |
373 | EFI_UDP6_PROTOCOL *Udp6;\r | |
216f7970 | 374 | \r |
375 | //\r | |
376 | // Only provide names for child handles.\r | |
377 | //\r | |
378 | if (ChildHandle == NULL) {\r | |
379 | return EFI_UNSUPPORTED;\r | |
380 | }\r | |
381 | \r | |
382 | //\r | |
383 | // Make sure this driver produced ChildHandle\r | |
384 | //\r | |
385 | Status = EfiTestChildHandle (\r | |
386 | ControllerHandle,\r | |
387 | ChildHandle,\r | |
388 | &gEfiIp6ProtocolGuid\r | |
389 | );\r | |
390 | if (EFI_ERROR (Status)) {\r | |
391 | return Status;\r | |
392 | }\r | |
393 | \r | |
394 | //\r | |
395 | // Retrieve an instance of a produced protocol from ChildHandle\r | |
396 | //\r | |
397 | Status = gBS->OpenProtocol (\r | |
398 | ChildHandle,\r | |
399 | &gEfiUdp6ProtocolGuid,\r | |
400 | (VOID **)&Udp6,\r | |
401 | NULL,\r | |
402 | NULL,\r | |
403 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
404 | );\r | |
405 | if (EFI_ERROR (Status)) {\r | |
406 | return Status;\r | |
407 | }\r | |
408 | \r | |
409 | //\r | |
410 | // Update the component name for this child handle.\r | |
411 | //\r | |
412 | Status = UpdateName (Udp6);\r | |
413 | if (EFI_ERROR (Status)) {\r | |
414 | return Status;\r | |
415 | }\r | |
a3bcde70 | 416 | \r |
216f7970 | 417 | return LookupUnicodeString2 (\r |
418 | Language,\r | |
419 | This->SupportedLanguages,\r | |
420 | gUdp6ControllerNameTable,\r | |
421 | ControllerName,\r | |
422 | (BOOLEAN)(This == &gUdp6ComponentName)\r | |
423 | );\r | |
424 | }\r |