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