]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Library/IpIoLib.h
1. add public functions header.
[mirror_edk2.git] / MdeModulePkg / Include / Library / IpIoLib.h
1 /** @file
2 This library provides IpIo layer upon EFI IP4 Protocol.
3
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
9
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.
12
13 **/
14
15 #ifndef _IP_IO_H_
16 #define _IP_IO_H_
17
18 #include <PiDxe.h>
19 #include <Protocol/Ip4.h>
20 #include <Library/IpIoLib.h>
21 #include <Library/NetLib.h>
22
23 //
24 // type and code define for ICMP protocol error got
25 // from IP
26 //
27 #define ICMP_TYPE_UNREACH 3
28 #define ICMP_TYPE_TIMXCEED 11
29 #define ICMP_TYPE_PARAMPROB 12
30 #define ICMP_TYPE_SOURCEQUENCH 4
31
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
45
46 //
47 // this error will be delivered to the
48 // listening transportation layer protocol
49 // consuming IpIO
50 //
51 typedef enum {
52 ICMP_ERR_UNREACH_NET = 0,
53 ICMP_ERR_UNREACH_HOST,
54 ICMP_ERR_UNREACH_PROTOCOL,
55 ICMP_ERR_UNREACH_PORT,
56 ICMP_ERR_MSGSIZE,
57 ICMP_ERR_UNREACH_SRCFAIL,
58 ICMP_ERR_TIMXCEED_INTRANS,
59 ICMP_ERR_TIMXCEED_REASS,
60 ICMP_ERR_QUENCH,
61 ICMP_ERR_PARAMPROB
62 } ICMP_ERROR;
63
64 typedef struct _ICMP_ERROR_INFO {
65 BOOLEAN IsHard;
66 BOOLEAN Notify;
67 } ICMP_ERROR_INFO;
68
69 #define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)
70
71 extern EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData;
72
73 typedef struct _EFI_NET_SESSION_DATA {
74 IP4_ADDR Source;
75 IP4_ADDR Dest;
76 EFI_IP4_HEADER *IpHdr;
77 } EFI_NET_SESSION_DATA;
78
79 typedef
80 VOID
81 (*PKT_RCVD_NOTIFY) (
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
88 );
89
90 typedef
91 VOID
92 (*PKT_SENT_NOTIFY) (
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
97 );
98
99 typedef struct _IP_IO {
100
101 //
102 // the node used to link this IpIo to the active IpIo list.
103 //
104 LIST_ENTRY Entry;
105
106 // the list used to maintain the IP instance for different sending purpose.
107 //
108 LIST_ENTRY IpList;
109
110 //
111 // the ip instance consumed by this IP IO
112 //
113 EFI_HANDLE Controller;
114 EFI_HANDLE Image;
115 EFI_HANDLE ChildHandle;
116 EFI_IP4_PROTOCOL *Ip;
117 BOOLEAN IsConfigured;
118
119 //
120 // some ip config data can be changed
121 //
122 UINT8 Protocol;
123
124 //
125 // token and event used to get data from IP
126 //
127 EFI_IP4_COMPLETION_TOKEN RcvToken;
128
129 //
130 // list entry used to link the token passed to IP_IO
131 //
132 LIST_ENTRY PendingSndList;
133
134 //
135 // User interface used to get notify from IP_IO
136 //
137 VOID *RcvdContext;
138 VOID *SndContext;
139 PKT_RCVD_NOTIFY PktRcvdNotify;
140 PKT_SENT_NOTIFY PktSentNotify;
141 } IP_IO;
142
143 typedef struct _IP_IO_OPEN_DATA {
144 EFI_IP4_CONFIG_DATA IpConfigData;
145 VOID *RcvdContext;
146 VOID *SndContext;
147 PKT_RCVD_NOTIFY PktRcvdNotify;
148 PKT_SENT_NOTIFY PktSentNotify;
149 } IP_IO_OPEN_DATA;
150
151 typedef struct _IP_IO_SEND_ENTRY {
152 LIST_ENTRY Entry;
153 IP_IO *IpIo;
154 VOID *Context;
155 VOID *NotifyData;
156 EFI_IP4_PROTOCOL *Ip;
157 NET_BUF *Pkt;
158 EFI_IP4_COMPLETION_TOKEN *SndToken;
159 } IP_IO_SEND_ENTRY;
160
161 typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE;
162
163 typedef struct _IP_IO_IP_INFO {
164 IP4_ADDR Addr;
165 IP4_ADDR SubnetMask;
166 LIST_ENTRY Entry;
167 EFI_HANDLE ChildHandle;
168 EFI_IP4_PROTOCOL *Ip;
169 EFI_IP4_COMPLETION_TOKEN DummyRcvToken;
170 INTN RefCnt;
171 } IP_IO_IP_INFO;
172
173 /**
174 Create a new IP_IO instance.
175
176 @param Image The image handle of an IP_IO consumer protocol.
177 @param Controller The controller handle of an IP_IO consumer protocol
178 installed on.
179
180 @return Pointer to a newly created IP_IO instance.
181
182 **/
183 IP_IO *
184 EFIAPI
185 IpIoCreate (
186 IN EFI_HANDLE Image,
187 IN EFI_HANDLE Controller
188 );
189
190 /**
191 Destroy an IP_IO instance.
192
193 @param IpIo Pointer to the IP_IO instance that needs to
194 destroy.
195
196 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
197 @retval other Error condition occurred.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 IpIoDestroy (
203 IN IP_IO *IpIo
204 );
205
206 /**
207 Stop an IP_IO instance.
208
209 @param IpIo Pointer to the IP_IO instance that needs to stop.
210
211 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
212 @retval other Error condition occurred.
213
214 **/
215 EFI_STATUS
216 EFIAPI
217 IpIoStop (
218 IN IP_IO *IpIo
219 );
220
221 /**
222 Open an IP_IO instance for use.
223
224 @param IpIo Pointer to an IP_IO instance that needs to open.
225 @param OpenData The configuration data for the IP_IO instance.
226
227 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
228 successfully.
229 @retval other Error condition occurred.
230
231 **/
232 EFI_STATUS
233 IpIoOpen (
234 IN IP_IO *IpIo,
235 IN IP_IO_OPEN_DATA *OpenData
236 );
237
238 /**
239 Send out an IP packet.
240
241 @param IpIo Pointer to an IP_IO instance used for sending IP
242 packet.
243 @param Pkt Pointer to the IP packet to be sent.
244 @param Sender The IP protocol instance used for sending.
245 @param NotifyData
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.
249
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.
253
254 **/
255 EFI_STATUS
256 EFIAPI
257 IpIoSend (
258 IN IP_IO *IpIo,
259 IN NET_BUF *Pkt,
260 IN IP_IO_IP_INFO *Sender,
261 IN VOID *Context OPTIONAL,
262 IN VOID *NotifyData OPTIONAL,
263 IN IP4_ADDR Dest,
264 IN IP_IO_OVERRIDE *OverrideData
265 );
266
267 /**
268 Add a new IP instance for sending data.
269
270 @param IpIo Pointer to a IP_IO instance to add a new IP
271 instance for sending purpose.
272
273 @return Pointer to the created IP_IO_IP_INFO structure, NULL is failed.
274
275 **/
276 VOID
277 EFIAPI
278 IpIoCancelTxToken (
279 IN IP_IO *IpIo,
280 IN VOID *Packet
281 );
282
283 /**
284 Add a new IP instance for sending data.
285
286 @param IpIo Pointer to a IP_IO instance to add a new IP
287 instance for sending purpose.
288
289 @return Pointer to the created IP_IO_IP_INFO structure, NULL is failed.
290
291 **/
292 IP_IO_IP_INFO *
293 EFIAPI
294 IpIoAddIp (
295 IN IP_IO *IpIo
296 );
297
298 /**
299 Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData
300 is not NULL.
301
302 @param IpInfo Pointer to the IP_IO_IP_INFO instance.
303 @param Ip4ConfigData The IP4 configure data used to configure the ip
304 instance, if NULL the ip instance is reseted. If
305 UseDefaultAddress is set to TRUE, and the configure
306 operation succeeds, the default address information
307 is written back in this Ip4ConfigData.
308
309 @retval EFI_STATUS The status returned by IP4->Configure or
310 IP4->Receive.
311
312 **/
313 EFI_STATUS
314 EFIAPI
315 IpIoConfigIp (
316 IN IP_IO_IP_INFO *IpInfo,
317 IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData OPTIONAL
318 );
319
320 /**
321 Destroy an IP instance maintained in IpIo->IpList for
322 sending purpose.
323
324 @param IpIo Pointer to the IP_IO instance.
325 @param IpInfo Pointer to the IpInfo to be removed.
326
327 @return None.
328
329 **/
330 VOID
331 EFIAPI
332 IpIoRemoveIp (
333 IN IP_IO *IpIo,
334 IN IP_IO_IP_INFO *IpInfo
335 );
336
337 /**
338 Find the first IP protocol maintained in IpIo whose local
339 address is the same with Src.
340
341 @param IpIo Pointer to the pointer of the IP_IO instance.
342 @param Src The local IP address.
343
344 @return Pointer to the IP protocol can be used for sending purpose and its local
345 @return address is the same with Src.
346
347 **/
348 IP_IO_IP_INFO *
349 EFIAPI
350 IpIoFindSender (
351 IN OUT IP_IO **IpIo,
352 IN IP4_ADDR Src
353 );
354
355 /**
356 Get the ICMP error map information, the ErrorStatus will be returned.
357 The IsHard and Notify are optional. If they are not NULL, this rouine will
358 fill them.
359 We move IcmpErrMap[] to local variable to enable EBC build.
360
361 @param IcmpError IcmpError Type
362 @param IsHard Whether it is a hard error
363 @param Notify Whether it need to notify SockError
364
365 @return ICMP Error Status
366
367 **/
368 EFI_STATUS
369 EFIAPI
370 IpIoGetIcmpErrStatus (
371 IN ICMP_ERROR IcmpError,
372 OUT BOOLEAN *IsHard, OPTIONAL
373 OUT BOOLEAN *Notify OPTIONAL
374 );
375
376 #endif