Home | History | Annotate | Download | only in Ip6Dxe
      1 /** @file
      2   Definitions for EFI IPv6 Configuartion Protocol implementation.
      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 #ifndef __IP6_CONFIG_IMPL_H__
     17 #define __IP6_CONFIG_IMPL_H__
     18 
     19 #define IP6_CONFIG_INSTANCE_SIGNATURE    SIGNATURE_32 ('I', 'P', '6', 'C')
     20 #define IP6_FORM_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('I', 'F', 'C', 'I')
     21 #define IP6_CONFIG_VARIABLE_ATTRIBUTE    (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
     22 
     23 #define IP6_CONFIG_DEFAULT_DAD_XMITS        1
     24 
     25 #define DATA_ATTRIB_SIZE_FIXED              0x1
     26 #define DATA_ATTRIB_VOLATILE                0x2
     27 
     28 #define DATA_ATTRIB_SET(Attrib, Bits)       (BOOLEAN)((Attrib) & (Bits))
     29 #define SET_DATA_ATTRIB(Attrib, Bits)       ((Attrib) |= (Bits))
     30 
     31 typedef struct _IP6_CONFIG_INSTANCE IP6_CONFIG_INSTANCE;
     32 
     33 #define IP6_CONFIG_INSTANCE_FROM_PROTOCOL(Proto) \
     34   CR ((Proto), \
     35       IP6_CONFIG_INSTANCE, \
     36       Ip6Config, \
     37       IP6_CONFIG_INSTANCE_SIGNATURE \
     38       )
     39 
     40 
     41 #define IP6_CONFIG_INSTANCE_FROM_FORM_CALLBACK(Callback) \
     42   CR ((Callback), \
     43       IP6_CONFIG_INSTANCE, \
     44       CallbackInfo, \
     45       IP6_CONFIG_INSTANCE_SIGNATURE \
     46       )
     47 
     48 #define IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE(Instance) \
     49   CR ((Instance), \
     50       IP6_SERVICE, \
     51       Ip6ConfigInstance, \
     52       IP6_SERVICE_SIGNATURE \
     53       )
     54 
     55 #define IP6_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(ConfigAccess) \
     56   CR ((ConfigAccess), \
     57       IP6_FORM_CALLBACK_INFO, \
     58       HiiConfigAccess, \
     59       IP6_FORM_CALLBACK_INFO_SIGNATURE \
     60       )
     61 
     62 /**
     63   The prototype of work function for EfiIp6ConfigSetData().
     64 
     65   @param[in]     Instance The pointer to the IP6 config instance data.
     66   @param[in]     DataSize In bytes, the size of the buffer pointed to by Data.
     67   @param[in]     Data     The data buffer to set.
     68 
     69   @retval EFI_BAD_BUFFER_SIZE  The DataSize does not match the size of the type,
     70                                8 bytes.
     71   @retval EFI_SUCCESS          The specified configuration data for the EFI IPv6
     72                                network stack was set successfully.
     73 
     74 **/
     75 typedef
     76 EFI_STATUS
     77 (*IP6_CONFIG_SET_DATA) (
     78   IN IP6_CONFIG_INSTANCE  *Instance,
     79   IN UINTN                DataSize,
     80   IN VOID                 *Data
     81   );
     82 
     83 /**
     84   The prototype of work function for EfiIp6ConfigGetData().
     85 
     86   @param[in]      Instance The pointer to the IP6 config instance data.
     87   @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
     88                            bytes, the size of buffer required to store the specified
     89                            configuration data.
     90   @param[in]      Data     The data buffer in which the configuration data is returned.
     91                            Ignored if DataSize is ZERO.
     92 
     93   @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
     94                                configuration data, and the required size is
     95                                returned in DataSize.
     96   @retval EFI_SUCCESS          The specified configuration data was obtained successfully.
     97 
     98 **/
     99 typedef
    100 EFI_STATUS
    101 (*IP6_CONFIG_GET_DATA) (
    102   IN IP6_CONFIG_INSTANCE  *Instance,
    103   IN OUT UINTN            *DataSize,
    104   IN VOID                 *Data      OPTIONAL
    105   );
    106 
    107 typedef union {
    108   VOID                                      *Ptr;
    109   EFI_IP6_CONFIG_INTERFACE_INFO             *IfInfo;
    110   EFI_IP6_CONFIG_INTERFACE_ID               *AltIfId;
    111   EFI_IP6_CONFIG_POLICY                     *Policy;
    112   EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS  *DadXmits;
    113   EFI_IP6_CONFIG_MANUAL_ADDRESS             *ManualAddress;
    114   EFI_IPv6_ADDRESS                          *Gateway;
    115   EFI_IPv6_ADDRESS                          *DnsServers;
    116 } IP6_CONFIG_DATA;
    117 
    118 typedef struct {
    119   IP6_CONFIG_SET_DATA  SetData;
    120   IP6_CONFIG_GET_DATA  GetData;
    121   EFI_STATUS           Status;
    122   UINT8                Attribute;
    123   NET_MAP              EventMap;
    124   IP6_CONFIG_DATA      Data;
    125   UINTN                DataSize;
    126 } IP6_CONFIG_DATA_ITEM;
    127 
    128 typedef struct {
    129   UINT16                    Offset;
    130   UINT32                    DataSize;
    131   EFI_IP6_CONFIG_DATA_TYPE  DataType;
    132 } IP6_CONFIG_DATA_RECORD;
    133 
    134 #pragma pack(1)
    135 
    136 //
    137 // heap data that contains the data for each data record.
    138 //
    139 //  BOOLEAN                                   IsAltIfIdSet;
    140 //  EFI_IP6_CONFIG_POLICY                     Policy;
    141 //  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS  DadXmits;
    142 //  UINT32                                    ManualaddressCount;
    143 //  UINT32                                    GatewayCount;
    144 //  UINT32                                    DnsServersCount;
    145 //  EFI_IP6_CONFIG_INTERFACE_ID               AltIfId;
    146 //  EFI_IP6_CONFIG_MANUAL_ADDRESS             ManualAddress[];
    147 //  EFI_IPv6_ADDRESS                          Gateway[];
    148 //  EFI_IPv6_ADDRESS                          DnsServers[];
    149 //
    150 typedef struct {
    151   UINT32                  IaId;
    152   UINT16                  Checksum;
    153   UINT16                  DataRecordCount;
    154   IP6_CONFIG_DATA_RECORD  DataRecord[1];
    155 } IP6_CONFIG_VARIABLE;
    156 
    157 #pragma pack()
    158 
    159 typedef struct {
    160   LIST_ENTRY                  Link;
    161   EFI_IP6_ADDRESS_INFO        AddrInfo;
    162 } IP6_ADDRESS_INFO_ENTRY;
    163 
    164 typedef struct {
    165   EFI_IP6_CONFIG_POLICY                    Policy;              ///< manual or automatic
    166   EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS DadTransmitCount;    ///< dad transmits count
    167   EFI_IP6_CONFIG_INTERFACE_ID              InterfaceId;         ///< alternative interface id
    168   LIST_ENTRY                               ManualAddress;       ///< IP addresses
    169   UINT32                                   ManualAddressCount;  ///< IP addresses count
    170   LIST_ENTRY                               GatewayAddress;      ///< Gateway address
    171   UINT32                                   GatewayAddressCount; ///< Gateway address count
    172   LIST_ENTRY                               DnsAddress;          ///< DNS server address
    173   UINT32                                   DnsAddressCount;     ///< DNS server address count
    174 } IP6_CONFIG_NVDATA;
    175 
    176 typedef struct _IP6_FORM_CALLBACK_INFO {
    177   UINT32                           Signature;
    178   EFI_HANDLE                       ChildHandle;
    179   EFI_HII_CONFIG_ACCESS_PROTOCOL   HiiConfigAccess;
    180   EFI_DEVICE_PATH_PROTOCOL         *HiiVendorDevicePath;
    181   EFI_HII_HANDLE                   RegisteredHandle;
    182 } IP6_FORM_CALLBACK_INFO;
    183 
    184 struct _IP6_CONFIG_INSTANCE {
    185   UINT32                                    Signature;
    186   BOOLEAN                                   Configured;
    187   LIST_ENTRY                                Link;
    188   UINT16                                    IfIndex;
    189 
    190   EFI_IP6_CONFIG_INTERFACE_INFO             InterfaceInfo;
    191   EFI_IP6_CONFIG_INTERFACE_ID               AltIfId;
    192   EFI_IP6_CONFIG_POLICY                     Policy;
    193   EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS  DadXmits;
    194 
    195   IP6_CONFIG_DATA_ITEM                      DataItem[Ip6ConfigDataTypeMaximum];
    196   NET_MAP                                   DadFailedMap;
    197   NET_MAP                                   DadPassedMap;
    198 
    199   EFI_IP6_CONFIG_PROTOCOL                   Ip6Config;
    200 
    201   EFI_EVENT                                 Dhcp6SbNotifyEvent;
    202   VOID                                      *Registration;
    203   EFI_HANDLE                                Dhcp6Handle;
    204   EFI_DHCP6_PROTOCOL                        *Dhcp6;
    205   BOOLEAN                                   OtherInfoOnly;
    206   UINT32                                    IaId;
    207   EFI_EVENT                                 Dhcp6Event;
    208   UINT32                                    FailedIaAddressCount;
    209   EFI_IPv6_ADDRESS                          *DeclineAddress;
    210   UINT32                                    DeclineAddressCount;
    211 
    212   IP6_FORM_CALLBACK_INFO                    CallbackInfo;
    213   IP6_CONFIG_NVDATA                         Ip6NvData;
    214 };
    215 
    216 /**
    217   Read the configuration data from variable storage according to the VarName and
    218   gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
    219   data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
    220   configuration data to IP6_CONFIG_INSTANCE.
    221 
    222   @param[in]      VarName  The pointer to the variable name
    223   @param[in, out] Instance The pointer to the IP6 config instance data.
    224 
    225   @retval EFI_NOT_FOUND         The variable can not be found or already corrupted.
    226   @retval EFI_OUT_OF_RESOURCES  Fail to allocate resource to complete the operation.
    227   @retval EFI_SUCCESS           The configuration data was retrieved successfully.
    228 
    229 **/
    230 EFI_STATUS
    231 Ip6ConfigReadConfigData (
    232   IN     CHAR16               *VarName,
    233   IN OUT IP6_CONFIG_INSTANCE  *Instance
    234   );
    235 
    236 /**
    237   The event process routine when the DHCPv6 server is answered with a reply packet
    238   for an information request.
    239 
    240   @param[in]     This          Points to the EFI_DHCP6_PROTOCOL.
    241   @param[in]     Context       The pointer to the IP6 configuration instance data.
    242   @param[in]     Packet        The DHCPv6 reply packet.
    243 
    244   @retval EFI_SUCCESS      The DNS server address was retrieved from the reply packet.
    245   @retval EFI_NOT_READY    The reply packet does not contain the DNS server option, or
    246                            the DNS server address is not valid.
    247 
    248 **/
    249 EFI_STATUS
    250 EFIAPI
    251 Ip6ConfigOnDhcp6Reply (
    252   IN EFI_DHCP6_PROTOCOL  *This,
    253   IN VOID                *Context,
    254   IN EFI_DHCP6_PACKET    *Packet
    255   );
    256 
    257 /**
    258   The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.
    259 
    260   @param[in]     Instance      Pointer to the IP6 config instance data.
    261   @param[in]     OtherInfoOnly If FALSE, get stateful address and other information
    262                                via DHCPv6. Otherwise, only get the other information.
    263 
    264   @retval    EFI_SUCCESS       The operation finished successfully.
    265   @retval    EFI_UNSUPPORTED   The DHCP6 driver is not available.
    266 
    267 **/
    268 EFI_STATUS
    269 Ip6ConfigStartStatefulAutoConfig (
    270   IN IP6_CONFIG_INSTANCE  *Instance,
    271   IN BOOLEAN              OtherInfoOnly
    272   );
    273 
    274 /**
    275   Initialize an IP6_CONFIG_INSTANCE.
    276 
    277   @param[out]    Instance       The buffer of IP6_CONFIG_INSTANCE to be initialized.
    278 
    279   @retval EFI_OUT_OF_RESOURCES  Failed to allocate resources to complete the operation.
    280   @retval EFI_SUCCESS           The IP6_CONFIG_INSTANCE initialized successfully.
    281 
    282 **/
    283 EFI_STATUS
    284 Ip6ConfigInitInstance (
    285   OUT IP6_CONFIG_INSTANCE  *Instance
    286   );
    287 
    288 /**
    289   Release an IP6_CONFIG_INSTANCE.
    290 
    291   @param[in, out] Instance    The buffer of IP6_CONFIG_INSTANCE to be freed.
    292 
    293 **/
    294 VOID
    295 Ip6ConfigCleanInstance (
    296   IN OUT IP6_CONFIG_INSTANCE  *Instance
    297   );
    298 
    299 /**
    300   Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.
    301 
    302   @param[in, out] Instance    The buffer of IP6_CONFIG_INSTANCE to be freed.
    303 
    304   @retval EFI_SUCCESS         The child was successfully destroyed.
    305   @retval Others              Failed to destroy the child.
    306 
    307 **/
    308 EFI_STATUS
    309 Ip6ConfigDestroyDhcp6 (
    310   IN OUT IP6_CONFIG_INSTANCE  *Instance
    311   );
    312 
    313 #endif
    314