2 Ip4 internal functions and type defintions.
4 Copyright (c) 2005 - 2014, 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
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.
15 #ifndef __EFI_IP4_IMPL_H__
16 #define __EFI_IP4_IMPL_H__
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>
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 #include <Library/PrintLib.h>
38 #include "Ip4Common.h"
39 #include "Ip4Driver.h"
42 #include "Ip4Option.h"
46 #include "Ip4Output.h"
48 #define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')
49 #define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')
52 // The state of IP4 protocol. It starts from UNCONFIGED. if it is
53 // successfully configured, it goes to CONFIGED. if configure NULL
54 // is called, it becomes UNCONFIGED again. If (partly) destroyed, it
57 #define IP4_STATE_UNCONFIGED 0
58 #define IP4_STATE_CONFIGED 1
59 #define IP4_STATE_DESTROY 2
62 // The state of IP4 service. It starts from UNSTARTED. It transits
63 // to STARTED if autoconfigure is started. If default address is
64 // configured, it becomes CONFIGED. and if partly destroyed, it goes
67 #define IP4_SERVICE_UNSTARTED 0
68 #define IP4_SERVICE_STARTED 1
69 #define IP4_SERVICE_CONFIGED 2
70 #define IP4_SERVICE_DESTROY 3
74 /// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.
75 /// The user's data is kept in the Packet. When fragment is
76 /// needed, each fragment of the Packet has a reference to the
77 /// Packet, no data is actually copied. The Packet will be
78 /// released when all the fragments of it have been recycled by
79 /// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and
80 /// user's event signalled.
83 IP4_PROTOCOL
*IpInstance
;
84 EFI_IP4_COMPLETION_TOKEN
*Token
;
85 EFI_EVENT IpSecRecycleSignal
;
92 /// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet
93 /// will be released after it has been processed by the receiver. Upon then,
94 /// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled
95 /// to notice IPsec to free the resources.
98 EFI_EVENT IpSecRecycleSignal
;
103 /// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the
104 /// upper layers. The received packet is kept in the Packet.
105 /// The Packet itself may be constructured from some fragments.
106 /// All the fragments of the Packet is organized by a
107 /// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by
108 /// the upper layer, the assemble entry and its associated
109 /// fragments will be freed at last.
113 IP4_PROTOCOL
*IpInstance
;
115 EFI_IP4_RECEIVE_DATA RxData
;
119 struct _IP4_PROTOCOL
{
122 EFI_IP4_PROTOCOL Ip4Proto
;
126 IP4_SERVICE
*Service
;
127 LIST_ENTRY Link
; // Link to all the IP protocol from the service
130 // User's transmit/receive tokens, and received/deliverd packets
133 NET_MAP TxTokens
; // map between (User's Token, IP4_TXTOKE_WRAP)
134 LIST_ENTRY Received
; // Received but not delivered packet
135 LIST_ENTRY Delivered
; // Delivered and to be recycled packets
136 EFI_LOCK RecycleLock
;
139 // Instance's address and route tables. There are two route tables.
140 // RouteTable is used by the IP4 driver to route packet. EfiRouteTable
141 // is used to communicate the current route info to the upper layer.
143 IP4_INTERFACE
*Interface
;
144 LIST_ENTRY AddrLink
; // Ip instances with the same IP address.
145 IP4_ROUTE_TABLE
*RouteTable
;
147 EFI_IP4_ROUTE_TABLE
*EfiRouteTable
;
148 UINT32 EfiRouteCount
;
151 // IGMP data for this instance
153 IP4_ADDR
*Groups
; // stored in network byte order
156 EFI_IP4_CONFIG_DATA ConfigData
;
160 struct _IP4_SERVICE
{
162 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
166 // List of all the IP instances and interfaces, and default
167 // interface and route table and caches.
172 LIST_ENTRY Interfaces
;
174 IP4_INTERFACE
*DefaultInterface
;
175 IP4_ROUTE_TABLE
*DefaultRouteTable
;
178 // Ip reassemble utilities, and IGMP data
180 IP4_ASSEMBLE_TABLE Assemble
;
181 IGMP_SERVICE_DATA IgmpCtrl
;
184 // Low level protocol used by this service instance
187 EFI_HANDLE Controller
;
189 EFI_HANDLE MnpChildHandle
;
190 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
192 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData
;
193 EFI_SIMPLE_NETWORK_MODE SnpMode
;
198 // Auto configure staff
200 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
202 EFI_EVENT ReconfigEvent
;
203 EFI_EVENT ActiveEvent
;
205 UINT32 MaxPacketSize
;
206 UINT32 OldMaxPacketSize
; ///< The MTU before IPsec enable.
209 #define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \
210 CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)
212 #define IP4_SERVICE_FROM_PROTOCOL(Sb) \
213 CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)
215 #define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)
217 extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete
;
220 Config the MNP parameter used by IP. The IP driver use one MNP
221 child to transmit/receive frames. By default, it configures MNP
222 to receive unicast/multicast/broadcast. And it will enable/disable
223 the promiscous receive according to whether there is IP child
224 enable that or not. If Force is FALSE, it will iterate through
225 all the IP children to check whether the promiscuous receive
226 setting has been changed. If it hasn't been changed, it won't
227 reconfigure the MNP. If Force is TRUE, the MNP is configured no
228 matter whether that is changed or not.
230 @param[in] IpSb The IP4 service instance that is to be changed.
231 @param[in] Force Force the configuration or not.
233 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
234 @retval Others Configuration failed.
238 Ip4ServiceConfigMnp (
239 IN IP4_SERVICE
*IpSb
,
244 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
246 @param IpSb The IP4 service instance.
247 @param IpInstance The IP4 child instance.
252 IN IP4_SERVICE
*IpSb
,
253 IN OUT IP4_PROTOCOL
*IpInstance
257 Clean up the IP4 child, release all the resources used by it.
259 @param[in] IpInstance The IP4 child to clean up.
261 @retval EFI_SUCCESS The IP4 child is cleaned up
262 @retval EFI_DEVICE_ERROR Some resources failed to be released
267 IN IP4_PROTOCOL
*IpInstance
271 Cancel the user's receive/transmit request.
273 @param[in] IpInstance The IP4 child
274 @param[in] Token The token to cancel. If NULL, all token will be
277 @retval EFI_SUCCESS The token is cancelled
278 @retval EFI_NOT_FOUND The token isn't found on either the
279 transmit/receive queue
280 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
285 IN IP4_PROTOCOL
*IpInstance
,
286 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
290 Change the IP4 child's multicast setting. The caller
291 should make sure that the parameters is valid.
293 @param[in] IpInstance The IP4 child to change the setting.
294 @param[in] JoinFlag TRUE to join the group, otherwise leave it
295 @param[in] GroupAddress The target group address
297 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
298 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
299 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
300 @retval EFI_SUCCESS Successfully updated the group setting.
301 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
306 IN IP4_PROTOCOL
*IpInstance
,
308 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
312 The heart beat timer of IP4 service instance. It times out
313 all of its IP4 children's received-but-not-delivered and
314 transmitted-but-not-recycle packets, and provides time input
315 for its IGMP protocol.
317 @param[in] Event The IP4 service instance's heart beat timer.
318 @param[in] Context The IP4 service instance.
329 Decrease the life of the transmitted packets. If it is
330 decreased to zero, cancel the packet. This function is
331 called by Ip4PacketTimerTicking which time out both the
332 received-but-not-delivered and transmitted-but-not-recycle
335 @param[in] Map The IP4 child's transmit map.
336 @param[in] Item Current transmitted packet
337 @param[in] Context Not used.
339 @retval EFI_SUCCESS Always returns EFI_SUCCESS
344 Ip4SentPacketTicking (
346 IN NET_MAP_ITEM
*Item
,
351 The callback function for the net buffer which wraps the user's
352 transmit token. Although it seems this function is pretty simple,
353 there are some subtle things.
354 When user requests the IP to transmit a packet by passing it a
355 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
356 is wrapped in an net buffer. the net buffer's Free function is
357 set to Ip4FreeTxToken. The Token and token wrap are added to the
358 IP child's TxToken map. Then the buffer is passed to Ip4Output for
359 transmission. If something error happened before that, the buffer
360 is freed, which in turn will free the token wrap. The wrap may
361 have been added to the TxToken map or not, and the user's event
362 shouldn't be fired because we are still in the EfiIp4Transmit. If
363 the buffer has been sent by Ip4Output, it should be removed from
364 the TxToken map and user's event signaled. The token wrap and buffer
365 are bound together. Check the comments in Ip4Output for information
366 about IP fragmentation.
368 @param[in] Context The token's wrap
377 extern EFI_IPSEC2_PROTOCOL
*mIpSec
;