Home | History | Annotate | Download | only in Dhcp6Dxe
      1 /** @file
      2   UEFI Component Name(2) protocol implementation for Dhcp6 driver.
      3 
      4   Copyright (c) 2009 - 2016, 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 "Dhcp6Impl.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 Dhcp6ComponentNameGetDriverName (
     61   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
     62   IN  CHAR8                        *Language,
     63   OUT CHAR16                       **DriverName
     64   );
     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 attempt to retrieve the name of the bus
     93                                 controller.  It will not be NULL for a bus
     94                                 driver that attempts 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 Dhcp6ComponentNameGetControllerName (
    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 //
    147 // EFI Component Name Protocol
    148 //
    149 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL    gDhcp6ComponentName = {
    150   Dhcp6ComponentNameGetDriverName,
    151   Dhcp6ComponentNameGetControllerName,
    152   "eng"
    153 };
    154 
    155 //
    156 // EFI Component Name 2 Protocol
    157 //
    158 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL   gDhcp6ComponentName2 = {
    159   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Dhcp6ComponentNameGetDriverName,
    160   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Dhcp6ComponentNameGetControllerName,
    161   "en"
    162 };
    163 
    164 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE       mDhcp6DriverNameTable[] = {
    165   {
    166     "eng;en",
    167     L"DHCP6 Protocol Driver"
    168   },
    169   {
    170     NULL,
    171     NULL
    172   }
    173 };
    174 
    175 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE   *gDhcp6ControllerNameTable = NULL;
    176 
    177 CHAR16 *mDhcp6ControllerName[] = {
    178   L"DHCPv6 (State=0, Init)",
    179   L"DHCPv6 (State=1, Selecting)",
    180   L"DHCPv6 (State=2, Requesting)",
    181   L"DHCPv6 (State=3, Declining)",
    182   L"DHCPv6 (State=4, Confirming)",
    183   L"DHCPv6 (State=5, Releasing)",
    184   L"DHCPv6 (State=6, Bound)",
    185   L"DHCPv6 (State=7, Renewing)",
    186   L"DHCPv6 (State=8, Rebinding)"
    187 };
    188 
    189 /**
    190   Retrieves a Unicode string that is the user-readable name of the driver.
    191 
    192   This function retrieves the user-readable name of a driver in the form of a
    193   Unicode string. If the driver specified by This has a user-readable name in
    194   the language specified by Language, then a pointer to the driver name is
    195   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
    196   by This does not support the language specified by Language,
    197   then EFI_UNSUPPORTED is returned.
    198 
    199   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    200                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    201 
    202   @param[in]  Language          A pointer to a Null-terminated ASCII string
    203                                 array indicating the language. This is the
    204                                 language of the driver name that the caller is
    205                                 requesting, and it must match one of the
    206                                 languages specified in SupportedLanguages. The
    207                                 number of languages supported by a driver is up
    208                                 to the driver writer. Language is specified
    209                                 in RFC 4646 or ISO 639-2 language code format.
    210 
    211   @param[out]  DriverName       A pointer to the Unicode string to return.
    212                                 This Unicode string is the name of the
    213                                 driver specified by This in the language
    214                                 specified by Language.
    215 
    216   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
    217                                 This and the language specified by Language was
    218                                 returned in DriverName.
    219 
    220   @retval EFI_INVALID_PARAMETER Language is NULL.
    221 
    222   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    223 
    224   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    225                                 the language specified by Language.
    226 
    227 **/
    228 EFI_STATUS
    229 EFIAPI
    230 Dhcp6ComponentNameGetDriverName (
    231   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    232   IN  CHAR8                        *Language,
    233   OUT CHAR16                       **DriverName
    234   )
    235 {
    236   return LookupUnicodeString2 (
    237            Language,
    238            This->SupportedLanguages,
    239            mDhcp6DriverNameTable,
    240            DriverName,
    241            (BOOLEAN)(This == &gDhcp6ComponentName)
    242            );
    243 }
    244 
    245 /**
    246   Update the component name for the Dhcp6 child handle.
    247 
    248   @param  Dhcp6[in]                   A pointer to the EFI_DHCP6_PROTOCOL.
    249 
    250 
    251   @retval EFI_SUCCESS                 Update the ControllerNameTable of this instance successfully.
    252   @retval EFI_INVALID_PARAMETER       The input parameter is invalid.
    253 
    254 **/
    255 EFI_STATUS
    256 UpdateName (
    257   IN   EFI_DHCP6_PROTOCOL             *Dhcp6
    258   )
    259 {
    260   EFI_STATUS                       Status;
    261   EFI_DHCP6_MODE_DATA              Dhcp6ModeData;
    262   CHAR16                           *HandleName;
    263 
    264   if (Dhcp6 == NULL) {
    265     return EFI_INVALID_PARAMETER;
    266   }
    267 
    268   //
    269   // Format the child name into the string buffer.
    270   //
    271   Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);
    272   if (EFI_ERROR (Status)) {
    273     return Status;
    274   }
    275 
    276   if (gDhcp6ControllerNameTable != NULL) {
    277     FreeUnicodeStringTable (gDhcp6ControllerNameTable);
    278     gDhcp6ControllerNameTable = NULL;
    279   }
    280 
    281   if (Dhcp6ModeData.Ia == NULL) {
    282     HandleName = L"DHCPv6 (No configured IA)";
    283   } else {
    284     if (Dhcp6ModeData.Ia->State > Dhcp6Rebinding) {
    285       return EFI_DEVICE_ERROR;
    286     }
    287     HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];
    288   }
    289 
    290   if (Dhcp6ModeData.Ia != NULL) {
    291     FreePool (Dhcp6ModeData.Ia);
    292   }
    293   if (Dhcp6ModeData.ClientId != NULL) {
    294     FreePool (Dhcp6ModeData.ClientId);
    295   }
    296 
    297   Status = AddUnicodeString2 (
    298              "eng",
    299              gDhcp6ComponentName.SupportedLanguages,
    300              &gDhcp6ControllerNameTable,
    301              HandleName,
    302              TRUE
    303              );
    304   if (EFI_ERROR (Status)) {
    305     return Status;
    306   }
    307 
    308   return AddUnicodeString2 (
    309            "en",
    310            gDhcp6ComponentName2.SupportedLanguages,
    311            &gDhcp6ControllerNameTable,
    312            HandleName,
    313            FALSE
    314            );
    315 }
    316 
    317 /**
    318   Retrieves a Unicode string that is the user-readable name of the controller
    319   that is being managed by a driver.
    320 
    321   This function retrieves the user-readable name of the controller specified by
    322   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    323   driver specified by This has a user-readable name in the language specified by
    324   Language, then a pointer to the controller name is returned in ControllerName,
    325   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    326   managing the controller specified by ControllerHandle and ChildHandle,
    327   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    328   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    329 
    330   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    331                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    332 
    333   @param[in]  ControllerHandle  The handle of a controller that the driver
    334                                 specified by This is managing.  This handle
    335                                 specifies the controller whose name is to be
    336                                 returned.
    337 
    338   @param[in]  ChildHandle       The handle of the child controller to retrieve
    339                                 the name of.  This is an optional parameter that
    340                                 may be NULL.  It will be NULL for device
    341                                 drivers.  It will also be NULL for a bus drivers
    342                                 that wish to retrieve the name of the bus
    343                                 controller.  It will not be NULL for a bus
    344                                 driver that wishes to retrieve the name of a
    345                                 child controller.
    346 
    347   @param[in]  Language          A pointer to a Null-terminated ASCII string
    348                                 array indicating the language.  This is the
    349                                 language of the driver name that the caller is
    350                                 requesting, and it must match one of the
    351                                 languages specified in SupportedLanguages. The
    352                                 number of languages supported by a driver is up
    353                                 to the driver writer. Language is specified in the
    354                                 RFC 4646 or ISO 639-2 language code format.
    355 
    356   @param[out]  ControllerName   A pointer to the Unicode string to return.
    357                                 This Unicode string is the name of the
    358                                 controller specified by ControllerHandle and
    359                                 ChildHandle in the language specified by
    360                                 Language, from the point of view of the driver
    361                                 specified by This.
    362 
    363   @retval EFI_SUCCESS           The Unicode string for the user-readable name in
    364                                 the language specified by Language for the
    365                                 driver specified by This was returned in
    366                                 DriverName.
    367 
    368   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
    369 
    370   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
    371                                 EFI_HANDLE.
    372 
    373   @retval EFI_INVALID_PARAMETER Language is NULL.
    374 
    375   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    376 
    377   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    378                                 managing the controller specified by
    379                                 ControllerHandle and ChildHandle.
    380 
    381   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    382                                 the language specified by Language.
    383 
    384 **/
    385 EFI_STATUS
    386 EFIAPI
    387 Dhcp6ComponentNameGetControllerName (
    388   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    389   IN  EFI_HANDLE                                      ControllerHandle,
    390   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    391   IN  CHAR8                                           *Language,
    392   OUT CHAR16                                          **ControllerName
    393   )
    394 {
    395   EFI_STATUS                    Status;
    396   EFI_DHCP6_PROTOCOL            *Dhcp6;
    397 
    398   //
    399   // Only provide names for child handles.
    400   //
    401   if (ChildHandle == NULL) {
    402     return EFI_UNSUPPORTED;
    403   }
    404 
    405   //
    406   // Make sure this driver produced ChildHandle
    407   //
    408   Status = EfiTestChildHandle (
    409              ControllerHandle,
    410              ChildHandle,
    411              &gEfiUdp6ProtocolGuid
    412              );
    413   if (EFI_ERROR (Status)) {
    414     return Status;
    415   }
    416 
    417   //
    418   // Retrieve an instance of a produced protocol from ChildHandle
    419   //
    420   Status = gBS->OpenProtocol (
    421                   ChildHandle,
    422                   &gEfiDhcp6ProtocolGuid,
    423                   (VOID **)&Dhcp6,
    424                   NULL,
    425                   NULL,
    426                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
    427                   );
    428   if (EFI_ERROR (Status)) {
    429     return Status;
    430   }
    431 
    432   //
    433   // Update the component name for this child handle.
    434   //
    435   Status = UpdateName (Dhcp6);
    436   if (EFI_ERROR (Status)) {
    437     return Status;
    438   }
    439 
    440   return LookupUnicodeString2 (
    441            Language,
    442            This->SupportedLanguages,
    443            gDhcp6ControllerNameTable,
    444            ControllerName,
    445            (BOOLEAN)(This == &gDhcp6ComponentName)
    446            );
    447 }
    448 
    449