• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3 Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 **/
13 
14 
15 #include "PxeBcImpl.h"
16 
17 //
18 // EFI Component Name Functions
19 //
20 /**
21   Retrieves a Unicode string that is the user readable name of the driver.
22 
23   This function retrieves the user readable name of a driver in the form of a
24   Unicode string. If the driver specified by This has a user readable name in
25   the language specified by Language, then a pointer to the driver name is
26   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
27   by This does not support the language specified by Language,
28   then EFI_UNSUPPORTED is returned.
29 
30   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
31                                 EFI_COMPONENT_NAME_PROTOCOL instance.
32 
33   @param[in]  Language          A pointer to a Null-terminated ASCII string
34                                 array indicating the language. This is the
35                                 language of the driver name that the caller is
36                                 requesting, and it must match one of the
37                                 languages specified in SupportedLanguages. The
38                                 number of languages supported by a driver is up
39                                 to the driver writer. Language is specified
40                                 in RFC 4646 or ISO 639-2 language code format.
41 
42   @param[out]  DriverName       A pointer to the Unicode string to return.
43                                 This Unicode string is the name of the
44                                 driver specified by This in the language
45                                 specified by Language.
46 
47   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
48                                 This and the language specified by Language was
49                                 returned in DriverName.
50 
51   @retval EFI_INVALID_PARAMETER Language is NULL.
52 
53   @retval EFI_INVALID_PARAMETER DriverName is NULL.
54 
55   @retval EFI_UNSUPPORTED       The driver specified by This does not support
56                                 the language specified by Language.
57 
58 **/
59 EFI_STATUS
60 EFIAPI
61 PxeBcComponentNameGetDriverName (
62   IN  EFI_COMPONENT_NAME_PROTOCOL  * This,
63   IN  CHAR8                        *Language,
64   OUT CHAR16                       **DriverName
65   );
66 
67 /**
68   Retrieves a Unicode string that is the user readable name of the controller
69   that is being managed by a driver.
70 
71   This function retrieves the user readable name of the controller specified by
72   ControllerHandle and ChildHandle in the form of a Unicode string. If the
73   driver specified by This has a user readable name in the language specified by
74   Language, then a pointer to the controller name is returned in ControllerName,
75   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
76   managing the controller specified by ControllerHandle and ChildHandle,
77   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
78   support the language specified by Language, then EFI_UNSUPPORTED is returned.
79 
80   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
81                                 EFI_COMPONENT_NAME_PROTOCOL instance.
82 
83   @param[in]  ControllerHandle  The handle of a controller that the driver
84                                 specified by This is managing.  This handle
85                                 specifies the controller whose name is to be
86                                 returned.
87 
88   @param[in]  ChildHandle       The handle of the child controller to retrieve
89                                 the name of.  This is an optional parameter that
90                                 may be NULL.  It will be NULL for device
91                                 drivers.  It will also be NULL for a bus drivers
92                                 that wish to retrieve the name of the bus
93                                 controller.  It will not be NULL for a bus
94                                 driver that wishes to retrieve the name of a
95                                 child controller.
96 
97   @param[in]  Language          A pointer to a Null-terminated ASCII string
98                                 array indicating the language.  This is the
99                                 language of the driver name that the caller is
100                                 requesting, and it must match one of the
101                                 languages specified in SupportedLanguages. The
102                                 number of languages supported by a driver is up
103                                 to the driver writer. Language is specified in
104                                 RFC 4646 or ISO 639-2 language code format.
105 
106   @param[out]  ControllerName   A pointer to the Unicode string to return.
107                                 This Unicode string is the name of the
108                                 controller specified by ControllerHandle and
109                                 ChildHandle in the language specified by
110                                 Language from the point of view of the driver
111                                 specified by This.
112 
113   @retval EFI_SUCCESS           The Unicode string for the user readable name in
114                                 the language specified by Language for the
115                                 driver specified by This was returned in
116                                 DriverName.
117 
118   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
119 
120   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
121                                 EFI_HANDLE.
122 
123   @retval EFI_INVALID_PARAMETER Language is NULL.
124 
125   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
126 
127   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
128                                 managing the controller specified by
129                                 ControllerHandle and ChildHandle.
130 
131   @retval EFI_UNSUPPORTED       The driver specified by This does not support
132                                 the language specified by Language.
133 
134 **/
135 EFI_STATUS
136 EFIAPI
137 PxeBcComponentNameGetControllerName (
138   IN  EFI_COMPONENT_NAME_PROTOCOL  * This,
139   IN  EFI_HANDLE                   ControllerHandle,
140   IN  EFI_HANDLE                   ChildHandle        OPTIONAL,
141   IN  CHAR8                        *Language,
142   OUT CHAR16                       **ControllerName
143   );
144 
145 //
146 // EFI Component Name Protocol
147 //
148 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL     gPxeBcComponentName = {
149   PxeBcComponentNameGetDriverName,
150   PxeBcComponentNameGetControllerName,
151   "eng"
152 };
153 
154 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL    gPxeBcComponentName2 = {
155   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PxeBcComponentNameGetDriverName,
156   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PxeBcComponentNameGetControllerName,
157   "en"
158 };
159 
160 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcDriverNameTable[] = {
161   {
162     "eng;en",
163     L"UEFI PXE Base Code Driver"
164   },
165   {
166     NULL,
167     NULL
168   }
169 };
170 
171 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcControllerNameTable[] = {
172   {
173     "eng;en",
174     L"PXE Controller"
175   },
176   {
177     NULL,
178     NULL
179   }
180 };
181 
182 /**
183   Retrieves a Unicode string that is the user readable name of the driver.
184 
185   This function retrieves the user readable name of a driver in the form of a
186   Unicode string. If the driver specified by This has a user readable name in
187   the language specified by Language, then a pointer to the driver name is
188   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
189   by This does not support the language specified by Language,
190   then EFI_UNSUPPORTED is returned.
191 
192   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
193                                 EFI_COMPONENT_NAME_PROTOCOL instance.
194 
195   @param[in]  Language          A pointer to a Null-terminated ASCII string
196                                 array indicating the language. This is the
197                                 language of the driver name that the caller is
198                                 requesting, and it must match one of the
199                                 languages specified in SupportedLanguages. The
200                                 number of languages supported by a driver is up
201                                 to the driver writer. Language is specified
202                                 in RFC 4646 or ISO 639-2 language code format.
203 
204   @param[out]  DriverName       A pointer to the Unicode string to return.
205                                 This Unicode string is the name of the
206                                 driver specified by This in the language
207                                 specified by Language.
208 
209   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
210                                 This and the language specified by Language was
211                                 returned in DriverName.
212 
213   @retval EFI_INVALID_PARAMETER Language is NULL.
214 
215   @retval EFI_INVALID_PARAMETER DriverName is NULL.
216 
217   @retval EFI_UNSUPPORTED       The driver specified by This does not support
218                                 the language specified by Language.
219 
220 **/
221 EFI_STATUS
222 EFIAPI
PxeBcComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)223 PxeBcComponentNameGetDriverName (
224   IN  EFI_COMPONENT_NAME_PROTOCOL  * This,
225   IN  CHAR8                        *Language,
226   OUT CHAR16                       **DriverName
227   )
228 {
229   return LookupUnicodeString2 (
230           Language,
231           This->SupportedLanguages,
232           mPxeBcDriverNameTable,
233           DriverName,
234           (BOOLEAN)(This == &gPxeBcComponentName)
235           );
236 }
237 
238 /**
239   Retrieves a Unicode string that is the user readable name of the controller
240   that is being managed by a driver.
241 
242   This function retrieves the user readable name of the controller specified by
243   ControllerHandle and ChildHandle in the form of a Unicode string. If the
244   driver specified by This has a user readable name in the language specified by
245   Language, then a pointer to the controller name is returned in ControllerName,
246   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
247   managing the controller specified by ControllerHandle and ChildHandle,
248   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
249   support the language specified by Language, then EFI_UNSUPPORTED is returned.
250 
251   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
252                                 EFI_COMPONENT_NAME_PROTOCOL instance.
253 
254   @param[in]  ControllerHandle  The handle of a controller that the driver
255                                 specified by This is managing.  This handle
256                                 specifies the controller whose name is to be
257                                 returned.
258 
259   @param[in]  ChildHandle       The handle of the child controller to retrieve
260                                 the name of.  This is an optional parameter that
261                                 may be NULL.  It will be NULL for device
262                                 drivers.  It will also be NULL for a bus drivers
263                                 that wish to retrieve the name of the bus
264                                 controller.  It will not be NULL for a bus
265                                 driver that wishes to retrieve the name of a
266                                 child controller.
267 
268   @param[in]  Language          A pointer to a Null-terminated ASCII string
269                                 array indicating the language.  This is the
270                                 language of the driver name that the caller is
271                                 requesting, and it must match one of the
272                                 languages specified in SupportedLanguages. The
273                                 number of languages supported by a driver is up
274                                 to the driver writer. Language is specified in
275                                 RFC 4646 or ISO 639-2 language code format.
276 
277   @param[out]  ControllerName   A pointer to the Unicode string to return.
278                                 This Unicode string is the name of the
279                                 controller specified by ControllerHandle and
280                                 ChildHandle in the language specified by
281                                 Language from the point of view of the driver
282                                 specified by This.
283 
284   @retval EFI_SUCCESS           The Unicode string for the user readable name in
285                                 the language specified by Language for the
286                                 driver specified by This was returned in
287                                 DriverName.
288 
289   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
290 
291   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
292                                 EFI_HANDLE.
293 
294   @retval EFI_INVALID_PARAMETER Language is NULL.
295 
296   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
297 
298   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
299                                 managing the controller specified by
300                                 ControllerHandle and ChildHandle.
301 
302   @retval EFI_UNSUPPORTED       The driver specified by This does not support
303                                 the language specified by Language.
304 
305 **/
306 EFI_STATUS
307 EFIAPI
PxeBcComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)308 PxeBcComponentNameGetControllerName (
309   IN  EFI_COMPONENT_NAME_PROTOCOL  * This,
310   IN  EFI_HANDLE                   ControllerHandle,
311   IN  EFI_HANDLE                   ChildHandle        OPTIONAL,
312   IN  CHAR8                        *Language,
313   OUT CHAR16                       **ControllerName
314   )
315 {
316   EFI_PXE_BASE_CODE_PROTOCOL  *PxeBc;
317   EFI_HANDLE                  NicHandle;
318   EFI_STATUS                  Status;
319 
320   if (ControllerHandle == NULL || ChildHandle != NULL) {
321     return EFI_UNSUPPORTED;
322   }
323 
324   NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid);
325   if (NicHandle == NULL) {
326     NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid);
327 
328     if (NicHandle == NULL) {
329       NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);
330 
331       if (NicHandle == NULL) {
332         NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);
333 
334         if (NicHandle == NULL) {
335           NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiMtftp4ProtocolGuid);
336 
337           if (NicHandle == NULL) {
338             return EFI_UNSUPPORTED;
339           }
340         }
341       }
342     }
343   }
344 
345   Status = gBS->OpenProtocol (
346                   NicHandle,
347                   &gEfiPxeBaseCodeProtocolGuid,
348                   (VOID **) &PxeBc,
349                   NULL,
350                   NULL,
351                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
352                   );
353 
354   if (EFI_ERROR (Status)) {
355     return Status;
356   }
357 
358   return LookupUnicodeString2 (
359            Language,
360            This->SupportedLanguages,
361            mPxeBcControllerNameTable,
362            ControllerName,
363            (BOOLEAN)(This == &gPxeBcComponentName)
364            );
365 }
366