]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | UEFI Component Name(2) protocol implementation for Mtftp6 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 "Mtftp6Impl.h"\r | |
11 | \r | |
a3bcde70 HT |
12 | /**\r |
13 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
14 | \r | |
15 | This function retrieves the user-readable name of a driver in the form of a\r | |
16 | Unicode string. If the driver specified by This has a user-readable name in\r | |
17 | the language specified by Language, then a pointer to the driver name is\r | |
18 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
19 | by This does not support the language specified by Language,\r | |
20 | then EFI_UNSUPPORTED is returned.\r | |
21 | \r | |
22 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
23 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
24 | \r | |
25 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
26 | array indicating the language. This is the\r | |
27 | language of the driver name that the caller is\r | |
28 | requesting, and it must match one of the\r | |
29 | languages specified in SupportedLanguages. The\r | |
30 | number of languages supported by a driver is up\r | |
31 | to the driver writer. Language is specified\r | |
32 | in RFC 4646 or ISO 639-2 language code format.\r | |
33 | \r | |
34 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
35 | This Unicode string is the name of the\r | |
36 | driver specified by This in the language\r | |
37 | specified by Language.\r | |
38 | \r | |
39 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
40 | This and the language specified by Language was\r | |
41 | returned in DriverName.\r | |
42 | \r | |
43 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
44 | \r | |
45 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
46 | \r | |
47 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
48 | the language specified by Language.\r | |
49 | \r | |
50 | **/\r | |
51 | EFI_STATUS\r | |
52 | EFIAPI\r | |
53 | Mtftp6ComponentNameGetDriverName (\r | |
54 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
55 | IN CHAR8 *Language,\r | |
56 | OUT CHAR16 **DriverName\r | |
57 | );\r | |
58 | \r | |
59 | /**\r | |
60 | Retrieves a Unicode string that is the user-readable name of the controller\r | |
61 | that is being managed by a driver.\r | |
62 | \r | |
63 | This function retrieves the user-readable name of the controller specified by\r | |
64 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
65 | driver specified by This has a user-readable name in the language specified by\r | |
66 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
67 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
68 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
69 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
70 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
71 | \r | |
72 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
73 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
74 | \r | |
75 | @param[in] ControllerHandle The handle of a controller that the driver\r | |
76 | specified by This is managing. This handle\r | |
77 | specifies the controller whose name is to be\r | |
78 | returned.\r | |
79 | \r | |
80 | @param[in] ChildHandle The handle of the child controller to retrieve\r | |
81 | the name of. This is an optional parameter that\r | |
82 | may be NULL. It will be NULL for device\r | |
83 | drivers. It will also be NULL for bus drivers\r | |
84 | attempting to retrieve the name of the bus\r | |
85 | controller. It will not be NULL for a bus\r | |
86 | driver that attempts to retrieve the name of a\r | |
87 | child controller.\r | |
88 | \r | |
89 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
90 | array indicating the language. This is the\r | |
91 | language of the driver name that the caller is\r | |
92 | requesting, and it must match one of the\r | |
93 | languages specified in SupportedLanguages. The\r | |
94 | number of languages supported by a driver is up\r | |
95 | to the driver writer. Language is specified in\r | |
96 | RFC 4646 or ISO 639-2 language code format.\r | |
97 | \r | |
98 | @param[out] ControllerName A pointer to the Unicode string to return.\r | |
99 | This Unicode string is the name of the\r | |
100 | controller specified by ControllerHandle and\r | |
101 | ChildHandle in the language specified by\r | |
102 | Language from the point of view of the driver\r | |
103 | specified by This.\r | |
104 | \r | |
105 | @retval EFI_SUCCESS The Unicode string for the user-readable name in\r | |
106 | the language specified by Language for the\r | |
107 | driver specified by This was returned in\r | |
108 | DriverName.\r | |
109 | \r | |
15ee13fc | 110 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
a3bcde70 HT |
111 | \r |
112 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r | |
113 | EFI_HANDLE.\r | |
114 | \r | |
115 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
116 | \r | |
117 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
118 | \r | |
119 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
120 | managing the controller specified by\r | |
121 | ControllerHandle and ChildHandle.\r | |
122 | \r | |
123 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
124 | the language specified by Language.\r | |
125 | \r | |
126 | **/\r | |
127 | EFI_STATUS\r | |
128 | EFIAPI\r | |
129 | Mtftp6ComponentNameGetControllerName (\r | |
d1050b9d MK |
130 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
131 | IN EFI_HANDLE ControllerHandle,\r | |
132 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
133 | IN CHAR8 *Language,\r | |
134 | OUT CHAR16 **ControllerName\r | |
a3bcde70 HT |
135 | );\r |
136 | \r | |
137 | //\r | |
138 | // EFI Component Name Protocol\r | |
139 | //\r | |
d1050b9d | 140 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentName = {\r |
a3bcde70 HT |
141 | Mtftp6ComponentNameGetDriverName,\r |
142 | Mtftp6ComponentNameGetControllerName,\r | |
143 | "eng"\r | |
144 | };\r | |
145 | \r | |
146 | //\r | |
147 | // EFI Component Name 2 Protocol\r | |
148 | //\r | |
d1050b9d MK |
149 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp6ComponentName2 = {\r |
150 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)Mtftp6ComponentNameGetDriverName,\r | |
151 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)Mtftp6ComponentNameGetControllerName,\r | |
a3bcde70 HT |
152 | "en"\r |
153 | };\r | |
154 | \r | |
d1050b9d | 155 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp6DriverNameTable[] = {\r |
a3bcde70 HT |
156 | {\r |
157 | "eng;en",\r | |
158 | L"MTFTP6 Network Service Driver"\r | |
159 | },\r | |
160 | {\r | |
161 | NULL,\r | |
162 | NULL\r | |
163 | }\r | |
164 | };\r | |
165 | \r | |
d1050b9d | 166 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp6ControllerNameTable = NULL;\r |
216f7970 | 167 | \r |
a3bcde70 HT |
168 | /**\r |
169 | Retrieves a Unicode string that is the user-readable name of the driver.\r | |
170 | \r | |
171 | This function retrieves the user-readable name of a driver in the form of a\r | |
172 | Unicode string. If the driver specified by This has a user-readable name in\r | |
173 | the language specified by Language, then a pointer to the driver name is\r | |
174 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
175 | by This does not support the language specified by Language,\r | |
176 | then EFI_UNSUPPORTED is returned.\r | |
177 | \r | |
178 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
179 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
180 | \r | |
181 | @param[in] Language A pointer to a Null-terminated ASCII string\r | |
182 | array indicating the language. This is the\r | |
183 | language of the driver name that the caller is\r | |
184 | requesting, and it must match one of the\r | |
185 | languages specified in SupportedLanguages. The\r | |
186 | number of languages supported by a driver is up\r | |
187 | to the driver writer. Language is specified\r | |
188 | in RFC 4646 or ISO 639-2 language code format.\r | |
189 | \r | |
190 | @param[out] DriverName A pointer to the Unicode string to return.\r | |
191 | This Unicode string is the name of the\r | |
192 | driver specified by This in the language\r | |
193 | specified by Language.\r | |
194 | \r | |
195 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
196 | This and the language specified by Language was\r | |
197 | returned in DriverName.\r | |
198 | \r | |
199 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
200 | \r | |
201 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
202 | \r | |
203 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
204 | the language specified by Language.\r | |
205 | \r | |
206 | **/\r | |
207 | EFI_STATUS\r | |
208 | EFIAPI\r | |
209 | Mtftp6ComponentNameGetDriverName (\r | |
210 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
211 | IN CHAR8 *Language,\r | |
212 | OUT CHAR16 **DriverName\r | |
213 | )\r | |
214 | {\r | |
215 | return LookupUnicodeString2 (\r | |
d1050b9d MK |
216 | Language,\r |
217 | This->SupportedLanguages,\r | |
218 | mMtftp6DriverNameTable,\r | |
219 | DriverName,\r | |
220 | (BOOLEAN)(This == &gMtftp6ComponentName)\r | |
221 | );\r | |
a3bcde70 HT |
222 | }\r |
223 | \r | |
216f7970 | 224 | /**\r |
225 | Update the component name for the Mtftp6 child handle.\r | |
226 | \r | |
227 | @param Mtftp6[in] A pointer to the EFI_MTFTP6_PROTOCOL.\r | |
228 | \r | |
f75a7f56 | 229 | \r |
216f7970 | 230 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r |
231 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r | |
f75a7f56 | 232 | \r |
216f7970 | 233 | **/\r |
234 | EFI_STATUS\r | |
235 | UpdateName (\r | |
d1050b9d | 236 | IN EFI_MTFTP6_PROTOCOL *Mtftp6\r |
216f7970 | 237 | )\r |
238 | {\r | |
d1050b9d MK |
239 | EFI_STATUS Status;\r |
240 | CHAR16 HandleName[128];\r | |
241 | EFI_MTFTP6_MODE_DATA Mtftp6ModeData;\r | |
242 | CHAR16 Address[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];\r | |
216f7970 | 243 | \r |
244 | if (Mtftp6 == NULL) {\r | |
245 | return EFI_INVALID_PARAMETER;\r | |
246 | }\r | |
247 | \r | |
248 | //\r | |
249 | // Format the child name into the string buffer.\r | |
250 | //\r | |
251 | Status = Mtftp6->GetModeData (Mtftp6, &Mtftp6ModeData);\r | |
252 | if (!EFI_ERROR (Status)) {\r | |
d1050b9d | 253 | Status = NetLibIp6ToStr (&Mtftp6ModeData.ConfigData.ServerIp, Address, sizeof (Address));\r |
216f7970 | 254 | if (EFI_ERROR (Status)) {\r |
255 | return Status;\r | |
256 | }\r | |
d1050b9d MK |
257 | \r |
258 | UnicodeSPrint (\r | |
259 | HandleName,\r | |
260 | sizeof (HandleName),\r | |
216f7970 | 261 | L"MTFTPv6(ServerIp=%s, InitialServerPort=%d)",\r |
262 | Address,\r | |
263 | Mtftp6ModeData.ConfigData.InitialServerPort\r | |
264 | );\r | |
265 | } else {\r | |
266 | UnicodeSPrint (HandleName, 0x100, L"MTFTPv6(%r)", Status);\r | |
267 | }\r | |
268 | \r | |
269 | if (gMtftp6ControllerNameTable != NULL) {\r | |
270 | FreeUnicodeStringTable (gMtftp6ControllerNameTable);\r | |
271 | gMtftp6ControllerNameTable = NULL;\r | |
272 | }\r | |
f75a7f56 | 273 | \r |
216f7970 | 274 | Status = AddUnicodeString2 (\r |
275 | "eng",\r | |
276 | gMtftp6ComponentName.SupportedLanguages,\r | |
277 | &gMtftp6ControllerNameTable,\r | |
278 | HandleName,\r | |
279 | TRUE\r | |
280 | );\r | |
281 | if (EFI_ERROR (Status)) {\r | |
282 | return Status;\r | |
283 | }\r | |
f75a7f56 | 284 | \r |
216f7970 | 285 | return AddUnicodeString2 (\r |
286 | "en",\r | |
287 | gMtftp6ComponentName2.SupportedLanguages,\r | |
288 | &gMtftp6ControllerNameTable,\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 | attempting to retrieve the name of the bus\r | |
320 | controller. It will not be NULL for a bus\r | |
321 | driver that attempts 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 | Mtftp6ComponentNameGetControllerName (\r | |
d1050b9d MK |
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 | |
a3bcde70 HT |
370 | )\r |
371 | {\r | |
d1050b9d MK |
372 | EFI_STATUS Status;\r |
373 | EFI_MTFTP6_PROTOCOL *Mtftp6;\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 | |
f75a7f56 LG |
381 | \r |
382 | //\r | |
383 | // Make sure this driver produced ChildHandle\r | |
384 | //\r | |
216f7970 | 385 | Status = EfiTestChildHandle (\r |
386 | ControllerHandle,\r | |
f75a7f56 | 387 | ChildHandle,\r |
216f7970 | 388 | &gEfiUdp6ProtocolGuid\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 | &gEfiMtftp6ProtocolGuid,\r | |
400 | (VOID **)&Mtftp6,\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 (Mtftp6);\r | |
413 | if (EFI_ERROR (Status)) {\r | |
f75a7f56 | 414 | return Status;\r |
216f7970 | 415 | }\r |
416 | \r | |
417 | return LookupUnicodeString2 (\r | |
418 | Language,\r | |
419 | This->SupportedLanguages,\r | |
420 | gMtftp6ControllerNameTable,\r | |
421 | ControllerName,\r | |
422 | (BOOLEAN)(This == &gMtftp6ComponentName)\r | |
423 | );\r | |
a3bcde70 | 424 | }\r |