]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
MdeModulePkg: IP4 should re-initiate a DHCP if it detects network reconnection
[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
1f6729ff 4Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
83cbd279 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
83cbd279 13**/\r
14\r
15#ifndef __EFI_IP4_IMPL_H__\r
16#define __EFI_IP4_IMPL_H__\r
17\r
2517435c 18#include <Uefi.h>\r
772db4bb 19\r
a1503a32 20#include <Protocol/IpSec.h>\r
5f778b1f 21#include <Protocol/Ip4.h>\r
1f6729ff 22#include <Protocol/Ip4Config2.h>\r
772db4bb 23#include <Protocol/Arp.h>\r
24#include <Protocol/ManagedNetwork.h>\r
1f6729ff 25#include <Protocol/Dhcp4.h>\r
26#include <Protocol/HiiConfigRouting.h>\r
27#include <Protocol/HiiConfigAccess.h>\r
772db4bb 28\r
29#include <Library/DebugLib.h>\r
30#include <Library/UefiRuntimeServicesTableLib.h>\r
31#include <Library/UefiDriverEntryPoint.h>\r
32#include <Library/UefiBootServicesTableLib.h>\r
33#include <Library/BaseLib.h>\r
83cbd279 34#include <Library/UefiLib.h>\r
35#include <Library/NetLib.h>\r
36#include <Library/BaseMemoryLib.h>\r
37#include <Library/MemoryAllocationLib.h>\r
d8d26fb2 38#include <Library/DpcLib.h>\r
216f7970 39#include <Library/PrintLib.h>\r
1f6729ff 40#include <Library/DevicePathLib.h>\r
41#include <Library/HiiLib.h>\r
42#include <Library/UefiHiiServicesLib.h>\r
83cbd279 43\r
44#include "Ip4Common.h"\r
45#include "Ip4Driver.h"\r
46#include "Ip4If.h"\r
47#include "Ip4Icmp.h"\r
48#include "Ip4Option.h"\r
49#include "Ip4Igmp.h"\r
50#include "Ip4Route.h"\r
51#include "Ip4Input.h"\r
52#include "Ip4Output.h"\r
1f6729ff 53#include "Ip4Config2Impl.h"\r
54#include "Ip4Config2Nv.h"\r
55#include "Ip4NvData.h"\r
83cbd279 56\r
f6b7393c 57#define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')\r
58#define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')\r
c6bc765f 59\r
f6b7393c 60//\r
61// The state of IP4 protocol. It starts from UNCONFIGED. if it is\r
62// successfully configured, it goes to CONFIGED. if configure NULL\r
75dce340 63// is called, it becomes UNCONFIGED again. If (partly) destroyed, it\r
64// becomes DESTROY.\r
f6b7393c 65//\r
66#define IP4_STATE_UNCONFIGED 0\r
67#define IP4_STATE_CONFIGED 1\r
75dce340 68#define IP4_STATE_DESTROY 2\r
c6bc765f 69\r
f6b7393c 70//\r
71// The state of IP4 service. It starts from UNSTARTED. It transits\r
72// to STARTED if autoconfigure is started. If default address is\r
75dce340 73// configured, it becomes CONFIGED. and if partly destroyed, it goes\r
74// to DESTROY.\r
f6b7393c 75//\r
76#define IP4_SERVICE_UNSTARTED 0\r
77#define IP4_SERVICE_STARTED 1\r
78#define IP4_SERVICE_CONFIGED 2\r
75dce340 79#define IP4_SERVICE_DESTROY 3\r
83cbd279 80\r
83cbd279 81\r
96e1079f 82///\r
83/// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.\r
84/// The user's data is kept in the Packet. When fragment is\r
85/// needed, each fragment of the Packet has a reference to the\r
86/// Packet, no data is actually copied. The Packet will be\r
87/// released when all the fragments of it have been recycled by\r
88/// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and\r
89/// user's event signalled.\r
90///\r
83cbd279 91typedef struct {\r
92 IP4_PROTOCOL *IpInstance;\r
93 EFI_IP4_COMPLETION_TOKEN *Token;\r
a1503a32 94 EFI_EVENT IpSecRecycleSignal;\r
83cbd279 95 NET_BUF *Packet;\r
96 BOOLEAN Sent;\r
97 INTN Life;\r
98} IP4_TXTOKEN_WRAP;\r
99\r
a1503a32 100///\r
101/// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet\r
102/// will be released after it has been processed by the receiver. Upon then,\r
103/// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled\r
104/// to notice IPsec to free the resources.\r
105///\r
106typedef struct {\r
107 EFI_EVENT IpSecRecycleSignal;\r
108 NET_BUF *Packet;\r
109} IP4_IPSEC_WRAP;\r
110\r
96e1079f 111///\r
112/// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the\r
113/// upper layers. The received packet is kept in the Packet.\r
114/// The Packet itself may be constructured from some fragments.\r
115/// All the fragments of the Packet is organized by a\r
116/// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by\r
117/// the upper layer, the assemble entry and its associated\r
118/// fragments will be freed at last.\r
119///\r
83cbd279 120typedef struct {\r
e48e37fc 121 LIST_ENTRY Link;\r
83cbd279 122 IP4_PROTOCOL *IpInstance;\r
123 NET_BUF *Packet;\r
124 EFI_IP4_RECEIVE_DATA RxData;\r
125} IP4_RXDATA_WRAP;\r
126\r
c6bc765f 127\r
128struct _IP4_PROTOCOL {\r
83cbd279 129 UINT32 Signature;\r
130\r
131 EFI_IP4_PROTOCOL Ip4Proto;\r
132 EFI_HANDLE Handle;\r
133 INTN State;\r
134\r
135 IP4_SERVICE *Service;\r
a1503a32 136 LIST_ENTRY Link; // Link to all the IP protocol from the service\r
83cbd279 137\r
138 //\r
139 // User's transmit/receive tokens, and received/deliverd packets\r
140 //\r
141 NET_MAP RxTokens;\r
142 NET_MAP TxTokens; // map between (User's Token, IP4_TXTOKE_WRAP)\r
e48e37fc 143 LIST_ENTRY Received; // Received but not delivered packet\r
144 LIST_ENTRY Delivered; // Delivered and to be recycled packets\r
83cbd279 145 EFI_LOCK RecycleLock;\r
146\r
147 //\r
148 // Instance's address and route tables. There are two route tables.\r
149 // RouteTable is used by the IP4 driver to route packet. EfiRouteTable\r
150 // is used to communicate the current route info to the upper layer.\r
151 //\r
152 IP4_INTERFACE *Interface;\r
e48e37fc 153 LIST_ENTRY AddrLink; // Ip instances with the same IP address.\r
83cbd279 154 IP4_ROUTE_TABLE *RouteTable;\r
155\r
156 EFI_IP4_ROUTE_TABLE *EfiRouteTable;\r
157 UINT32 EfiRouteCount;\r
158\r
159 //\r
160 // IGMP data for this instance\r
161 //\r
a1503a32 162 IP4_ADDR *Groups; // stored in network byte order\r
83cbd279 163 UINT32 GroupCount;\r
164\r
165 EFI_IP4_CONFIG_DATA ConfigData;\r
166\r
c6bc765f 167};\r
83cbd279 168\r
c6bc765f 169struct _IP4_SERVICE {\r
83cbd279 170 UINT32 Signature;\r
171 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
172 INTN State;\r
83cbd279 173\r
174 //\r
175 // List of all the IP instances and interfaces, and default\r
176 // interface and route table and caches.\r
177 //\r
178 UINTN NumChildren;\r
e48e37fc 179 LIST_ENTRY Children;\r
83cbd279 180\r
e48e37fc 181 LIST_ENTRY Interfaces;\r
83cbd279 182\r
183 IP4_INTERFACE *DefaultInterface;\r
184 IP4_ROUTE_TABLE *DefaultRouteTable;\r
185\r
186 //\r
187 // Ip reassemble utilities, and IGMP data\r
188 //\r
189 IP4_ASSEMBLE_TABLE Assemble;\r
190 IGMP_SERVICE_DATA IgmpCtrl;\r
191\r
192 //\r
193 // Low level protocol used by this service instance\r
194 //\r
195 EFI_HANDLE Image;\r
196 EFI_HANDLE Controller;\r
197\r
198 EFI_HANDLE MnpChildHandle;\r
199 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
200\r
201 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;\r
202 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
203\r
204 EFI_EVENT Timer;\r
205\r
2c320007
JW
206 EFI_EVENT ReconfigEvent;\r
207\r
208 //\r
209 // Underlying media present status. \r
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
331 The heart beat timer of IP4 service instance. It times out\r
332 all of its IP4 children's received-but-not-delivered and\r
333 transmitted-but-not-recycle packets, and provides time input\r
334 for its IGMP protocol.\r
335\r
3e8c18da 336 @param[in] Event The IP4 service instance's heart beat timer.\r
337 @param[in] Context The IP4 service instance.\r
2ff29212 338\r
339**/\r
83cbd279 340VOID\r
341EFIAPI\r
342Ip4TimerTicking (\r
343 IN EFI_EVENT Event,\r
344 IN VOID *Context\r
345 );\r
346\r
2ff29212 347/**\r
348 Decrease the life of the transmitted packets. If it is\r
349 decreased to zero, cancel the packet. This function is\r
350 called by Ip4PacketTimerTicking which time out both the\r
351 received-but-not-delivered and transmitted-but-not-recycle\r
352 packets.\r
353\r
3e8c18da 354 @param[in] Map The IP4 child's transmit map.\r
1f6729ff 355 @param[in] Item Current transmitted packet.\r
3e8c18da 356 @param[in] Context Not used.\r
2ff29212 357\r
1f6729ff 358 @retval EFI_SUCCESS Always returns EFI_SUCCESS.\r
2ff29212 359\r
360**/\r
83cbd279 361EFI_STATUS\r
e798cd87 362EFIAPI\r
83cbd279 363Ip4SentPacketTicking (\r
364 IN NET_MAP *Map,\r
365 IN NET_MAP_ITEM *Item,\r
366 IN VOID *Context\r
367 );\r
a1503a32 368\r
369/**\r
370 The callback function for the net buffer which wraps the user's\r
371 transmit token. Although it seems this function is pretty simple,\r
372 there are some subtle things.\r
373 When user requests the IP to transmit a packet by passing it a\r
374 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r
375 is wrapped in an net buffer. the net buffer's Free function is\r
376 set to Ip4FreeTxToken. The Token and token wrap are added to the\r
377 IP child's TxToken map. Then the buffer is passed to Ip4Output for\r
378 transmission. If something error happened before that, the buffer\r
379 is freed, which in turn will free the token wrap. The wrap may\r
380 have been added to the TxToken map or not, and the user's event\r
381 shouldn't be fired because we are still in the EfiIp4Transmit. If\r
382 the buffer has been sent by Ip4Output, it should be removed from\r
383 the TxToken map and user's event signaled. The token wrap and buffer\r
384 are bound together. Check the comments in Ip4Output for information\r
385 about IP fragmentation.\r
386\r
1f6729ff 387 @param[in] Context The token's wrap.\r
a1503a32 388\r
389**/\r
390VOID\r
e798cd87 391EFIAPI\r
a1503a32 392Ip4FreeTxToken (\r
393 IN VOID *Context\r
394 );\r
395\r
705f53a9 396extern EFI_IPSEC2_PROTOCOL *mIpSec;\r
a1503a32 397\r
83cbd279 398#endif\r