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