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