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