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.
19 #include <Protocol/Ip4.h>
20 #include <Library/IpIoLib.h>
21 #include <Library/NetLib.h>
24 // type and code define for ICMP protocol error got
27 #define ICMP_TYPE_UNREACH 3
28 #define ICMP_TYPE_TIMXCEED 11
29 #define ICMP_TYPE_PARAMPROB 12
30 #define ICMP_TYPE_SOURCEQUENCH 4
32 #define ICMP_CODE_UNREACH_NET 0
33 #define ICMP_CODE_UNREACH_HOST 1
34 #define ICMP_CODE_UNREACH_PROTOCOL 2
35 #define ICMP_CODE_UNREACH_PORT 3
36 #define ICMP_CODE_UNREACH_NEEDFRAG 4
37 #define ICMP_CODE_UNREACH_SRCFAIL 5
38 #define ICMP_CODE_UNREACH_NET_UNKNOWN 6
39 #define ICMP_CODE_UNREACH_HOST_UNKNOWN 7
40 #define ICMP_CODE_UNREACH_ISOLATED 8
41 #define ICMP_CODE_UNREACH_NET_PROHIB 9
42 #define ICMP_CODE_UNREACH_HOST_PROHIB 10
43 #define ICMP_CODE_UNREACH_TOSNET 11
44 #define ICMP_CODE_UNREACH_TOSHOST 12
47 // this error will be delivered to the
48 // listening transportation layer protocol
52 ICMP_ERR_UNREACH_NET
= 0,
53 ICMP_ERR_UNREACH_HOST
,
54 ICMP_ERR_UNREACH_PROTOCOL
,
55 ICMP_ERR_UNREACH_PORT
,
57 ICMP_ERR_UNREACH_SRCFAIL
,
58 ICMP_ERR_TIMXCEED_INTRANS
,
59 ICMP_ERR_TIMXCEED_REASS
,
64 typedef struct _ICMP_ERROR_INFO
{
69 #define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)
71 extern EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData
;
73 typedef struct _EFI_NET_SESSION_DATA
{
76 EFI_IP4_HEADER
*IpHdr
;
77 } EFI_NET_SESSION_DATA
;
82 IN EFI_STATUS Status
, // rcvd pkt result
83 IN ICMP_ERROR IcmpErr
, // if Status == EFI_ICMP_ERROR, this
84 // field is valid for user
85 IN EFI_NET_SESSION_DATA
*NetSession
, // the communication point
86 IN NET_BUF
*Pkt
, // packet received
87 IN VOID
*Context
// the Context provided by user for recive data
93 IN EFI_STATUS Status
, // sent pkt result
94 IN VOID
*Context
, // the context provided by user for sending data
95 IN VOID
*Sender
, // the sender to be notified
96 IN VOID
*NotifyData
// sent pkt related data to notify
99 typedef struct _IP_IO
{
102 // the node used to link this IpIo to the active IpIo list.
106 // the list used to maintain the IP instance for different sending purpose.
111 // the ip instance consumed by this IP IO
113 EFI_HANDLE Controller
;
115 EFI_HANDLE ChildHandle
;
116 EFI_IP4_PROTOCOL
*Ip
;
117 BOOLEAN IsConfigured
;
120 // some ip config data can be changed
125 // token and event used to get data from IP
127 EFI_IP4_COMPLETION_TOKEN RcvToken
;
130 // list entry used to link the token passed to IP_IO
132 LIST_ENTRY PendingSndList
;
135 // User interface used to get notify from IP_IO
139 PKT_RCVD_NOTIFY PktRcvdNotify
;
140 PKT_SENT_NOTIFY PktSentNotify
;
143 typedef struct _IP_IO_OPEN_DATA
{
144 EFI_IP4_CONFIG_DATA IpConfigData
;
147 PKT_RCVD_NOTIFY PktRcvdNotify
;
148 PKT_SENT_NOTIFY PktSentNotify
;
151 typedef struct _IP_IO_SEND_ENTRY
{
156 EFI_IP4_PROTOCOL
*Ip
;
158 EFI_IP4_COMPLETION_TOKEN
*SndToken
;
161 typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE
;
163 typedef struct _IP_IO_IP_INFO
{
167 EFI_HANDLE ChildHandle
;
168 EFI_IP4_PROTOCOL
*Ip
;
169 EFI_IP4_COMPLETION_TOKEN DummyRcvToken
;
174 Create a new IP_IO instance.
176 @param Image The image handle of an IP_IO consumer protocol.
177 @param Controller The controller handle of an IP_IO consumer protocol
180 @return Pointer to a newly created IP_IO instance.
187 IN EFI_HANDLE Controller
191 Destroy an IP_IO instance.
193 @param IpIo Pointer to the IP_IO instance that needs to
196 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
197 @retval other Error condition occurred.
207 Stop an IP_IO instance.
209 @param IpIo Pointer to the IP_IO instance that needs to stop.
211 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
212 @retval other Error condition occurred.
222 Open an IP_IO instance for use.
224 @param IpIo Pointer to an IP_IO instance that needs to open.
225 @param OpenData The configuration data for the IP_IO instance.
227 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
229 @retval other Error condition occurred.
235 IN IP_IO_OPEN_DATA
*OpenData
239 Send out an IP packet.
241 @param IpIo Pointer to an IP_IO instance used for sending IP
243 @param Pkt Pointer to the IP packet to be sent.
244 @param Sender The IP protocol instance used for sending.
247 @param Dest The destination IP address to send this packet to.
248 @param OverrideData The data to override some configuration of the IP
249 instance used for sending.
251 @retval EFI_SUCCESS The operation is completed successfully.
252 @retval EFI_NOT_STARTED The IpIo is not configured.
253 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
261 IN IP_IO_IP_INFO
*Sender
,
262 IN VOID
*Context OPTIONAL
,
263 IN VOID
*NotifyData OPTIONAL
,
265 IN IP_IO_OVERRIDE
*OverrideData
269 Cancel the IP transmit token which wraps this Packet.
271 @param IpIo Pointer to the IP_IO instance.
272 @param Packet Pointer to the packet to cancel.
283 Add a new IP instance for sending data.
285 @param IpIo Pointer to a IP_IO instance to add a new IP
286 instance for sending purpose.
288 @return Pointer to the created IP_IO_IP_INFO structure, NULL is failed.
298 Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData
301 @param IpInfo Pointer to the IP_IO_IP_INFO instance.
302 @param Ip4ConfigData The IP4 configure data used to configure the ip
303 instance, if NULL the ip instance is reseted. If
304 UseDefaultAddress is set to TRUE, and the configure
305 operation succeeds, the default address information
306 is written back in this Ip4ConfigData.
308 @retval EFI_STATUS The status returned by IP4->Configure or
315 IN IP_IO_IP_INFO
*IpInfo
,
316 IN OUT EFI_IP4_CONFIG_DATA
*Ip4ConfigData OPTIONAL
320 Destroy an IP instance maintained in IpIo->IpList for
323 @param IpIo Pointer to the IP_IO instance.
324 @param IpInfo Pointer to the IpInfo to be removed.
333 IN IP_IO_IP_INFO
*IpInfo
337 Find the first IP protocol maintained in IpIo whose local
338 address is the same with Src.
340 @param IpIo Pointer to the pointer of the IP_IO instance.
341 @param Src The local IP address.
343 @return Pointer to the IP protocol can be used for sending purpose and its local
344 @return address is the same with Src.
355 Get the ICMP error map information, the ErrorStatus will be returned.
356 The IsHard and Notify are optional. If they are not NULL, this rouine will
358 We move IcmpErrMap[] to local variable to enable EBC build.
360 @param IcmpError IcmpError Type
361 @param IsHard Whether it is a hard error
362 @param Notify Whether it need to notify SockError
364 @return ICMP Error Status
369 IpIoGetIcmpErrStatus (
370 IN ICMP_ERROR IcmpError
,
371 OUT BOOLEAN
*IsHard
, OPTIONAL
372 OUT BOOLEAN
*Notify OPTIONAL