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