2 This library provides IpIo layer upon EFI IP4 Protocol.
4 Copyright (c) 2005 - 2008, Intel Corporation
5 All rights reserved. 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.
18 #include <Protocol/Ip4.h>
19 #include <Library/IpIoLib.h>
20 #include <Library/NetLib.h>
23 // type and code define for ICMP protocol error got
26 #define ICMP_TYPE_UNREACH 3
27 #define ICMP_TYPE_TIMXCEED 11
28 #define ICMP_TYPE_PARAMPROB 12
29 #define ICMP_TYPE_SOURCEQUENCH 4
31 #define ICMP_CODE_UNREACH_NET 0
32 #define ICMP_CODE_UNREACH_HOST 1
33 #define ICMP_CODE_UNREACH_PROTOCOL 2
34 #define ICMP_CODE_UNREACH_PORT 3
35 #define ICMP_CODE_UNREACH_NEEDFRAG 4
36 #define ICMP_CODE_UNREACH_SRCFAIL 5
37 #define ICMP_CODE_UNREACH_NET_UNKNOWN 6
38 #define ICMP_CODE_UNREACH_HOST_UNKNOWN 7
39 #define ICMP_CODE_UNREACH_ISOLATED 8
40 #define ICMP_CODE_UNREACH_NET_PROHIB 9
41 #define ICMP_CODE_UNREACH_HOST_PROHIB 10
42 #define ICMP_CODE_UNREACH_TOSNET 11
43 #define ICMP_CODE_UNREACH_TOSHOST 12
46 // this error will be delivered to the
47 // listening transportation layer protocol
51 ICMP_ERR_UNREACH_NET
= 0,
52 ICMP_ERR_UNREACH_HOST
,
53 ICMP_ERR_UNREACH_PROTOCOL
,
54 ICMP_ERR_UNREACH_PORT
,
56 ICMP_ERR_UNREACH_SRCFAIL
,
57 ICMP_ERR_TIMXCEED_INTRANS
,
58 ICMP_ERR_TIMXCEED_REASS
,
63 typedef struct _ICMP_ERROR_INFO
{
68 #define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)
70 extern EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData
;
72 typedef struct _EFI_NET_SESSION_DATA
{
75 EFI_IP4_HEADER
*IpHdr
;
76 } EFI_NET_SESSION_DATA
;
81 IN EFI_STATUS Status
, // rcvd pkt result
82 IN ICMP_ERROR IcmpErr
, // if Status == EFI_ICMP_ERROR, this
83 // field is valid for user
84 IN EFI_NET_SESSION_DATA
*NetSession
, // the communication point
85 IN NET_BUF
*Pkt
, // packet received
86 IN VOID
*Context
// the Context provided by user for recive data
92 IN EFI_STATUS Status
, // sent pkt result
93 IN VOID
*Context
, // the context provided by user for sending data
94 IN VOID
*Sender
, // the sender to be notified
95 IN VOID
*NotifyData
// sent pkt related data to notify
98 typedef struct _IP_IO
{
101 // the node used to link this IpIo to the active IpIo list.
105 // the list used to maintain the IP instance for different sending purpose.
110 // the ip instance consumed by this IP IO
112 EFI_HANDLE Controller
;
114 EFI_HANDLE ChildHandle
;
115 EFI_IP4_PROTOCOL
*Ip
;
116 BOOLEAN IsConfigured
;
119 // some ip config data can be changed
124 // token and event used to get data from IP
126 EFI_IP4_COMPLETION_TOKEN RcvToken
;
129 // list entry used to link the token passed to IP_IO
131 LIST_ENTRY PendingSndList
;
134 // User interface used to get notify from IP_IO
138 PKT_RCVD_NOTIFY PktRcvdNotify
;
139 PKT_SENT_NOTIFY PktSentNotify
;
142 typedef struct _IP_IO_OPEN_DATA
{
143 EFI_IP4_CONFIG_DATA IpConfigData
;
146 PKT_RCVD_NOTIFY PktRcvdNotify
;
147 PKT_SENT_NOTIFY PktSentNotify
;
150 typedef struct _IP_IO_SEND_ENTRY
{
155 EFI_IP4_PROTOCOL
*Ip
;
157 EFI_IP4_COMPLETION_TOKEN
*SndToken
;
160 typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE
;
162 typedef struct _IP_IO_IP_INFO
{
166 EFI_HANDLE ChildHandle
;
167 EFI_IP4_PROTOCOL
*Ip
;
168 EFI_IP4_COMPLETION_TOKEN DummyRcvToken
;
173 Create a new IP_IO instance.
175 @param Image The image handle of an IP_IO consumer protocol.
176 @param Controller The controller handle of an IP_IO consumer protocol
179 @return Pointer to a newly created IP_IO instance.
186 IN EFI_HANDLE Controller
190 Destroy an IP_IO instance.
192 @param IpIo Pointer to the IP_IO instance that needs to
195 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
196 @retval other Error condition occurred.
206 Stop an IP_IO instance.
208 @param IpIo Pointer to the IP_IO instance that needs to stop.
210 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
211 @retval other Error condition occurred.
221 Open an IP_IO instance for use.
223 @param IpIo Pointer to an IP_IO instance that needs to open.
224 @param OpenData The configuration data for the IP_IO instance.
226 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
228 @retval other Error condition occurred.
234 IN IP_IO_OPEN_DATA
*OpenData
238 Send out an IP packet.
240 @param IpIo Pointer to an IP_IO instance used for sending IP
242 @param Pkt Pointer to the IP packet to be sent.
243 @param Sender The IP protocol instance used for sending.
246 @param Dest The destination IP address to send this packet to.
247 @param OverrideData The data to override some configuration of the IP
248 instance used for sending.
250 @retval EFI_SUCCESS The operation is completed successfully.
251 @retval EFI_NOT_STARTED The IpIo is not configured.
252 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
260 IN IP_IO_IP_INFO
*Sender
,
261 IN VOID
*Context OPTIONAL
,
262 IN VOID
*NotifyData OPTIONAL
,
264 IN IP_IO_OVERRIDE
*OverrideData
268 Cancel the IP transmit token which wraps this Packet.
270 @param IpIo Pointer to the IP_IO instance.
271 @param Packet Pointer to the packet to cancel.
282 Add a new IP instance for sending data.
284 @param IpIo Pointer to a IP_IO instance to add a new IP
285 instance for sending purpose.
287 @return Pointer to the created IP_IO_IP_INFO structure, NULL is failed.
297 Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData
300 @param IpInfo Pointer to the IP_IO_IP_INFO instance.
301 @param Ip4ConfigData The IP4 configure data used to configure the ip
302 instance, if NULL the ip instance is reseted. If
303 UseDefaultAddress is set to TRUE, and the configure
304 operation succeeds, the default address information
305 is written back in this Ip4ConfigData.
307 @retval EFI_STATUS The status returned by IP4->Configure or
314 IN IP_IO_IP_INFO
*IpInfo
,
315 IN OUT EFI_IP4_CONFIG_DATA
*Ip4ConfigData OPTIONAL
319 Destroy an IP instance maintained in IpIo->IpList for
322 @param IpIo Pointer to the IP_IO instance.
323 @param IpInfo Pointer to the IpInfo to be removed.
332 IN IP_IO_IP_INFO
*IpInfo
336 Find the first IP protocol maintained in IpIo whose local
337 address is the same with Src.
339 @param IpIo Pointer to the pointer of the IP_IO instance.
340 @param Src The local IP address.
342 @return Pointer to the IP protocol can be used for sending purpose and its local
343 @return address is the same with Src.
354 Get the ICMP error map information, the ErrorStatus will be returned.
355 The IsHard and Notify are optional. If they are not NULL, this rouine will
357 We move IcmpErrMap[] to local variable to enable EBC build.
359 @param IcmpError IcmpError Type
360 @param IsHard Whether it is a hard error
361 @param Notify Whether it need to notify SockError
363 @return ICMP Error Status
368 IpIoGetIcmpErrStatus (
369 IN ICMP_ERROR IcmpError
,
370 OUT BOOLEAN
*IsHard
, OPTIONAL
371 OUT BOOLEAN
*Notify OPTIONAL