e2c9f67559ef81631efbd9b7fc510bbd9c648da0
[mirror_edk2.git] / MdeModulePkg / Include / Library / IpIoLib.h
1 /** @file
2
3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 IpIo.h
15
16 Abstract:
17
18
19 **/
20
21 #ifndef _IP_IO_H_
22 #define _IP_IO_H_
23
24 #include <PiDxe.h>
25 #include <Protocol/Ip4.h>
26 #include <Library/IpIoLib.h>
27 #include <Library/NetLib.h>
28
29 //
30 // type and code define for ICMP protocol error got
31 // from IP
32 //
33 #define ICMP_TYPE_UNREACH 3
34 #define ICMP_TYPE_TIMXCEED 11
35 #define ICMP_TYPE_PARAMPROB 12
36 #define ICMP_TYPE_SOURCEQUENCH 4
37
38 #define ICMP_CODE_UNREACH_NET 0
39 #define ICMP_CODE_UNREACH_HOST 1
40 #define ICMP_CODE_UNREACH_PROTOCOL 2
41 #define ICMP_CODE_UNREACH_PORT 3
42 #define ICMP_CODE_UNREACH_NEEDFRAG 4
43 #define ICMP_CODE_UNREACH_SRCFAIL 5
44 #define ICMP_CODE_UNREACH_NET_UNKNOWN 6
45 #define ICMP_CODE_UNREACH_HOST_UNKNOWN 7
46 #define ICMP_CODE_UNREACH_ISOLATED 8
47 #define ICMP_CODE_UNREACH_NET_PROHIB 9
48 #define ICMP_CODE_UNREACH_HOST_PROHIB 10
49 #define ICMP_CODE_UNREACH_TOSNET 11
50 #define ICMP_CODE_UNREACH_TOSHOST 12
51
52 //
53 // this error will be delivered to the
54 // listening transportation layer protocol
55 // consuming IpIO
56 //
57 typedef enum {
58 ICMP_ERR_UNREACH_NET = 0,
59 ICMP_ERR_UNREACH_HOST,
60 ICMP_ERR_UNREACH_PROTOCOL,
61 ICMP_ERR_UNREACH_PORT,
62 ICMP_ERR_MSGSIZE,
63 ICMP_ERR_UNREACH_SRCFAIL,
64 ICMP_ERR_TIMXCEED_INTRANS,
65 ICMP_ERR_TIMXCEED_REASS,
66 ICMP_ERR_QUENCH,
67 ICMP_ERR_PARAMPROB
68 } ICMP_ERROR;
69
70 typedef struct _ICMP_ERROR_INFO {
71 EFI_STATUS Error;
72 BOOLEAN IsHard;
73 BOOLEAN Notify;
74 } ICMP_ERROR_INFO;
75
76
77 #define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)
78
79 extern EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData;
80
81 typedef struct _EFI_NET_SESSION_DATA {
82 IP4_ADDR Source;
83 IP4_ADDR Dest;
84 EFI_IP4_HEADER *IpHdr;
85 } EFI_NET_SESSION_DATA;
86
87 typedef
88 VOID
89 (*PKT_RCVD_NOTIFY) (
90 IN EFI_STATUS Status, // rcvd pkt result
91 IN ICMP_ERROR IcmpErr, // if Status == EFI_ICMP_ERROR, this
92 // field is valid for user
93 IN EFI_NET_SESSION_DATA *NetSession, // the communication point
94 IN NET_BUF *Pkt, // packet received
95 IN VOID *Context // the Context provided by user for recive data
96 );
97
98 typedef
99 VOID
100 (*PKT_SENT_NOTIFY) (
101 IN EFI_STATUS Status, // sent pkt result
102 IN VOID *Context, // the context provided by user for sending data
103 IN VOID *Sender, // the sender to be notified
104 IN VOID *NotifyData // sent pkt related data to notify
105 );
106
107 typedef struct _IP_IO {
108
109 //
110 // the node used to link this IpIo to the active IpIo list.
111 //
112 NET_LIST_ENTRY Entry;
113
114 // the list used to maintain the IP instance for different sending purpose.
115 //
116 NET_LIST_ENTRY IpList;
117
118 //
119 // the ip instance consumed by this IP IO
120 //
121 EFI_HANDLE Controller;
122 EFI_HANDLE Image;
123 EFI_HANDLE ChildHandle;
124 EFI_IP4_PROTOCOL *Ip;
125 BOOLEAN IsConfigured;
126
127 //
128 // some ip config data can be changed
129 //
130 UINT8 Protocol;
131
132 //
133 // token and event used to get data from IP
134 //
135 EFI_IP4_COMPLETION_TOKEN RcvToken;
136
137 //
138 // list entry used to link the token passed to IP_IO
139 //
140 NET_LIST_ENTRY PendingSndList;
141
142 //
143 // User interface used to get notify from IP_IO
144 //
145 VOID *RcvdContext;
146 VOID *SndContext;
147 PKT_RCVD_NOTIFY PktRcvdNotify;
148 PKT_SENT_NOTIFY PktSentNotify;
149 } IP_IO;
150
151 typedef struct _IP_IO_OPEN_DATA {
152 EFI_IP4_CONFIG_DATA IpConfigData;
153 VOID *RcvdContext;
154 VOID *SndContext;
155 PKT_RCVD_NOTIFY PktRcvdNotify;
156 PKT_SENT_NOTIFY PktSentNotify;
157 } IP_IO_OPEN_DATA;
158
159 typedef struct _IP_IO_SEND_ENTRY {
160 NET_LIST_ENTRY Entry;
161 IP_IO *IpIo;
162 VOID *Context;
163 VOID *NotifyData;
164 EFI_IP4_PROTOCOL *Ip;
165 NET_BUF *Pkt;
166 EFI_IP4_COMPLETION_TOKEN *SndToken;
167 } IP_IO_SEND_ENTRY;
168
169 typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE;
170
171 typedef struct _IP_IO_IP_INFO {
172 IP4_ADDR Addr;
173 IP4_ADDR SubnetMask;
174 NET_LIST_ENTRY Entry;
175 EFI_HANDLE ChildHandle;
176 EFI_IP4_PROTOCOL *Ip;
177 EFI_IP4_COMPLETION_TOKEN DummyRcvToken;
178 INTN RefCnt;
179 } IP_IO_IP_INFO;
180
181 IP_IO *
182 IpIoCreate (
183 IN EFI_HANDLE Image,
184 IN EFI_HANDLE Controller
185 );
186
187 EFI_STATUS
188 IpIoDestroy (
189 IN IP_IO *IpIo
190 );
191
192 EFI_STATUS
193 IpIoStop (
194 IN IP_IO *IpIo
195 );
196
197 EFI_STATUS
198 IpIoOpen (
199 IN IP_IO *IpIo,
200 IN IP_IO_OPEN_DATA *OpenData
201 );
202
203 EFI_STATUS
204 IpIoSend (
205 IN IP_IO *IpIo,
206 IN NET_BUF *Pkt,
207 IN IP_IO_IP_INFO *Sender,
208 IN VOID *Context OPTIONAL,
209 IN VOID *NotifyData OPTIONAL,
210 IN IP4_ADDR Dest,
211 IN IP_IO_OVERRIDE *OverrideData
212 );
213
214 VOID
215 IpIoCancelTxToken (
216 IN IP_IO *IpIo,
217 IN VOID *Packet
218 );
219
220 IP_IO_IP_INFO *
221 IpIoAddIp (
222 IN IP_IO *IpIo
223 );
224
225 EFI_STATUS
226 IpIoConfigIp (
227 IN IP_IO_IP_INFO *IpInfo,
228 IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData OPTIONAL
229 );
230
231 VOID
232 IpIoRemoveIp (
233 IN IP_IO *IpIo,
234 IN IP_IO_IP_INFO *IpInfo
235 );
236
237 IP_IO_IP_INFO *
238 IpIoFindSender (
239 IN OUT IP_IO **IpIo,
240 IN IP4_ADDR Src
241 );
242
243 EFI_STATUS
244 IpIoGetIcmpErrStatus (
245 IN ICMP_ERROR IcmpError,
246 OUT BOOLEAN *IsHard, OPTIONAL
247 OUT BOOLEAN *Notify OPTIONAL
248 );
249
250 #endif