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