]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
MdeModulePkg/Ip4Dxe: return error on memory allocate failure instead of ASSERT.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Impl.h
CommitLineData
83cbd279 1/** @file\r
3e8c18da 2 Ip4 internal functions and type defintions.\r
3 \r
4bb89650 4Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
c79de074
SEHM
5(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
6\r
e5eed7d3 7This program and the accompanying materials\r
83cbd279 8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
83cbd279 15**/\r
16\r
17#ifndef __EFI_IP4_IMPL_H__\r
18#define __EFI_IP4_IMPL_H__\r
19\r
2517435c 20#include <Uefi.h>\r
772db4bb 21\r
a1503a32 22#include <Protocol/IpSec.h>\r
5f778b1f 23#include <Protocol/Ip4.h>\r
1f6729ff 24#include <Protocol/Ip4Config2.h>\r
772db4bb 25#include <Protocol/Arp.h>\r
26#include <Protocol/ManagedNetwork.h>\r
1f6729ff 27#include <Protocol/Dhcp4.h>\r
28#include <Protocol/HiiConfigRouting.h>\r
29#include <Protocol/HiiConfigAccess.h>\r
772db4bb 30\r
ac6c3d90
ZL
31#include <IndustryStandard/Dhcp.h>\r
32\r
772db4bb 33#include <Library/DebugLib.h>\r
34#include <Library/UefiRuntimeServicesTableLib.h>\r
35#include <Library/UefiDriverEntryPoint.h>\r
36#include <Library/UefiBootServicesTableLib.h>\r
37#include <Library/BaseLib.h>\r
83cbd279 38#include <Library/UefiLib.h>\r
39#include <Library/NetLib.h>\r
40#include <Library/BaseMemoryLib.h>\r
41#include <Library/MemoryAllocationLib.h>\r
d8d26fb2 42#include <Library/DpcLib.h>\r
216f7970 43#include <Library/PrintLib.h>\r
1f6729ff 44#include <Library/DevicePathLib.h>\r
45#include <Library/HiiLib.h>\r
46#include <Library/UefiHiiServicesLib.h>\r
83cbd279 47\r
48#include "Ip4Common.h"\r
49#include "Ip4Driver.h"\r
50#include "Ip4If.h"\r
51#include "Ip4Icmp.h"\r
52#include "Ip4Option.h"\r
53#include "Ip4Igmp.h"\r
54#include "Ip4Route.h"\r
55#include "Ip4Input.h"\r
56#include "Ip4Output.h"\r
1f6729ff 57#include "Ip4Config2Impl.h"\r
58#include "Ip4Config2Nv.h"\r
59#include "Ip4NvData.h"\r
83cbd279 60\r
f6b7393c 61#define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')\r
62#define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')\r
c6bc765f 63\r
f6b7393c 64//\r
65// The state of IP4 protocol. It starts from UNCONFIGED. if it is\r
66// successfully configured, it goes to CONFIGED. if configure NULL\r
4bb89650 67// is called, it becomes UNCONFIGED again.\r
f6b7393c 68//\r
69#define IP4_STATE_UNCONFIGED 0\r
70#define IP4_STATE_CONFIGED 1\r
c6bc765f 71\r
f6b7393c 72//\r
73// The state of IP4 service. It starts from UNSTARTED. It transits\r
74// to STARTED if autoconfigure is started. If default address is\r
75dce340 75// configured, it becomes CONFIGED. and if partly destroyed, it goes\r
76// to DESTROY.\r
f6b7393c 77//\r
78#define IP4_SERVICE_UNSTARTED 0\r
79#define IP4_SERVICE_STARTED 1\r
80#define IP4_SERVICE_CONFIGED 2\r
75dce340 81#define IP4_SERVICE_DESTROY 3\r
83cbd279 82\r
83cbd279 83\r
96e1079f 84///\r
85/// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.\r
86/// The user's data is kept in the Packet. When fragment is\r
87/// needed, each fragment of the Packet has a reference to the\r
88/// Packet, no data is actually copied. The Packet will be\r
89/// released when all the fragments of it have been recycled by\r
90/// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and\r
91/// user's event signalled.\r
92///\r
83cbd279 93typedef struct {\r
94 IP4_PROTOCOL *IpInstance;\r
95 EFI_IP4_COMPLETION_TOKEN *Token;\r
a1503a32 96 EFI_EVENT IpSecRecycleSignal;\r
83cbd279 97 NET_BUF *Packet;\r
98 BOOLEAN Sent;\r
99 INTN Life;\r
100} IP4_TXTOKEN_WRAP;\r
101\r
a1503a32 102///\r
103/// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet\r
104/// will be released after it has been processed by the receiver. Upon then,\r
105/// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled\r
106/// to notice IPsec to free the resources.\r
107///\r
108typedef struct {\r
109 EFI_EVENT IpSecRecycleSignal;\r
110 NET_BUF *Packet;\r
111} IP4_IPSEC_WRAP;\r
112\r
96e1079f 113///\r
114/// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the\r
115/// upper layers. The received packet is kept in the Packet.\r
116/// The Packet itself may be constructured from some fragments.\r
117/// All the fragments of the Packet is organized by a\r
118/// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by\r
119/// the upper layer, the assemble entry and its associated\r
120/// fragments will be freed at last.\r
121///\r
83cbd279 122typedef struct {\r
e48e37fc 123 LIST_ENTRY Link;\r
83cbd279 124 IP4_PROTOCOL *IpInstance;\r
125 NET_BUF *Packet;\r
126 EFI_IP4_RECEIVE_DATA RxData;\r
127} IP4_RXDATA_WRAP;\r
128\r
c6bc765f 129\r
130struct _IP4_PROTOCOL {\r
83cbd279 131 UINT32 Signature;\r
132\r
133 EFI_IP4_PROTOCOL Ip4Proto;\r
134 EFI_HANDLE Handle;\r
135 INTN State;\r
136\r
4bb89650
ZL
137 BOOLEAN InDestroy; \r
138\r
83cbd279 139 IP4_SERVICE *Service;\r
a1503a32 140 LIST_ENTRY Link; // Link to all the IP protocol from the service\r
83cbd279 141\r
142 //\r
143 // User's transmit/receive tokens, and received/deliverd packets\r
144 //\r
145 NET_MAP RxTokens;\r
146 NET_MAP TxTokens; // map between (User's Token, IP4_TXTOKE_WRAP)\r
e48e37fc 147 LIST_ENTRY Received; // Received but not delivered packet\r
148 LIST_ENTRY Delivered; // Delivered and to be recycled packets\r
83cbd279 149 EFI_LOCK RecycleLock;\r
150\r
151 //\r
152 // Instance's address and route tables. There are two route tables.\r
153 // RouteTable is used by the IP4 driver to route packet. EfiRouteTable\r
154 // is used to communicate the current route info to the upper layer.\r
155 //\r
156 IP4_INTERFACE *Interface;\r
e48e37fc 157 LIST_ENTRY AddrLink; // Ip instances with the same IP address.\r
83cbd279 158 IP4_ROUTE_TABLE *RouteTable;\r
159\r
160 EFI_IP4_ROUTE_TABLE *EfiRouteTable;\r
161 UINT32 EfiRouteCount;\r
162\r
163 //\r
164 // IGMP data for this instance\r
165 //\r
a1503a32 166 IP4_ADDR *Groups; // stored in network byte order\r
83cbd279 167 UINT32 GroupCount;\r
168\r
169 EFI_IP4_CONFIG_DATA ConfigData;\r
170\r
c6bc765f 171};\r
83cbd279 172\r
c6bc765f 173struct _IP4_SERVICE {\r
83cbd279 174 UINT32 Signature;\r
175 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
176 INTN State;\r
83cbd279 177\r
178 //\r
179 // List of all the IP instances and interfaces, and default\r
180 // interface and route table and caches.\r
181 //\r
182 UINTN NumChildren;\r
e48e37fc 183 LIST_ENTRY Children;\r
83cbd279 184\r
e48e37fc 185 LIST_ENTRY Interfaces;\r
83cbd279 186\r
187 IP4_INTERFACE *DefaultInterface;\r
188 IP4_ROUTE_TABLE *DefaultRouteTable;\r
189\r
190 //\r
191 // Ip reassemble utilities, and IGMP data\r
192 //\r
193 IP4_ASSEMBLE_TABLE Assemble;\r
194 IGMP_SERVICE_DATA IgmpCtrl;\r
195\r
196 //\r
197 // Low level protocol used by this service instance\r
198 //\r
199 EFI_HANDLE Image;\r
200 EFI_HANDLE Controller;\r
201\r
202 EFI_HANDLE MnpChildHandle;\r
203 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
204\r
205 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;\r
206 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
207\r
208 EFI_EVENT Timer;\r
209\r
2c320007
JW
210 EFI_EVENT ReconfigEvent;\r
211\r
e371cc14
JW
212 BOOLEAN Reconfig;\r
213\r
2c320007
JW
214 //\r
215 // Underlying media present status. \r
216 //\r
217 BOOLEAN MediaPresent;\r
218\r
83cbd279 219 //\r
1f6729ff 220 // IPv4 Configuration II Protocol instance\r
83cbd279 221 //\r
1f6729ff 222 IP4_CONFIG2_INSTANCE Ip4Config2Instance;\r
223\r
224 CHAR16 *MacString;\r
83cbd279 225\r
a1503a32 226 UINT32 MaxPacketSize;\r
227 UINT32 OldMaxPacketSize; ///< The MTU before IPsec enable.\r
c6bc765f 228};\r
83cbd279 229\r
230#define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \\r
231 CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)\r
232\r
233#define IP4_SERVICE_FROM_PROTOCOL(Sb) \\r
234 CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)\r
235\r
1f6729ff 236#define IP4_SERVICE_FROM_CONFIG2_INSTANCE(This) \\r
237 CR (This, IP4_SERVICE, Ip4Config2Instance, IP4_SERVICE_SIGNATURE)\r
238\r
239\r
83cbd279 240#define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)\r
241\r
242extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete;\r
243\r
2ff29212 244/**\r
245 Config the MNP parameter used by IP. The IP driver use one MNP\r
246 child to transmit/receive frames. By default, it configures MNP\r
247 to receive unicast/multicast/broadcast. And it will enable/disable\r
248 the promiscous receive according to whether there is IP child\r
249 enable that or not. If Force is FALSE, it will iterate through\r
250 all the IP children to check whether the promiscuous receive\r
251 setting has been changed. If it hasn't been changed, it won't\r
252 reconfigure the MNP. If Force is TRUE, the MNP is configured no\r
253 matter whether that is changed or not.\r
254\r
3e8c18da 255 @param[in] IpSb The IP4 service instance that is to be changed.\r
256 @param[in] Force Force the configuration or not.\r
2ff29212 257\r
258 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.\r
259 @retval Others Configuration failed.\r
260\r
261**/\r
83cbd279 262EFI_STATUS\r
263Ip4ServiceConfigMnp (\r
264 IN IP4_SERVICE *IpSb,\r
265 IN BOOLEAN Force\r
266 );\r
267\r
2ff29212 268/**\r
269 Intiialize the IP4_PROTOCOL structure to the unconfigured states.\r
270\r
271 @param IpSb The IP4 service instance.\r
272 @param IpInstance The IP4 child instance.\r
273\r
2ff29212 274**/\r
83cbd279 275VOID\r
276Ip4InitProtocol (\r
2ff29212 277 IN IP4_SERVICE *IpSb,\r
278 IN OUT IP4_PROTOCOL *IpInstance\r
83cbd279 279 );\r
280\r
2ff29212 281/**\r
282 Clean up the IP4 child, release all the resources used by it.\r
283\r
3e8c18da 284 @param[in] IpInstance The IP4 child to clean up.\r
2ff29212 285\r
1f6729ff 286 @retval EFI_SUCCESS The IP4 child is cleaned up.\r
287 @retval EFI_DEVICE_ERROR Some resources failed to be released.\r
2ff29212 288\r
289**/\r
83cbd279 290EFI_STATUS\r
291Ip4CleanProtocol (\r
292 IN IP4_PROTOCOL *IpInstance\r
293 );\r
294\r
2ff29212 295/**\r
296 Cancel the user's receive/transmit request.\r
297\r
1f6729ff 298 @param[in] IpInstance The IP4 child.\r
3e8c18da 299 @param[in] Token The token to cancel. If NULL, all token will be\r
2ff29212 300 cancelled.\r
301\r
1f6729ff 302 @retval EFI_SUCCESS The token is cancelled.\r
2ff29212 303 @retval EFI_NOT_FOUND The token isn't found on either the\r
1f6729ff 304 transmit/receive queue.\r
2ff29212 305 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.\r
306\r
307**/\r
83cbd279 308EFI_STATUS\r
309Ip4Cancel (\r
310 IN IP4_PROTOCOL *IpInstance,\r
2ff29212 311 IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r
83cbd279 312 );\r
313\r
2ff29212 314/**\r
315 Change the IP4 child's multicast setting. The caller\r
316 should make sure that the parameters is valid.\r
317\r
3e8c18da 318 @param[in] IpInstance The IP4 child to change the setting.\r
319 @param[in] JoinFlag TRUE to join the group, otherwise leave it\r
320 @param[in] GroupAddress The target group address\r
2ff29212 321\r
322 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it\r
323 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r
324 @retval EFI_DEVICE_ERROR Failed to set the group configuraton\r
325 @retval EFI_SUCCESS Successfully updated the group setting.\r
326 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.\r
327\r
328**/\r
83cbd279 329EFI_STATUS\r
330Ip4Groups (\r
331 IN IP4_PROTOCOL *IpInstance,\r
332 IN BOOLEAN JoinFlag,\r
2ff29212 333 IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r
83cbd279 334 );\r
335\r
2ff29212 336/**\r
337 The heart beat timer of IP4 service instance. It times out\r
338 all of its IP4 children's received-but-not-delivered and\r
339 transmitted-but-not-recycle packets, and provides time input\r
340 for its IGMP protocol.\r
341\r
3e8c18da 342 @param[in] Event The IP4 service instance's heart beat timer.\r
343 @param[in] Context The IP4 service instance.\r
2ff29212 344\r
345**/\r
83cbd279 346VOID\r
347EFIAPI\r
348Ip4TimerTicking (\r
349 IN EFI_EVENT Event,\r
350 IN VOID *Context\r
351 );\r
352\r
2ff29212 353/**\r
354 Decrease the life of the transmitted packets. If it is\r
355 decreased to zero, cancel the packet. This function is\r
356 called by Ip4PacketTimerTicking which time out both the\r
357 received-but-not-delivered and transmitted-but-not-recycle\r
358 packets.\r
359\r
3e8c18da 360 @param[in] Map The IP4 child's transmit map.\r
1f6729ff 361 @param[in] Item Current transmitted packet.\r
3e8c18da 362 @param[in] Context Not used.\r
2ff29212 363\r
1f6729ff 364 @retval EFI_SUCCESS Always returns EFI_SUCCESS.\r
2ff29212 365\r
366**/\r
83cbd279 367EFI_STATUS\r
e798cd87 368EFIAPI\r
83cbd279 369Ip4SentPacketTicking (\r
370 IN NET_MAP *Map,\r
371 IN NET_MAP_ITEM *Item,\r
372 IN VOID *Context\r
373 );\r
a1503a32 374\r
375/**\r
376 The callback function for the net buffer which wraps the user's\r
377 transmit token. Although it seems this function is pretty simple,\r
378 there are some subtle things.\r
379 When user requests the IP to transmit a packet by passing it a\r
380 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r
381 is wrapped in an net buffer. the net buffer's Free function is\r
382 set to Ip4FreeTxToken. The Token and token wrap are added to the\r
383 IP child's TxToken map. Then the buffer is passed to Ip4Output for\r
384 transmission. If something error happened before that, the buffer\r
385 is freed, which in turn will free the token wrap. The wrap may\r
386 have been added to the TxToken map or not, and the user's event\r
387 shouldn't be fired because we are still in the EfiIp4Transmit. If\r
388 the buffer has been sent by Ip4Output, it should be removed from\r
389 the TxToken map and user's event signaled. The token wrap and buffer\r
390 are bound together. Check the comments in Ip4Output for information\r
391 about IP fragmentation.\r
392\r
1f6729ff 393 @param[in] Context The token's wrap.\r
a1503a32 394\r
395**/\r
396VOID\r
e798cd87 397EFIAPI\r
a1503a32 398Ip4FreeTxToken (\r
399 IN VOID *Context\r
400 );\r
401\r
705f53a9 402extern EFI_IPSEC2_PROTOCOL *mIpSec;\r
c79de074 403extern BOOLEAN mIpSec2Installed;\r
a1503a32 404\r
83cbd279 405#endif\r