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