summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.h
blob: 66b730a32d1d049448a5fa69a643ff35c07bb3bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/** @file
  Definitions for EFI IPv6 Configuration Protocol implementation.

  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef __IP6_CONFIG_IMPL_H__
#define __IP6_CONFIG_IMPL_H__

#define IP6_CONFIG_INSTANCE_SIGNATURE     SIGNATURE_32 ('I', 'P', '6', 'C')
#define IP6_FORM_CALLBACK_INFO_SIGNATURE  SIGNATURE_32 ('I', 'F', 'C', 'I')
#define IP6_CONFIG_VARIABLE_ATTRIBUTE     (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)

#define IP6_CONFIG_DEFAULT_DAD_XMITS  1

#define DATA_ATTRIB_SIZE_FIXED  0x1
#define DATA_ATTRIB_VOLATILE    0x2

#define DATA_ATTRIB_SET(Attrib, Bits)  (BOOLEAN)((Attrib) & (Bits))
#define SET_DATA_ATTRIB(Attrib, Bits)  ((Attrib) |= (Bits))

typedef struct _IP6_CONFIG_INSTANCE IP6_CONFIG_INSTANCE;

#define IP6_CONFIG_INSTANCE_FROM_PROTOCOL(Proto) \
  CR ((Proto), \
      IP6_CONFIG_INSTANCE, \
      Ip6Config, \
      IP6_CONFIG_INSTANCE_SIGNATURE \
      )

#define IP6_CONFIG_INSTANCE_FROM_FORM_CALLBACK(Callback) \
  CR ((Callback), \
      IP6_CONFIG_INSTANCE, \
      CallbackInfo, \
      IP6_CONFIG_INSTANCE_SIGNATURE \
      )

#define IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE(Instance) \
  CR ((Instance), \
      IP6_SERVICE, \
      Ip6ConfigInstance, \
      IP6_SERVICE_SIGNATURE \
      )

#define IP6_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(ConfigAccess) \
  CR ((ConfigAccess), \
      IP6_FORM_CALLBACK_INFO, \
      HiiConfigAccess, \
      IP6_FORM_CALLBACK_INFO_SIGNATURE \
      )

/**
  The prototype of work function for EfiIp6ConfigSetData().

  @param[in]     Instance The pointer to the IP6 config instance data.
  @param[in]     DataSize In bytes, the size of the buffer pointed to by Data.
  @param[in]     Data     The data buffer to set.

  @retval EFI_BAD_BUFFER_SIZE  The DataSize does not match the size of the type,
                               8 bytes.
  @retval EFI_SUCCESS          The specified configuration data for the EFI IPv6
                               network stack was set successfully.

**/
typedef
EFI_STATUS
(*IP6_CONFIG_SET_DATA) (
  IN IP6_CONFIG_INSTANCE  *Instance,
  IN UINTN                DataSize,
  IN VOID                 *Data
  );

/**
  The prototype of work function for EfiIp6ConfigGetData().

  @param[in]      Instance The pointer to the IP6 config instance data.
  @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
                           bytes, the size of buffer required to store the specified
                           configuration data.
  @param[in]      Data     The data buffer in which the configuration data is returned.
                           Ignored if DataSize is ZERO.

  @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
                               configuration data, and the required size is
                               returned in DataSize.
  @retval EFI_SUCCESS          The specified configuration data was obtained successfully.

**/
typedef
EFI_STATUS
(*IP6_CONFIG_GET_DATA) (
  IN IP6_CONFIG_INSTANCE  *Instance,
  IN OUT UINTN            *DataSize,
  IN VOID                 *Data      OPTIONAL
  );

typedef union {
  VOID                                        *Ptr;
  EFI_IP6_CONFIG_INTERFACE_INFO               *IfInfo;
  EFI_IP6_CONFIG_INTERFACE_ID                 *AltIfId;
  EFI_IP6_CONFIG_POLICY                       *Policy;
  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS    *DadXmits;
  EFI_IP6_CONFIG_MANUAL_ADDRESS               *ManualAddress;
  EFI_IPv6_ADDRESS                            *Gateway;
  EFI_IPv6_ADDRESS                            *DnsServers;
} IP6_CONFIG_DATA;

typedef struct {
  IP6_CONFIG_SET_DATA    SetData;
  IP6_CONFIG_GET_DATA    GetData;
  EFI_STATUS             Status;
  UINT8                  Attribute;
  NET_MAP                EventMap;
  IP6_CONFIG_DATA        Data;
  UINTN                  DataSize;
} IP6_CONFIG_DATA_ITEM;

typedef struct {
  UINT16                      Offset;
  UINT32                      DataSize;
  EFI_IP6_CONFIG_DATA_TYPE    DataType;
} IP6_CONFIG_DATA_RECORD;

#pragma pack(1)

//
// heap data that contains the data for each data record.
//
//  BOOLEAN                                   IsAltIfIdSet;
//  EFI_IP6_CONFIG_POLICY                     Policy;
//  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS  DadXmits;
//  UINT32                                    ManualaddressCount;
//  UINT32                                    GatewayCount;
//  UINT32                                    DnsServersCount;
//  EFI_IP6_CONFIG_INTERFACE_ID               AltIfId;
//  EFI_IP6_CONFIG_MANUAL_ADDRESS             ManualAddress[];
//  EFI_IPv6_ADDRESS                          Gateway[];
//  EFI_IPv6_ADDRESS                          DnsServers[];
//
typedef struct {
  UINT32                    IaId;
  UINT16                    Checksum;
  UINT16                    DataRecordCount;
  IP6_CONFIG_DATA_RECORD    DataRecord[1];
} IP6_CONFIG_VARIABLE;

#pragma pack()

typedef struct {
  LIST_ENTRY              Link;
  EFI_IP6_ADDRESS_INFO    AddrInfo;
} IP6_ADDRESS_INFO_ENTRY;

typedef struct {
  EFI_IP6_CONFIG_POLICY                       Policy;              ///< manual or automatic
  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS    DadTransmitCount;    ///< dad transmits count
  EFI_IP6_CONFIG_INTERFACE_ID                 InterfaceId;         ///< alternative interface id
  LIST_ENTRY                                  ManualAddress;       ///< IP addresses
  UINT32                                      ManualAddressCount;  ///< IP addresses count
  LIST_ENTRY                                  GatewayAddress;      ///< Gateway address
  UINT32                                      GatewayAddressCount; ///< Gateway address count
  LIST_ENTRY                                  DnsAddress;          ///< DNS server address
  UINT32                                      DnsAddressCount;     ///< DNS server address count
} IP6_CONFIG_NVDATA;

typedef struct _IP6_FORM_CALLBACK_INFO {
  UINT32                            Signature;
  EFI_HANDLE                        ChildHandle;
  EFI_HII_CONFIG_ACCESS_PROTOCOL    HiiConfigAccess;
  EFI_DEVICE_PATH_PROTOCOL          *HiiVendorDevicePath;
  EFI_HII_HANDLE                    RegisteredHandle;
} IP6_FORM_CALLBACK_INFO;

struct _IP6_CONFIG_INSTANCE {
  UINT32                                      Signature;
  BOOLEAN                                     Configured;
  LIST_ENTRY                                  Link;
  UINT16                                      IfIndex;

  EFI_IP6_CONFIG_INTERFACE_INFO               InterfaceInfo;
  EFI_IP6_CONFIG_INTERFACE_ID                 AltIfId;
  EFI_IP6_CONFIG_POLICY                       Policy;
  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS    DadXmits;

  IP6_CONFIG_DATA_ITEM                        DataItem[Ip6ConfigDataTypeMaximum];
  NET_MAP                                     DadFailedMap;
  NET_MAP                                     DadPassedMap;

  EFI_IP6_CONFIG_PROTOCOL                     Ip6Config;

  EFI_EVENT                                   Dhcp6SbNotifyEvent;
  VOID                                        *Registration;
  EFI_HANDLE                                  Dhcp6Handle;
  EFI_DHCP6_PROTOCOL                          *Dhcp6;
  BOOLEAN                                     OtherInfoOnly;
  UINT32                                      IaId;
  EFI_EVENT                                   Dhcp6Event;
  UINT32                                      FailedIaAddressCount;
  EFI_IPv6_ADDRESS                            *DeclineAddress;
  UINT32                                      DeclineAddressCount;

  IP6_FORM_CALLBACK_INFO                      CallbackInfo;
  IP6_CONFIG_NVDATA                           Ip6NvData;
};

/**
  Read the configuration data from variable storage according to the VarName and
  gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
  data is corrupted, it clears the variable data to ZERO. Otherwise, it outputs the
  configuration data to IP6_CONFIG_INSTANCE.

  @param[in]      VarName  The pointer to the variable name
  @param[in, out] Instance The pointer to the IP6 config instance data.

  @retval EFI_NOT_FOUND         The variable can not be found or already corrupted.
  @retval EFI_OUT_OF_RESOURCES  Fail to allocate resource to complete the operation.
  @retval EFI_SUCCESS           The configuration data was retrieved successfully.

**/
EFI_STATUS
Ip6ConfigReadConfigData (
  IN     CHAR16               *VarName,
  IN OUT IP6_CONFIG_INSTANCE  *Instance
  );

/**
  The event process routine when the DHCPv6 server is answered with a reply packet
  for an information request.

  @param[in]     This          Points to the EFI_DHCP6_PROTOCOL.
  @param[in]     Context       The pointer to the IP6 configuration instance data.
  @param[in]     Packet        The DHCPv6 reply packet.

  @retval EFI_SUCCESS      The DNS server address was retrieved from the reply packet.
  @retval EFI_NOT_READY    The reply packet does not contain the DNS server option, or
                           the DNS server address is not valid.

**/
EFI_STATUS
EFIAPI
Ip6ConfigOnDhcp6Reply (
  IN EFI_DHCP6_PROTOCOL  *This,
  IN VOID                *Context,
  IN EFI_DHCP6_PACKET    *Packet
  );

/**
  The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.

  @param[in]     Instance      Pointer to the IP6 config instance data.
  @param[in]     OtherInfoOnly If FALSE, get stateful address and other information
                               via DHCPv6. Otherwise, only get the other information.

  @retval    EFI_SUCCESS       The operation finished successfully.
  @retval    EFI_UNSUPPORTED   The DHCP6 driver is not available.

**/
EFI_STATUS
Ip6ConfigStartStatefulAutoConfig (
  IN IP6_CONFIG_INSTANCE  *Instance,
  IN BOOLEAN              OtherInfoOnly
  );

/**
  Initialize an IP6_CONFIG_INSTANCE.

  @param[out]    Instance       The buffer of IP6_CONFIG_INSTANCE to be initialized.

  @retval EFI_OUT_OF_RESOURCES  Failed to allocate resources to complete the operation.
  @retval EFI_SUCCESS           The IP6_CONFIG_INSTANCE initialized successfully.

**/
EFI_STATUS
Ip6ConfigInitInstance (
  OUT IP6_CONFIG_INSTANCE  *Instance
  );

/**
  Release an IP6_CONFIG_INSTANCE.

  @param[in, out] Instance    The buffer of IP6_CONFIG_INSTANCE to be freed.

**/
VOID
Ip6ConfigCleanInstance (
  IN OUT IP6_CONFIG_INSTANCE  *Instance
  );

/**
  Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.

  @param[in, out] Instance    The buffer of IP6_CONFIG_INSTANCE to be freed.

  @retval EFI_SUCCESS         The child was successfully destroyed.
  @retval Others              Failed to destroy the child.

**/
EFI_STATUS
Ip6ConfigDestroyDhcp6 (
  IN OUT IP6_CONFIG_INSTANCE  *Instance
  );

#endif