]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
MdeModulePkg: Fix default router table and interface missing error
[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
e371cc14
JW
208 BOOLEAN Reconfig;\r
209\r
2c320007
JW
210 //\r
211 // Underlying media present status. \r
212 //\r
213 BOOLEAN MediaPresent;\r
214\r
83cbd279 215 //\r
1f6729ff 216 // IPv4 Configuration II Protocol instance\r
83cbd279 217 //\r
1f6729ff 218 IP4_CONFIG2_INSTANCE Ip4Config2Instance;\r
219\r
220 CHAR16 *MacString;\r
83cbd279 221\r
a1503a32 222 UINT32 MaxPacketSize;\r
223 UINT32 OldMaxPacketSize; ///< The MTU before IPsec enable.\r
c6bc765f 224};\r
83cbd279 225\r
226#define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \\r
227 CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)\r
228\r
229#define IP4_SERVICE_FROM_PROTOCOL(Sb) \\r
230 CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)\r
231\r
1f6729ff 232#define IP4_SERVICE_FROM_CONFIG2_INSTANCE(This) \\r
233 CR (This, IP4_SERVICE, Ip4Config2Instance, IP4_SERVICE_SIGNATURE)\r
234\r
235\r
83cbd279 236#define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)\r
237\r
238extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete;\r
239\r
2ff29212 240/**\r
241 Config the MNP parameter used by IP. The IP driver use one MNP\r
242 child to transmit/receive frames. By default, it configures MNP\r
243 to receive unicast/multicast/broadcast. And it will enable/disable\r
244 the promiscous receive according to whether there is IP child\r
245 enable that or not. If Force is FALSE, it will iterate through\r
246 all the IP children to check whether the promiscuous receive\r
247 setting has been changed. If it hasn't been changed, it won't\r
248 reconfigure the MNP. If Force is TRUE, the MNP is configured no\r
249 matter whether that is changed or not.\r
250\r
3e8c18da 251 @param[in] IpSb The IP4 service instance that is to be changed.\r
252 @param[in] Force Force the configuration or not.\r
2ff29212 253\r
254 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.\r
255 @retval Others Configuration failed.\r
256\r
257**/\r
83cbd279 258EFI_STATUS\r
259Ip4ServiceConfigMnp (\r
260 IN IP4_SERVICE *IpSb,\r
261 IN BOOLEAN Force\r
262 );\r
263\r
2ff29212 264/**\r
265 Intiialize the IP4_PROTOCOL structure to the unconfigured states.\r
266\r
267 @param IpSb The IP4 service instance.\r
268 @param IpInstance The IP4 child instance.\r
269\r
2ff29212 270**/\r
83cbd279 271VOID\r
272Ip4InitProtocol (\r
2ff29212 273 IN IP4_SERVICE *IpSb,\r
274 IN OUT IP4_PROTOCOL *IpInstance\r
83cbd279 275 );\r
276\r
2ff29212 277/**\r
278 Clean up the IP4 child, release all the resources used by it.\r
279\r
3e8c18da 280 @param[in] IpInstance The IP4 child to clean up.\r
2ff29212 281\r
1f6729ff 282 @retval EFI_SUCCESS The IP4 child is cleaned up.\r
283 @retval EFI_DEVICE_ERROR Some resources failed to be released.\r
2ff29212 284\r
285**/\r
83cbd279 286EFI_STATUS\r
287Ip4CleanProtocol (\r
288 IN IP4_PROTOCOL *IpInstance\r
289 );\r
290\r
2ff29212 291/**\r
292 Cancel the user's receive/transmit request.\r
293\r
1f6729ff 294 @param[in] IpInstance The IP4 child.\r
3e8c18da 295 @param[in] Token The token to cancel. If NULL, all token will be\r
2ff29212 296 cancelled.\r
297\r
1f6729ff 298 @retval EFI_SUCCESS The token is cancelled.\r
2ff29212 299 @retval EFI_NOT_FOUND The token isn't found on either the\r
1f6729ff 300 transmit/receive queue.\r
2ff29212 301 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.\r
302\r
303**/\r
83cbd279 304EFI_STATUS\r
305Ip4Cancel (\r
306 IN IP4_PROTOCOL *IpInstance,\r
2ff29212 307 IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r
83cbd279 308 );\r
309\r
2ff29212 310/**\r
311 Change the IP4 child's multicast setting. The caller\r
312 should make sure that the parameters is valid.\r
313\r
3e8c18da 314 @param[in] IpInstance The IP4 child to change the setting.\r
315 @param[in] JoinFlag TRUE to join the group, otherwise leave it\r
316 @param[in] GroupAddress The target group address\r
2ff29212 317\r
318 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it\r
319 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r
320 @retval EFI_DEVICE_ERROR Failed to set the group configuraton\r
321 @retval EFI_SUCCESS Successfully updated the group setting.\r
322 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.\r
323\r
324**/\r
83cbd279 325EFI_STATUS\r
326Ip4Groups (\r
327 IN IP4_PROTOCOL *IpInstance,\r
328 IN BOOLEAN JoinFlag,\r
2ff29212 329 IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r
83cbd279 330 );\r
331\r
2ff29212 332/**\r
333 The heart beat timer of IP4 service instance. It times out\r
334 all of its IP4 children's received-but-not-delivered and\r
335 transmitted-but-not-recycle packets, and provides time input\r
336 for its IGMP protocol.\r
337\r
3e8c18da 338 @param[in] Event The IP4 service instance's heart beat timer.\r
339 @param[in] Context The IP4 service instance.\r
2ff29212 340\r
341**/\r
83cbd279 342VOID\r
343EFIAPI\r
344Ip4TimerTicking (\r
345 IN EFI_EVENT Event,\r
346 IN VOID *Context\r
347 );\r
348\r
2ff29212 349/**\r
350 Decrease the life of the transmitted packets. If it is\r
351 decreased to zero, cancel the packet. This function is\r
352 called by Ip4PacketTimerTicking which time out both the\r
353 received-but-not-delivered and transmitted-but-not-recycle\r
354 packets.\r
355\r
3e8c18da 356 @param[in] Map The IP4 child's transmit map.\r
1f6729ff 357 @param[in] Item Current transmitted packet.\r
3e8c18da 358 @param[in] Context Not used.\r
2ff29212 359\r
1f6729ff 360 @retval EFI_SUCCESS Always returns EFI_SUCCESS.\r
2ff29212 361\r
362**/\r
83cbd279 363EFI_STATUS\r
e798cd87 364EFIAPI\r
83cbd279 365Ip4SentPacketTicking (\r
366 IN NET_MAP *Map,\r
367 IN NET_MAP_ITEM *Item,\r
368 IN VOID *Context\r
369 );\r
a1503a32 370\r
371/**\r
372 The callback function for the net buffer which wraps the user's\r
373 transmit token. Although it seems this function is pretty simple,\r
374 there are some subtle things.\r
375 When user requests the IP to transmit a packet by passing it a\r
376 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r
377 is wrapped in an net buffer. the net buffer's Free function is\r
378 set to Ip4FreeTxToken. The Token and token wrap are added to the\r
379 IP child's TxToken map. Then the buffer is passed to Ip4Output for\r
380 transmission. If something error happened before that, the buffer\r
381 is freed, which in turn will free the token wrap. The wrap may\r
382 have been added to the TxToken map or not, and the user's event\r
383 shouldn't be fired because we are still in the EfiIp4Transmit. If\r
384 the buffer has been sent by Ip4Output, it should be removed from\r
385 the TxToken map and user's event signaled. The token wrap and buffer\r
386 are bound together. Check the comments in Ip4Output for information\r
387 about IP fragmentation.\r
388\r
1f6729ff 389 @param[in] Context The token's wrap.\r
a1503a32 390\r
391**/\r
392VOID\r
e798cd87 393EFIAPI\r
a1503a32 394Ip4FreeTxToken (\r
395 IN VOID *Context\r
396 );\r
397\r
705f53a9 398extern EFI_IPSEC2_PROTOCOL *mIpSec;\r
a1503a32 399\r
83cbd279 400#endif\r