1 | /** @file
|
---|
2 | UEFI Component Name(2) protocol implementation for Mtftp6 driver.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | This program and the accompanying materials
|
---|
7 | are licensed and made available under the terms and conditions of the BSD License
|
---|
8 | which accompanies this distribution. The full text of the license may be found at
|
---|
9 | http://opensource.org/licenses/bsd-license.php.
|
---|
10 |
|
---|
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
13 |
|
---|
14 | **/
|
---|
15 |
|
---|
16 | #include "Mtftp6Impl.h"
|
---|
17 |
|
---|
18 |
|
---|
19 | /**
|
---|
20 | Retrieves a Unicode string that is the user-readable name of the driver.
|
---|
21 |
|
---|
22 | This function retrieves the user-readable name of a driver in the form of a
|
---|
23 | Unicode string. If the driver specified by This has a user-readable name in
|
---|
24 | the language specified by Language, then a pointer to the driver name is
|
---|
25 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
|
---|
26 | by This does not support the language specified by Language,
|
---|
27 | then EFI_UNSUPPORTED is returned.
|
---|
28 |
|
---|
29 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
30 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
31 |
|
---|
32 | @param[in] Language A pointer to a Null-terminated ASCII string
|
---|
33 | array indicating the language. This is the
|
---|
34 | language of the driver name that the caller is
|
---|
35 | requesting, and it must match one of the
|
---|
36 | languages specified in SupportedLanguages. The
|
---|
37 | number of languages supported by a driver is up
|
---|
38 | to the driver writer. Language is specified
|
---|
39 | in RFC 4646 or ISO 639-2 language code format.
|
---|
40 |
|
---|
41 | @param[out] DriverName A pointer to the Unicode string to return.
|
---|
42 | This Unicode string is the name of the
|
---|
43 | driver specified by This in the language
|
---|
44 | specified by Language.
|
---|
45 |
|
---|
46 | @retval EFI_SUCCESS The Unicode string for the Driver specified by
|
---|
47 | This and the language specified by Language was
|
---|
48 | returned in DriverName.
|
---|
49 |
|
---|
50 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
51 |
|
---|
52 | @retval EFI_INVALID_PARAMETER DriverName is NULL.
|
---|
53 |
|
---|
54 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
55 | the language specified by Language.
|
---|
56 |
|
---|
57 | **/
|
---|
58 | EFI_STATUS
|
---|
59 | EFIAPI
|
---|
60 | Mtftp6ComponentNameGetDriverName (
|
---|
61 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
62 | IN CHAR8 *Language,
|
---|
63 | OUT CHAR16 **DriverName
|
---|
64 | );
|
---|
65 |
|
---|
66 | /**
|
---|
67 | Retrieves a Unicode string that is the user-readable name of the controller
|
---|
68 | that is being managed by a driver.
|
---|
69 |
|
---|
70 | This function retrieves the user-readable name of the controller specified by
|
---|
71 | ControllerHandle and ChildHandle in the form of a Unicode string. If the
|
---|
72 | driver specified by This has a user-readable name in the language specified by
|
---|
73 | Language, then a pointer to the controller name is returned in ControllerName,
|
---|
74 | and EFI_SUCCESS is returned. If the driver specified by This is not currently
|
---|
75 | managing the controller specified by ControllerHandle and ChildHandle,
|
---|
76 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not
|
---|
77 | support the language specified by Language, then EFI_UNSUPPORTED is returned.
|
---|
78 |
|
---|
79 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
80 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
81 |
|
---|
82 | @param[in] ControllerHandle The handle of a controller that the driver
|
---|
83 | specified by This is managing. This handle
|
---|
84 | specifies the controller whose name is to be
|
---|
85 | returned.
|
---|
86 |
|
---|
87 | @param[in] ChildHandle The handle of the child controller to retrieve
|
---|
88 | the name of. This is an optional parameter that
|
---|
89 | may be NULL. It will be NULL for device
|
---|
90 | drivers. It will also be NULL for bus drivers
|
---|
91 | attempting to retrieve the name of the bus
|
---|
92 | controller. It will not be NULL for a bus
|
---|
93 | driver that attempts to retrieve the name of a
|
---|
94 | child controller.
|
---|
95 |
|
---|
96 | @param[in] Language A pointer to a Null-terminated ASCII string
|
---|
97 | array indicating the language. This is the
|
---|
98 | language of the driver name that the caller is
|
---|
99 | requesting, and it must match one of the
|
---|
100 | languages specified in SupportedLanguages. The
|
---|
101 | number of languages supported by a driver is up
|
---|
102 | to the driver writer. Language is specified in
|
---|
103 | RFC 4646 or ISO 639-2 language code format.
|
---|
104 |
|
---|
105 | @param[out] ControllerName A pointer to the Unicode string to return.
|
---|
106 | This Unicode string is the name of the
|
---|
107 | controller specified by ControllerHandle and
|
---|
108 | ChildHandle in the language specified by
|
---|
109 | Language from the point of view of the driver
|
---|
110 | specified by This.
|
---|
111 |
|
---|
112 | @retval EFI_SUCCESS The Unicode string for the user-readable name in
|
---|
113 | the language specified by Language for the
|
---|
114 | driver specified by This was returned in
|
---|
115 | DriverName.
|
---|
116 |
|
---|
117 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
|
---|
118 |
|
---|
119 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
|
---|
120 | EFI_HANDLE.
|
---|
121 |
|
---|
122 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
123 |
|
---|
124 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.
|
---|
125 |
|
---|
126 | @retval EFI_UNSUPPORTED The driver specified by This is not currently
|
---|
127 | managing the controller specified by
|
---|
128 | ControllerHandle and ChildHandle.
|
---|
129 |
|
---|
130 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
131 | the language specified by Language.
|
---|
132 |
|
---|
133 | **/
|
---|
134 | EFI_STATUS
|
---|
135 | EFIAPI
|
---|
136 | Mtftp6ComponentNameGetControllerName (
|
---|
137 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
138 | IN EFI_HANDLE ControllerHandle,
|
---|
139 | IN EFI_HANDLE ChildHandle OPTIONAL,
|
---|
140 | IN CHAR8 *Language,
|
---|
141 | OUT CHAR16 **ControllerName
|
---|
142 | );
|
---|
143 |
|
---|
144 | //
|
---|
145 | // EFI Component Name Protocol
|
---|
146 | //
|
---|
147 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp6ComponentName = {
|
---|
148 | Mtftp6ComponentNameGetDriverName,
|
---|
149 | Mtftp6ComponentNameGetControllerName,
|
---|
150 | "eng"
|
---|
151 | };
|
---|
152 |
|
---|
153 | //
|
---|
154 | // EFI Component Name 2 Protocol
|
---|
155 | //
|
---|
156 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp6ComponentName2 = {
|
---|
157 | (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Mtftp6ComponentNameGetDriverName,
|
---|
158 | (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Mtftp6ComponentNameGetControllerName,
|
---|
159 | "en"
|
---|
160 | };
|
---|
161 |
|
---|
162 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp6DriverNameTable[] = {
|
---|
163 | {
|
---|
164 | "eng;en",
|
---|
165 | L"MTFTP6 Network Service Driver"
|
---|
166 | },
|
---|
167 | {
|
---|
168 | NULL,
|
---|
169 | NULL
|
---|
170 | }
|
---|
171 | };
|
---|
172 |
|
---|
173 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp6ControllerNameTable = NULL;
|
---|
174 |
|
---|
175 | /**
|
---|
176 | Retrieves a Unicode string that is the user-readable name of the driver.
|
---|
177 |
|
---|
178 | This function retrieves the user-readable name of a driver in the form of a
|
---|
179 | Unicode string. If the driver specified by This has a user-readable name in
|
---|
180 | the language specified by Language, then a pointer to the driver name is
|
---|
181 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
|
---|
182 | by This does not support the language specified by Language,
|
---|
183 | then EFI_UNSUPPORTED is returned.
|
---|
184 |
|
---|
185 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
186 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
187 |
|
---|
188 | @param[in] Language A pointer to a Null-terminated ASCII string
|
---|
189 | array indicating the language. This is the
|
---|
190 | language of the driver name that the caller is
|
---|
191 | requesting, and it must match one of the
|
---|
192 | languages specified in SupportedLanguages. The
|
---|
193 | number of languages supported by a driver is up
|
---|
194 | to the driver writer. Language is specified
|
---|
195 | in RFC 4646 or ISO 639-2 language code format.
|
---|
196 |
|
---|
197 | @param[out] DriverName A pointer to the Unicode string to return.
|
---|
198 | This Unicode string is the name of the
|
---|
199 | driver specified by This in the language
|
---|
200 | specified by Language.
|
---|
201 |
|
---|
202 | @retval EFI_SUCCESS The Unicode string for the Driver specified by
|
---|
203 | This and the language specified by Language was
|
---|
204 | returned in DriverName.
|
---|
205 |
|
---|
206 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
207 |
|
---|
208 | @retval EFI_INVALID_PARAMETER DriverName is NULL.
|
---|
209 |
|
---|
210 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
211 | the language specified by Language.
|
---|
212 |
|
---|
213 | **/
|
---|
214 | EFI_STATUS
|
---|
215 | EFIAPI
|
---|
216 | Mtftp6ComponentNameGetDriverName (
|
---|
217 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
218 | IN CHAR8 *Language,
|
---|
219 | OUT CHAR16 **DriverName
|
---|
220 | )
|
---|
221 | {
|
---|
222 | return LookupUnicodeString2 (
|
---|
223 | Language,
|
---|
224 | This->SupportedLanguages,
|
---|
225 | mMtftp6DriverNameTable,
|
---|
226 | DriverName,
|
---|
227 | (BOOLEAN)(This == &gMtftp6ComponentName)
|
---|
228 | );
|
---|
229 | }
|
---|
230 |
|
---|
231 | /**
|
---|
232 | Update the component name for the Mtftp6 child handle.
|
---|
233 |
|
---|
234 | @param Mtftp6[in] A pointer to the EFI_MTFTP6_PROTOCOL.
|
---|
235 |
|
---|
236 |
|
---|
237 | @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
|
---|
238 | @retval EFI_INVALID_PARAMETER The input parameter is invalid.
|
---|
239 |
|
---|
240 | **/
|
---|
241 | EFI_STATUS
|
---|
242 | UpdateName (
|
---|
243 | IN EFI_MTFTP6_PROTOCOL *Mtftp6
|
---|
244 | )
|
---|
245 | {
|
---|
246 | EFI_STATUS Status;
|
---|
247 | CHAR16 HandleName[128];
|
---|
248 | EFI_MTFTP6_MODE_DATA Mtftp6ModeData;
|
---|
249 | CHAR16 Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
|
---|
250 |
|
---|
251 | if (Mtftp6 == NULL) {
|
---|
252 | return EFI_INVALID_PARAMETER;
|
---|
253 | }
|
---|
254 |
|
---|
255 | //
|
---|
256 | // Format the child name into the string buffer.
|
---|
257 | //
|
---|
258 | Status = Mtftp6->GetModeData (Mtftp6, &Mtftp6ModeData);
|
---|
259 | if (!EFI_ERROR (Status)) {
|
---|
260 | Status = NetLibIp6ToStr (&Mtftp6ModeData.ConfigData.ServerIp, Address, sizeof(Address));
|
---|
261 | if (EFI_ERROR (Status)) {
|
---|
262 | return Status;
|
---|
263 | }
|
---|
264 | UnicodeSPrint (HandleName, sizeof (HandleName),
|
---|
265 | L"MTFTPv6(ServerIp=%s, InitialServerPort=%d)",
|
---|
266 | Address,
|
---|
267 | Mtftp6ModeData.ConfigData.InitialServerPort
|
---|
268 | );
|
---|
269 | } else {
|
---|
270 | UnicodeSPrint (HandleName, 0x100, L"MTFTPv6(%r)", Status);
|
---|
271 | }
|
---|
272 |
|
---|
273 | if (gMtftp6ControllerNameTable != NULL) {
|
---|
274 | FreeUnicodeStringTable (gMtftp6ControllerNameTable);
|
---|
275 | gMtftp6ControllerNameTable = NULL;
|
---|
276 | }
|
---|
277 |
|
---|
278 | Status = AddUnicodeString2 (
|
---|
279 | "eng",
|
---|
280 | gMtftp6ComponentName.SupportedLanguages,
|
---|
281 | &gMtftp6ControllerNameTable,
|
---|
282 | HandleName,
|
---|
283 | TRUE
|
---|
284 | );
|
---|
285 | if (EFI_ERROR (Status)) {
|
---|
286 | return Status;
|
---|
287 | }
|
---|
288 |
|
---|
289 | return AddUnicodeString2 (
|
---|
290 | "en",
|
---|
291 | gMtftp6ComponentName2.SupportedLanguages,
|
---|
292 | &gMtftp6ControllerNameTable,
|
---|
293 | HandleName,
|
---|
294 | FALSE
|
---|
295 | );
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | /**
|
---|
300 | Retrieves a Unicode string that is the user-readable name of the controller
|
---|
301 | that is being managed by a driver.
|
---|
302 |
|
---|
303 | This function retrieves the user-readable name of the controller specified by
|
---|
304 | ControllerHandle and ChildHandle in the form of a Unicode string. If the
|
---|
305 | driver specified by This has a user-readable name in the language specified by
|
---|
306 | Language, then a pointer to the controller name is returned in ControllerName,
|
---|
307 | and EFI_SUCCESS is returned. If the driver specified by This is not currently
|
---|
308 | managing the controller specified by ControllerHandle and ChildHandle,
|
---|
309 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not
|
---|
310 | support the language specified by Language, then EFI_UNSUPPORTED is returned.
|
---|
311 |
|
---|
312 | @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
313 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
314 |
|
---|
315 | @param[in] ControllerHandle The handle of a controller that the driver
|
---|
316 | specified by This is managing. This handle
|
---|
317 | specifies the controller whose name is to be
|
---|
318 | returned.
|
---|
319 |
|
---|
320 | @param[in] ChildHandle The handle of the child controller to retrieve
|
---|
321 | the name of. This is an optional parameter that
|
---|
322 | may be NULL. It will be NULL for device
|
---|
323 | drivers. It will also be NULL for a bus drivers
|
---|
324 | attempting to retrieve the name of the bus
|
---|
325 | controller. It will not be NULL for a bus
|
---|
326 | driver that attempts to retrieve the name of a
|
---|
327 | child controller.
|
---|
328 |
|
---|
329 | @param[in] Language A pointer to a Null-terminated ASCII string
|
---|
330 | array indicating the language. This is the
|
---|
331 | language of the driver name that the caller is
|
---|
332 | requesting, and it must match one of the
|
---|
333 | languages specified in SupportedLanguages. The
|
---|
334 | number of languages supported by a driver is up
|
---|
335 | to the driver writer. Language is specified in
|
---|
336 | RFC 4646 or ISO 639-2 language code format.
|
---|
337 |
|
---|
338 | @param[out] ControllerName A pointer to the Unicode string to return.
|
---|
339 | This Unicode string is the name of the
|
---|
340 | controller specified by ControllerHandle and
|
---|
341 | ChildHandle in the language specified by
|
---|
342 | Language from the point of view of the driver
|
---|
343 | specified by This.
|
---|
344 |
|
---|
345 | @retval EFI_SUCCESS The Unicode string for the user-readable name in
|
---|
346 | the language specified by Language for the
|
---|
347 | driver specified by This was returned in
|
---|
348 | DriverName.
|
---|
349 |
|
---|
350 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
|
---|
351 |
|
---|
352 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
|
---|
353 | EFI_HANDLE.
|
---|
354 |
|
---|
355 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
356 |
|
---|
357 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.
|
---|
358 |
|
---|
359 | @retval EFI_UNSUPPORTED The driver specified by This is not currently
|
---|
360 | managing the controller specified by
|
---|
361 | ControllerHandle and ChildHandle.
|
---|
362 |
|
---|
363 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
364 | the language specified by Language.
|
---|
365 |
|
---|
366 | **/
|
---|
367 | EFI_STATUS
|
---|
368 | EFIAPI
|
---|
369 | Mtftp6ComponentNameGetControllerName (
|
---|
370 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
371 | IN EFI_HANDLE ControllerHandle,
|
---|
372 | IN EFI_HANDLE ChildHandle OPTIONAL,
|
---|
373 | IN CHAR8 *Language,
|
---|
374 | OUT CHAR16 **ControllerName
|
---|
375 | )
|
---|
376 | {
|
---|
377 | EFI_STATUS Status;
|
---|
378 | EFI_MTFTP6_PROTOCOL *Mtftp6;
|
---|
379 |
|
---|
380 | //
|
---|
381 | // Only provide names for child handles.
|
---|
382 | //
|
---|
383 | if (ChildHandle == NULL) {
|
---|
384 | return EFI_UNSUPPORTED;
|
---|
385 | }
|
---|
386 |
|
---|
387 | //
|
---|
388 | // Make sure this driver produced ChildHandle
|
---|
389 | //
|
---|
390 | Status = EfiTestChildHandle (
|
---|
391 | ControllerHandle,
|
---|
392 | ChildHandle,
|
---|
393 | &gEfiUdp6ProtocolGuid
|
---|
394 | );
|
---|
395 | if (EFI_ERROR (Status)) {
|
---|
396 | return Status;
|
---|
397 | }
|
---|
398 |
|
---|
399 | //
|
---|
400 | // Retrieve an instance of a produced protocol from ChildHandle
|
---|
401 | //
|
---|
402 | Status = gBS->OpenProtocol (
|
---|
403 | ChildHandle,
|
---|
404 | &gEfiMtftp6ProtocolGuid,
|
---|
405 | (VOID **)&Mtftp6,
|
---|
406 | NULL,
|
---|
407 | NULL,
|
---|
408 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
409 | );
|
---|
410 | if (EFI_ERROR (Status)) {
|
---|
411 | return Status;
|
---|
412 | }
|
---|
413 |
|
---|
414 | //
|
---|
415 | // Update the component name for this child handle.
|
---|
416 | //
|
---|
417 | Status = UpdateName (Mtftp6);
|
---|
418 | if (EFI_ERROR (Status)) {
|
---|
419 | return Status;
|
---|
420 | }
|
---|
421 |
|
---|
422 | return LookupUnicodeString2 (
|
---|
423 | Language,
|
---|
424 | This->SupportedLanguages,
|
---|
425 | gMtftp6ControllerNameTable,
|
---|
426 | ControllerName,
|
---|
427 | (BOOLEAN)(This == &gMtftp6ComponentName)
|
---|
428 | );
|
---|
429 | }
|
---|
430 |
|
---|