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