2 Ip4 internal functions and type defintions.
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef __EFI_IP4_IMPL_H__
18 #define __EFI_IP4_IMPL_H__
22 #include <Protocol/IpSec.h>
23 #include <Protocol/Ip4.h>
24 #include <Protocol/Ip4Config2.h>
25 #include <Protocol/Arp.h>
26 #include <Protocol/ManagedNetwork.h>
27 #include <Protocol/Dhcp4.h>
28 #include <Protocol/HiiConfigRouting.h>
29 #include <Protocol/HiiConfigAccess.h>
31 #include <IndustryStandard/Dhcp.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiRuntimeServicesTableLib.h>
35 #include <Library/UefiDriverEntryPoint.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/BaseLib.h>
38 #include <Library/UefiLib.h>
39 #include <Library/NetLib.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/DpcLib.h>
43 #include <Library/PrintLib.h>
44 #include <Library/DevicePathLib.h>
45 #include <Library/HiiLib.h>
46 #include <Library/UefiHiiServicesLib.h>
48 #include "Ip4Common.h"
49 #include "Ip4Driver.h"
52 #include "Ip4Option.h"
56 #include "Ip4Output.h"
57 #include "Ip4Config2Impl.h"
58 #include "Ip4Config2Nv.h"
59 #include "Ip4NvData.h"
61 #define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')
62 #define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')
65 // The state of IP4 protocol. It starts from UNCONFIGED. if it is
66 // successfully configured, it goes to CONFIGED. if configure NULL
67 // is called, it becomes UNCONFIGED again.
69 #define IP4_STATE_UNCONFIGED 0
70 #define IP4_STATE_CONFIGED 1
73 // The state of IP4 service. It starts from UNSTARTED. It transits
74 // to STARTED if autoconfigure is started. If default address is
75 // configured, it becomes CONFIGED. and if partly destroyed, it goes
78 #define IP4_SERVICE_UNSTARTED 0
79 #define IP4_SERVICE_STARTED 1
80 #define IP4_SERVICE_CONFIGED 2
81 #define IP4_SERVICE_DESTROY 3
85 /// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.
86 /// The user's data is kept in the Packet. When fragment is
87 /// needed, each fragment of the Packet has a reference to the
88 /// Packet, no data is actually copied. The Packet will be
89 /// released when all the fragments of it have been recycled by
90 /// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and
91 /// user's event signalled.
94 IP4_PROTOCOL
*IpInstance
;
95 EFI_IP4_COMPLETION_TOKEN
*Token
;
96 EFI_EVENT IpSecRecycleSignal
;
103 /// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet
104 /// will be released after it has been processed by the receiver. Upon then,
105 /// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled
106 /// to notice IPsec to free the resources.
109 EFI_EVENT IpSecRecycleSignal
;
114 /// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the
115 /// upper layers. The received packet is kept in the Packet.
116 /// The Packet itself may be constructured from some fragments.
117 /// All the fragments of the Packet is organized by a
118 /// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by
119 /// the upper layer, the assemble entry and its associated
120 /// fragments will be freed at last.
124 IP4_PROTOCOL
*IpInstance
;
126 EFI_IP4_RECEIVE_DATA RxData
;
130 struct _IP4_PROTOCOL
{
133 EFI_IP4_PROTOCOL Ip4Proto
;
139 IP4_SERVICE
*Service
;
140 LIST_ENTRY Link
; // Link to all the IP protocol from the service
143 // User's transmit/receive tokens, and received/deliverd packets
146 NET_MAP TxTokens
; // map between (User's Token, IP4_TXTOKE_WRAP)
147 LIST_ENTRY Received
; // Received but not delivered packet
148 LIST_ENTRY Delivered
; // Delivered and to be recycled packets
149 EFI_LOCK RecycleLock
;
152 // Instance's address and route tables. There are two route tables.
153 // RouteTable is used by the IP4 driver to route packet. EfiRouteTable
154 // is used to communicate the current route info to the upper layer.
156 IP4_INTERFACE
*Interface
;
157 LIST_ENTRY AddrLink
; // Ip instances with the same IP address.
158 IP4_ROUTE_TABLE
*RouteTable
;
160 EFI_IP4_ROUTE_TABLE
*EfiRouteTable
;
161 UINT32 EfiRouteCount
;
164 // IGMP data for this instance
166 IP4_ADDR
*Groups
; // stored in network byte order
169 EFI_IP4_CONFIG_DATA ConfigData
;
173 struct _IP4_SERVICE
{
175 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
179 // List of all the IP instances and interfaces, and default
180 // interface and route table and caches.
185 LIST_ENTRY Interfaces
;
187 IP4_INTERFACE
*DefaultInterface
;
188 IP4_ROUTE_TABLE
*DefaultRouteTable
;
191 // Ip reassemble utilities, and IGMP data
193 IP4_ASSEMBLE_TABLE Assemble
;
194 IGMP_SERVICE_DATA IgmpCtrl
;
197 // Low level protocol used by this service instance
200 EFI_HANDLE Controller
;
202 EFI_HANDLE MnpChildHandle
;
203 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
205 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData
;
206 EFI_SIMPLE_NETWORK_MODE SnpMode
;
209 EFI_EVENT ReconfigCheckTimer
;
210 EFI_EVENT ReconfigEvent
;
215 // Underlying media present status.
217 BOOLEAN MediaPresent
;
220 // IPv4 Configuration II Protocol instance
222 IP4_CONFIG2_INSTANCE Ip4Config2Instance
;
226 UINT32 MaxPacketSize
;
227 UINT32 OldMaxPacketSize
; ///< The MTU before IPsec enable.
230 #define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \
231 CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)
233 #define IP4_SERVICE_FROM_PROTOCOL(Sb) \
234 CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)
236 #define IP4_SERVICE_FROM_CONFIG2_INSTANCE(This) \
237 CR (This, IP4_SERVICE, Ip4Config2Instance, IP4_SERVICE_SIGNATURE)
240 #define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)
242 extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete
;
245 Config the MNP parameter used by IP. The IP driver use one MNP
246 child to transmit/receive frames. By default, it configures MNP
247 to receive unicast/multicast/broadcast. And it will enable/disable
248 the promiscous receive according to whether there is IP child
249 enable that or not. If Force is FALSE, it will iterate through
250 all the IP children to check whether the promiscuous receive
251 setting has been changed. If it hasn't been changed, it won't
252 reconfigure the MNP. If Force is TRUE, the MNP is configured no
253 matter whether that is changed or not.
255 @param[in] IpSb The IP4 service instance that is to be changed.
256 @param[in] Force Force the configuration or not.
258 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
259 @retval Others Configuration failed.
263 Ip4ServiceConfigMnp (
264 IN IP4_SERVICE
*IpSb
,
269 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
271 @param IpSb The IP4 service instance.
272 @param IpInstance The IP4 child instance.
277 IN IP4_SERVICE
*IpSb
,
278 IN OUT IP4_PROTOCOL
*IpInstance
282 Clean up the IP4 child, release all the resources used by it.
284 @param[in] IpInstance The IP4 child to clean up.
286 @retval EFI_SUCCESS The IP4 child is cleaned up.
287 @retval EFI_DEVICE_ERROR Some resources failed to be released.
292 IN IP4_PROTOCOL
*IpInstance
296 Cancel the user's receive/transmit request.
298 @param[in] IpInstance The IP4 child.
299 @param[in] Token The token to cancel. If NULL, all token will be
302 @retval EFI_SUCCESS The token is cancelled.
303 @retval EFI_NOT_FOUND The token isn't found on either the
304 transmit/receive queue.
305 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
310 IN IP4_PROTOCOL
*IpInstance
,
311 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
315 Change the IP4 child's multicast setting. The caller
316 should make sure that the parameters is valid.
318 @param[in] IpInstance The IP4 child to change the setting.
319 @param[in] JoinFlag TRUE to join the group, otherwise leave it
320 @param[in] GroupAddress The target group address
322 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
323 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
324 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
325 @retval EFI_SUCCESS Successfully updated the group setting.
326 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
331 IN IP4_PROTOCOL
*IpInstance
,
333 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
337 This heart beat timer of IP4 service instance times out all of its IP4 children's
338 received-but-not-delivered and transmitted-but-not-recycle packets, and provides
339 time input for its IGMP protocol.
341 @param[in] Event The IP4 service instance's heart beat timer.
342 @param[in] Context The IP4 service instance.
353 This dedicated timer is used to poll underlying network media status. In case
354 of cable swap or wireless network switch, a new round auto configuration will
355 be initiated. The timer will signal the IP4 to run DHCP configuration again.
356 IP4 driver will free old IP address related resource, such as route table and
357 Interface, then initiate a DHCP process to acquire new IP, eventually create
358 route table for new IP address.
360 @param[in] Event The IP4 service instance's heart beat timer.
361 @param[in] Context The IP4 service instance.
366 Ip4TimerReconfigChecking (
372 Decrease the life of the transmitted packets. If it is
373 decreased to zero, cancel the packet. This function is
374 called by Ip4PacketTimerTicking which time out both the
375 received-but-not-delivered and transmitted-but-not-recycle
378 @param[in] Map The IP4 child's transmit map.
379 @param[in] Item Current transmitted packet.
380 @param[in] Context Not used.
382 @retval EFI_SUCCESS Always returns EFI_SUCCESS.
387 Ip4SentPacketTicking (
389 IN NET_MAP_ITEM
*Item
,
394 The callback function for the net buffer which wraps the user's
395 transmit token. Although it seems this function is pretty simple,
396 there are some subtle things.
397 When user requests the IP to transmit a packet by passing it a
398 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
399 is wrapped in an net buffer. the net buffer's Free function is
400 set to Ip4FreeTxToken. The Token and token wrap are added to the
401 IP child's TxToken map. Then the buffer is passed to Ip4Output for
402 transmission. If something error happened before that, the buffer
403 is freed, which in turn will free the token wrap. The wrap may
404 have been added to the TxToken map or not, and the user's event
405 shouldn't be fired because we are still in the EfiIp4Transmit. If
406 the buffer has been sent by Ip4Output, it should be removed from
407 the TxToken map and user's event signaled. The token wrap and buffer
408 are bound together. Check the comments in Ip4Output for information
409 about IP fragmentation.
411 @param[in] Context The token's wrap.
420 extern EFI_IPSEC2_PROTOCOL
*mIpSec
;
421 extern BOOLEAN mIpSec2Installed
;