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