]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.h
MdeModulePkg: Change the default IPv4 config policy
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Config2Impl.h
1 /** @file
2 Definitions for EFI IPv4 Configuration II Protocol implementation.
3
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #ifndef __IP4_CONFIG2_IMPL_H__
18 #define __IP4_CONFIG2_IMPL_H__
19
20 #define IP4_CONFIG2_INSTANCE_SIGNATURE SIGNATURE_32 ('I', 'P', 'C', '2')
21 #define IP4_FORM_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('I', 'F', 'C', 'I')
22
23 #define IP4_CONFIG2_VARIABLE_ATTRIBUTE (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
24
25 #define DATA_ATTRIB_SIZE_FIXED 0x1
26 #define DATA_ATTRIB_VOLATILE 0x2
27
28 #define DHCP_TAG_PARA_LIST 55
29 #define DHCP_TAG_NETMASK 1
30 #define DHCP_TAG_ROUTER 3
31 #define DHCP_TAG_DNS_SERVER 6
32
33 #define DATA_ATTRIB_SET(Attrib, Bits) (BOOLEAN)((Attrib) & (Bits))
34 #define SET_DATA_ATTRIB(Attrib, Bits) ((Attrib) |= (Bits))
35
36 typedef struct _IP4_CONFIG2_INSTANCE IP4_CONFIG2_INSTANCE;
37
38 #define IP4_CONFIG2_INSTANCE_FROM_PROTOCOL(Proto) \
39 CR ((Proto), \
40 IP4_CONFIG2_INSTANCE, \
41 Ip4Config2, \
42 IP4_CONFIG2_INSTANCE_SIGNATURE \
43 )
44
45 #define IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE(Instance) \
46 CR ((Instance), \
47 IP4_SERVICE, \
48 Ip4Config2Instance, \
49 IP4_SERVICE_SIGNATURE \
50 )
51
52 #define IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Callback) \
53 CR ((Callback), \
54 IP4_CONFIG2_INSTANCE, \
55 CallbackInfo, \
56 IP4_CONFIG2_INSTANCE_SIGNATURE \
57 )
58
59 #define IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(ConfigAccess) \
60 CR ((ConfigAccess), \
61 IP4_FORM_CALLBACK_INFO, \
62 HiiConfigAccessProtocol, \
63 IP4_FORM_CALLBACK_INFO_SIGNATURE \
64 )
65
66 /**
67 The prototype of work function for EfiIp4Config2SetData().
68
69 @param[in] Instance The pointer to the IP4 config2 instance data.
70 @param[in] DataSize In bytes, the size of the buffer pointed to by Data.
71 @param[in] Data The data buffer to set.
72
73 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
74 8 bytes.
75 @retval EFI_SUCCESS The specified configuration data for the EFI IPv4
76 network stack was set successfully.
77
78 **/
79 typedef
80 EFI_STATUS
81 (*IP4_CONFIG2_SET_DATA) (
82 IN IP4_CONFIG2_INSTANCE *Instance,
83 IN UINTN DataSize,
84 IN VOID *Data
85 );
86
87 /**
88 The prototype of work function for EfiIp4Config2GetData().
89
90 @param[in] Instance The pointer to the IP4 config2 instance data.
91 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
92 bytes, the size of buffer required to store the specified
93 configuration data.
94 @param[in] Data The data buffer in which the configuration data is returned.
95 Ignored if DataSize is ZERO.
96
97 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
98 configuration data, and the required size is
99 returned in DataSize.
100 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
101
102 **/
103 typedef
104 EFI_STATUS
105 (*IP4_CONFIG2_GET_DATA) (
106 IN IP4_CONFIG2_INSTANCE *Instance,
107 IN OUT UINTN *DataSize,
108 IN VOID *Data OPTIONAL
109 );
110
111 typedef union {
112 VOID *Ptr;
113 EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
114 EFI_IP4_CONFIG2_POLICY *Policy;
115 EFI_IP4_CONFIG2_MANUAL_ADDRESS *ManualAddress;
116 EFI_IPv4_ADDRESS *Gateway;
117 EFI_IPv4_ADDRESS *DnsServers;
118 } IP4_CONFIG2_DATA;
119
120 typedef struct {
121 IP4_CONFIG2_SET_DATA SetData;
122 IP4_CONFIG2_GET_DATA GetData;
123 EFI_STATUS Status;
124 UINT8 Attribute;
125 NET_MAP EventMap;
126 IP4_CONFIG2_DATA Data;
127 UINTN DataSize;
128 } IP4_CONFIG2_DATA_ITEM;
129
130 typedef struct {
131 UINT16 Offset;
132 UINT32 DataSize;
133 EFI_IP4_CONFIG2_DATA_TYPE DataType;
134 } IP4_CONFIG2_DATA_RECORD;
135
136 #pragma pack(1)
137
138 //
139 // heap data that contains the data for each data record.
140 //
141 // EFI_IP4_CONFIG2_POLICY Policy;
142 // UINT32 ManualaddressCount;
143 // UINT32 GatewayCount;
144 // UINT32 DnsServersCount;
145 // EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress[];
146 // EFI_IPv4_ADDRESS Gateway[];
147 // EFI_IPv4_ADDRESS DnsServers[];
148 //
149 typedef struct {
150 UINT16 Checksum;
151 UINT16 DataRecordCount;
152 IP4_CONFIG2_DATA_RECORD DataRecord[1];
153 } IP4_CONFIG2_VARIABLE;
154
155 #pragma pack()
156
157 typedef struct {
158 EFI_IP4_CONFIG2_POLICY Policy; ///< manual or automatic
159 EFI_IP4_CONFIG2_MANUAL_ADDRESS *ManualAddress; ///< IP addresses
160 UINT32 ManualAddressCount; ///< IP addresses count
161 EFI_IPv4_ADDRESS *GatewayAddress; ///< Gateway address
162 UINT32 GatewayAddressCount; ///< Gateway address count
163 EFI_IPv4_ADDRESS *DnsAddress; ///< DNS server address
164 UINT32 DnsAddressCount; ///< DNS server address count
165 } IP4_CONFIG2_NVDATA;
166
167 typedef struct _IP4_FORM_CALLBACK_INFO {
168 UINT32 Signature;
169 EFI_HANDLE ChildHandle;
170 EFI_HII_CONFIG_ACCESS_PROTOCOL HiiConfigAccessProtocol;
171 EFI_DEVICE_PATH_PROTOCOL *HiiVendorDevicePath;
172 EFI_HII_HANDLE RegisteredHandle;
173 } IP4_FORM_CALLBACK_INFO;
174
175 struct _IP4_CONFIG2_INSTANCE {
176 UINT32 Signature;
177 BOOLEAN Configured;
178 LIST_ENTRY Link;
179 UINT16 IfIndex;
180
181 EFI_IP4_CONFIG2_PROTOCOL Ip4Config2;
182
183 EFI_IP4_CONFIG2_INTERFACE_INFO InterfaceInfo;
184 EFI_IP4_CONFIG2_POLICY Policy;
185 IP4_CONFIG2_DATA_ITEM DataItem[Ip4Config2DataTypeMaximum];
186
187 EFI_EVENT Dhcp4SbNotifyEvent;
188 VOID *Registration;
189 EFI_HANDLE Dhcp4Handle;
190 EFI_DHCP4_PROTOCOL *Dhcp4;
191 BOOLEAN DhcpSuccess;
192 BOOLEAN OtherInfoOnly;
193 EFI_EVENT Dhcp4Event;
194 UINT32 FailedIaAddressCount;
195 EFI_IPv4_ADDRESS *DeclineAddress;
196 UINT32 DeclineAddressCount;
197
198 IP4_FORM_CALLBACK_INFO CallbackInfo;
199
200 IP4_CONFIG2_NVDATA Ip4NvData;
201 };
202
203 //
204 // Configure the DHCP to request the routers and netmask
205 // from server. The DHCP_TAG_NETMASK is included in Head.
206 //
207 #pragma pack(1)
208 typedef struct {
209 EFI_DHCP4_PACKET_OPTION Head;
210 UINT8 Route;
211 UINT8 Dns;
212 } IP4_CONFIG2_DHCP4_OPTION;
213 #pragma pack()
214
215 /**
216 Read the configuration data from variable storage according to the VarName and
217 gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the
218 data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
219 configuration data to IP4_CONFIG2_INSTANCE.
220
221 @param[in] VarName The pointer to the variable name
222 @param[in, out] Instance The pointer to the IP4 config2 instance data.
223
224 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
225 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
226 @retval EFI_SUCCESS The configuration data was retrieved successfully.
227
228 **/
229 EFI_STATUS
230 Ip4Config2ReadConfigData (
231 IN CHAR16 *VarName,
232 IN OUT IP4_CONFIG2_INSTANCE *Instance
233 );
234
235 /**
236 Start the DHCP configuration for this IP service instance.
237 It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
238 DHCP configuration.
239
240 @param[in] Instance The IP4 config2 instance to configure.
241
242 @retval EFI_SUCCESS The auto configuration is successfull started.
243 @retval Others Failed to start auto configuration.
244
245 **/
246 EFI_STATUS
247 Ip4StartAutoConfig (
248 IN IP4_CONFIG2_INSTANCE *Instance
249 );
250
251 /**
252 Initialize an IP4_CONFIG2_INSTANCE.
253
254 @param[out] Instance The buffer of IP4_CONFIG2_INSTANCE to be initialized.
255
256 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
257 @retval EFI_SUCCESS The IP4_CONFIG2_INSTANCE initialized successfully.
258
259 **/
260 EFI_STATUS
261 Ip4Config2InitInstance (
262 OUT IP4_CONFIG2_INSTANCE *Instance
263 );
264
265 /**
266 Release an IP4_CONFIG2_INSTANCE.
267
268 @param[in, out] Instance The buffer of IP4_CONFIG2_INSTANCE to be freed.
269
270 **/
271 VOID
272 Ip4Config2CleanInstance (
273 IN OUT IP4_CONFIG2_INSTANCE *Instance
274 );
275
276 /**
277 Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.
278
279 @param Event The event that is signalled.
280 @param Context The IP4 service binding instance.
281
282 **/
283 VOID
284 EFIAPI
285 Ip4AutoReconfigCallBack (
286 IN EFI_EVENT Event,
287 IN VOID *Context
288 );
289
290 /**
291 Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.
292
293 @param[in, out] Instance The buffer of IP4 config2 instance to be freed.
294
295 @retval EFI_SUCCESS The child was successfully destroyed.
296 @retval Others Failed to destroy the child.
297
298 **/
299 EFI_STATUS
300 Ip4Config2DestroyDhcp4 (
301 IN OUT IP4_CONFIG2_INSTANCE *Instance
302 );
303
304 #endif