Home | History | Annotate | Download | only in UefiPxeBcDxe
      1 /** @file
      2   UEFI Component Name(2) protocol implementation for UefiPxeBc 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 "PxeBcImpl.h"
     17 
     18 /**
     19   Retrieves a Unicode string that is the user-readable name of the driver.
     20 
     21   This function retrieves the user-readable name of a driver in the form of a
     22   Unicode string. If the driver specified by This has a user-readable name in
     23   the language specified by Language, then a pointer to the driver name is
     24   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
     25   by This does not support the language specified by Language,
     26   then EFI_UNSUPPORTED is returned.
     27 
     28   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
     29                                 EFI_COMPONENT_NAME_PROTOCOL instance.
     30 
     31   @param[in]  Language          A pointer to a Null-terminated ASCII string
     32                                 array indicating the language. This is the
     33                                 language of the driver name that the caller is
     34                                 requesting, and it must match one of the
     35                                 languages specified in SupportedLanguages. The
     36                                 number of languages supported by a driver is up
     37                                 to the driver writer. Language is specified
     38                                 in RFC 4646 or ISO 639-2 language code format.
     39 
     40   @param[out]  DriverName       A pointer to the Unicode string to return.
     41                                 This Unicode string is the name of the
     42                                 driver specified by This in the language
     43                                 specified by Language.
     44 
     45   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
     46                                 This and the language specified by Language was
     47                                 returned in DriverName.
     48 
     49   @retval EFI_INVALID_PARAMETER Language is NULL.
     50 
     51   @retval EFI_INVALID_PARAMETER DriverName is NULL.
     52 
     53   @retval EFI_UNSUPPORTED       The driver specified by This does not support
     54                                 the language specified by Language.
     55 
     56 **/
     57 EFI_STATUS
     58 EFIAPI
     59 PxeBcComponentNameGetDriverName (
     60   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
     61   IN  CHAR8                        *Language,
     62   OUT CHAR16                       **DriverName
     63   );
     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 a bus drivers
     91                                 that wish to retrieve the name of the bus
     92                                 controller.  It will not be NULL for a bus
     93                                 driver that wishes 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 PxeBcComponentNameGetControllerName (
    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 //
    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 //
    155 // EFI Component Name 2 Protocol
    156 //
    157 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL   gPxeBcComponentName2 = {
    158   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PxeBcComponentNameGetDriverName,
    159   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PxeBcComponentNameGetControllerName,
    160   "en"
    161 };
    162 
    163 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE       mPxeBcDriverNameTable[] = {
    164   {
    165     "eng;en",
    166     L"UEFI PXE Base Code Driver"
    167   },
    168   {
    169     NULL,
    170     NULL
    171   }
    172 };
    173 
    174 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE       mPxeBcControllerNameTable[] = {
    175   {
    176     "eng;en",
    177     L"PXE Controller"
    178   },
    179   {
    180     NULL,
    181     NULL
    182   }
    183 };
    184 
    185 /**
    186   Retrieves a Unicode string that is the user-readable name of the driver.
    187 
    188   This function retrieves the user-readable name of a driver in the form of a
    189   Unicode string. If the driver specified by This has a user-readable name in
    190   the language specified by Language, then a pointer to the driver name is
    191   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
    192   by This does not support the language specified by Language,
    193   then EFI_UNSUPPORTED is returned.
    194 
    195   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    196                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    197 
    198   @param[in]  Language          A pointer to a Null-terminated ASCII string
    199                                 array indicating the language. This is the
    200                                 language of the driver name that the caller is
    201                                 requesting, and it must match one of the
    202                                 languages specified in SupportedLanguages. The
    203                                 number of languages supported by a driver is up
    204                                 to the driver writer. Language is specified
    205                                 in RFC 4646 or ISO 639-2 language code format.
    206 
    207   @param[out]  DriverName       A pointer to the Unicode string to return.
    208                                 This Unicode string is the name of the
    209                                 driver specified by This in the language
    210                                 specified by Language.
    211 
    212   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
    213                                 This and the language specified by Language was
    214                                 returned in DriverName.
    215 
    216   @retval EFI_INVALID_PARAMETER Language is NULL.
    217 
    218   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    219 
    220   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    221                                 the language specified by Language.
    222 
    223 **/
    224 EFI_STATUS
    225 EFIAPI
    226 PxeBcComponentNameGetDriverName (
    227   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    228   IN  CHAR8                        *Language,
    229   OUT CHAR16                       **DriverName
    230   )
    231 {
    232   return LookupUnicodeString2(
    233            Language,
    234            This->SupportedLanguages,
    235            mPxeBcDriverNameTable,
    236            DriverName,
    237            (BOOLEAN)(This == &gPxeBcComponentName)
    238            );
    239 }
    240 
    241 
    242 /**
    243   Retrieves a Unicode string that is the user-readable name of the controller
    244   that is being managed by a driver.
    245 
    246   This function retrieves the user-readable name of the controller specified by
    247   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    248   driver specified by This has a user-readable name in the language specified by
    249   Language, then a pointer to the controller name is returned in ControllerName,
    250   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    251   managing the controller specified by ControllerHandle and ChildHandle,
    252   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    253   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    254 
    255   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    256                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    257 
    258   @param[in]  ControllerHandle  The handle of a controller that the driver
    259                                 specified by This is managing.  This handle
    260                                 specifies the controller whose name is to be
    261                                 returned.
    262 
    263   @param[in]  ChildHandle       The handle of the child controller to retrieve
    264                                 the name of.  This is an optional parameter that
    265                                 may be NULL.  It will be NULL for device
    266                                 drivers.  It will also be NULL for a bus drivers
    267                                 that wish to retrieve the name of the bus
    268                                 controller.  It will not be NULL for a bus
    269                                 driver that wishes to retrieve the name of a
    270                                 child controller.
    271 
    272   @param[in]  Language          A pointer to a Null-terminated ASCII string
    273                                 array indicating the language.  This is the
    274                                 language of the driver name that the caller is
    275                                 requesting, and it must match one of the
    276                                 languages specified in SupportedLanguages. The
    277                                 number of languages supported by a driver is up
    278                                 to the driver writer. Language is specified in
    279                                 RFC 4646 or ISO 639-2 language code format.
    280 
    281   @param[out]  ControllerName   A pointer to the Unicode string to return.
    282                                 This Unicode string is the name of the
    283                                 controller specified by ControllerHandle and
    284                                 ChildHandle in the language specified by
    285                                 Language from the point of view of the driver
    286                                 specified by This.
    287 
    288   @retval EFI_SUCCESS           The Unicode string for the user-readable name in
    289                                 the language specified by Language for the
    290                                 driver specified by This was returned in
    291                                 DriverName.
    292 
    293   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
    294 
    295   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    296                                 EFI_HANDLE.
    297 
    298   @retval EFI_INVALID_PARAMETER Language is NULL.
    299 
    300   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    301 
    302   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    303                                 managing the controller specified by
    304                                 ControllerHandle and ChildHandle.
    305 
    306   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    307                                 the language specified by Language.
    308 
    309 **/
    310 EFI_STATUS
    311 EFIAPI
    312 PxeBcComponentNameGetControllerName (
    313   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    314   IN  EFI_HANDLE                   ControllerHandle,
    315   IN  EFI_HANDLE                   ChildHandle        OPTIONAL,
    316   IN  CHAR8                        *Language,
    317   OUT CHAR16                       **ControllerName
    318   )
    319 {
    320   EFI_STATUS                      Status;
    321   EFI_HANDLE                      NicHandle;
    322   PXEBC_PRIVATE_PROTOCOL          *Id;
    323 
    324   if (ControllerHandle == NULL || ChildHandle != NULL) {
    325     return EFI_UNSUPPORTED;
    326   }
    327 
    328   NicHandle = PxeBcGetNicByIp4Children (ControllerHandle);
    329   if (NicHandle == NULL) {
    330     NicHandle = PxeBcGetNicByIp6Children (ControllerHandle);
    331     if (NicHandle == NULL) {
    332       return EFI_UNSUPPORTED;
    333     }
    334   }
    335 
    336   //
    337   // Try to retrieve the private data by PxeBcPrivate protocol.
    338   //
    339   Status = gBS->OpenProtocol (
    340                   NicHandle,
    341                   &gEfiCallerIdGuid,
    342                   (VOID **) &Id,
    343                   NULL,
    344                   NULL,
    345                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
    346                   );
    347   if (EFI_ERROR (Status)) {
    348     return Status;
    349   }
    350 
    351   return LookupUnicodeString2 (
    352            Language,
    353            This->SupportedLanguages,
    354            mPxeBcControllerNameTable,
    355            ControllerName,
    356            (BOOLEAN)(This == &gPxeBcComponentName)
    357            );
    358 }
    359