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