]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Library/IpIoLib.h
Enhance function 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 <Protocol/Ip4.h>
19 #include <Library/IpIoLib.h>
20 #include <Library/NetLib.h>
21
22 //
23 // type and code define for ICMP protocol error got
24 // from IP
25 //
26 #define ICMP_TYPE_UNREACH 3
27 #define ICMP_TYPE_TIMXCEED 11
28 #define ICMP_TYPE_PARAMPROB 12
29 #define ICMP_TYPE_SOURCEQUENCH 4
30
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
44
45 ///
46 /// This error will be delivered to the
47 /// listening transportation layer protocol
48 /// that consumes IpIO.
49 ///
50 typedef enum {
51 ICMP_ERR_UNREACH_NET = 0,
52 ICMP_ERR_UNREACH_HOST,
53 ICMP_ERR_UNREACH_PROTOCOL,
54 ICMP_ERR_UNREACH_PORT,
55 ICMP_ERR_MSGSIZE,
56 ICMP_ERR_UNREACH_SRCFAIL,
57 ICMP_ERR_TIMXCEED_INTRANS,
58 ICMP_ERR_TIMXCEED_REASS,
59 ICMP_ERR_QUENCH,
60 ICMP_ERR_PARAMPROB
61 } ICMP_ERROR;
62
63 ///
64 /// The helper struct for IpIoGetIcmpErrStatus(). It is internal-use only.
65 ///
66 typedef struct _ICMP_ERROR_INFO {
67 BOOLEAN IsHard;
68 BOOLEAN Notify;
69 } ICMP_ERROR_INFO;
70
71 /**
72 Get the IP header length from EFI_IP4_HEADER struct.
73
74 @param HdrPtr A pointer to EFI_IP4_HEADER
75
76 @return The IP header length
77 **/
78 #define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)
79
80 extern EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData;
81
82 ///
83 /// The IP session for an IP receive packet.
84 ///
85 typedef struct _EFI_NET_SESSION_DATA {
86 IP4_ADDR Source; ///< Source IP of the received packet
87 IP4_ADDR Dest; ///< Destination IP of the received packet
88 EFI_IP4_HEADER *IpHdr; ///< IP4 header of the received packet
89 } EFI_NET_SESSION_DATA;
90
91 /**
92 The prototype is called back when an IP packet is received.
93
94 @param Status Result of the receive request
95 @param IcmpErr Valid when Status is EFI_ICMP_ERROR
96 @param NetSession The IP session for the received packet
97 @param Pkt Packet received
98 @param Context The data provided by user for the received packet when
99 the callback is registered in IP_IO_OPEN_DATA::RcvdContext.
100
101 **/
102 typedef
103 VOID
104 (*PKT_RCVD_NOTIFY) (
105 IN EFI_STATUS Status,
106 IN ICMP_ERROR IcmpErr,
107 IN EFI_NET_SESSION_DATA *NetSession,
108 IN NET_BUF *Pkt,
109 IN VOID *Context
110 );
111
112 /**
113 The prototype is called back when an IP packet is sent.
114
115 @param Status Result of the sending
116 @param Context The data provided by user for the received packet when
117 the callback is registered in IP_IO_OPEN_DATA::SndContext.
118 @param Sender A pointer to EFI_IP4_PROTOCOL for sender
119 @param NotifyData Context data specified when calling IpIoSend()
120
121 **/
122 typedef
123 VOID
124 (*PKT_SENT_NOTIFY) (
125 IN EFI_STATUS Status,
126 IN VOID *Context,
127 IN VOID *Sender,
128 IN VOID *NotifyData
129 );
130
131 ///
132 /// The data structure wraps Ip4 instance. It is used by IpIo Library to do all
133 /// Ip4 operations.
134 ///
135 typedef struct _IP_IO {
136 ///
137 /// The node used to link this IpIo to the active IpIo list.
138 ///
139 LIST_ENTRY Entry;
140
141 ///
142 /// The list used to maintain the IP instance for different sending purpose.
143 ///
144 LIST_ENTRY IpList;
145
146 EFI_HANDLE Controller;
147 EFI_HANDLE Image;
148 EFI_HANDLE ChildHandle;
149 //
150 // The IP instance consumed by this IP_IO
151 //
152 EFI_IP4_PROTOCOL *Ip;
153 BOOLEAN IsConfigured;
154
155 ///
156 /// some ip config data can be changed
157 ///
158 UINT8 Protocol;
159
160 ///
161 /// Token and event used to get data from IP
162 ///
163 EFI_IP4_COMPLETION_TOKEN RcvToken;
164
165 ///
166 /// List entry used to link the token passed to IP_IO
167 ///
168 LIST_ENTRY PendingSndList;
169
170 //
171 // User interface used to get notify from IP_IO
172 //
173 VOID *RcvdContext; ///< See IP_IO_OPEN_DATA::RcvdContext
174 VOID *SndContext; ///< See IP_IO_OPEN_DATA::SndContext
175 PKT_RCVD_NOTIFY PktRcvdNotify; ///< See IP_IO_OPEN_DATA::PktRcvdNotify
176 PKT_SENT_NOTIFY PktSentNotify; ///< See IP_IO_OPEN_DATA::PktSentNotify
177 } IP_IO;
178
179 ///
180 /// The struct is used for user to pass IP configuration and callbacks to IP_IO.
181 /// It is used by IpIoOpen().
182 ///
183 typedef struct _IP_IO_OPEN_DATA {
184 EFI_IP4_CONFIG_DATA IpConfigData; ///< Configuration of the IP instance
185 VOID *RcvdContext; ///< Context data used by receive callback
186 VOID *SndContext; ///< Context data used by send callback
187 PKT_RCVD_NOTIFY PktRcvdNotify; ///< Receive callback
188 PKT_SENT_NOTIFY PktSentNotify; ///< Send callback
189 } IP_IO_OPEN_DATA;
190
191 ///
192 /// Internal struct book-keeping send request of IP_IO.
193 ///
194 /// An IP_IO_SEND_ENTRY will be created each time a send request is issued to
195 /// IP_IO via IpIoSend().
196 ///
197 typedef struct _IP_IO_SEND_ENTRY {
198 LIST_ENTRY Entry;
199 IP_IO *IpIo;
200 VOID *Context;
201 VOID *NotifyData;
202 EFI_IP4_PROTOCOL *Ip;
203 NET_BUF *Pkt;
204 EFI_IP4_COMPLETION_TOKEN *SndToken;
205 } IP_IO_SEND_ENTRY;
206
207 typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE;
208
209 ///
210 /// The IP_IO_IP_INFO is used in IpIoSend() to override the default IP instance
211 /// in IP_IO.
212 ///
213 typedef struct _IP_IO_IP_INFO {
214 IP4_ADDR Addr;
215 IP4_ADDR SubnetMask;
216 LIST_ENTRY Entry;
217 EFI_HANDLE ChildHandle;
218 EFI_IP4_PROTOCOL *Ip;
219 EFI_IP4_COMPLETION_TOKEN DummyRcvToken;
220 INTN RefCnt;
221 } IP_IO_IP_INFO;
222
223 /**
224 Create a new IP_IO instance.
225
226 This function uses IP4 service binding protocol in Controller to create an IP4
227 child (aka IP4 instance).
228
229 @param Image The image handle of the driver or application that
230 consumes IP_IO.
231 @param Controller The controller handle that has IP4 service binding
232 protocol installed.
233
234 @return Pointer to a newly created IP_IO instance, or NULL if failed.
235
236 **/
237 IP_IO *
238 EFIAPI
239 IpIoCreate (
240 IN EFI_HANDLE Image,
241 IN EFI_HANDLE Controller
242 );
243
244 /**
245 Destroy an IP_IO instance.
246
247 This function is paired with IpIoCreate(). The IP_IO will be closed first.
248 Resource will be freed afterwards. See IpIoClose().
249
250 @param IpIo Pointer to the IP_IO instance that needs to be
251 destroyed.
252
253 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
254 @retval Other Error condition occurred.
255
256 **/
257 EFI_STATUS
258 EFIAPI
259 IpIoDestroy (
260 IN IP_IO *IpIo
261 );
262
263 /**
264 Stop an IP_IO instance.
265
266 This function is paired with IpIoOpen(). The IP_IO will be unconfigured and all
267 the pending send/receive tokens will be canceled.
268
269 @param IpIo Pointer to the IP_IO instance that needs to stop.
270
271 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
272 @retval Other Error condition occurred.
273
274 **/
275 EFI_STATUS
276 EFIAPI
277 IpIoStop (
278 IN IP_IO *IpIo
279 );
280
281 /**
282 Open an IP_IO instance for use.
283
284 This function is called after IpIoCreate(). It is used for configuring the IP
285 instance and register the callbacks and their context data for sending and
286 receiving IP packets.
287
288 @param IpIo Pointer to an IP_IO instance that needs to open.
289 @param OpenData The configuration data and callbacks for the IP_IO
290 instance.
291
292 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
293 successfully.
294 @retval Other Error condition occurred.
295
296 **/
297 EFI_STATUS
298 EFIAPI
299 IpIoOpen (
300 IN IP_IO *IpIo,
301 IN IP_IO_OPEN_DATA *OpenData
302 );
303
304 /**
305 Send out an IP packet.
306
307 This function is called after IpIoOpen(). The data to be sent are wrapped in
308 Pkt. The IP instance wrapped in IpIo is used for sending by default but can be
309 overriden by Sender. Other sending configs, like source address and gateway
310 address etc., are specified in OverrideData.
311
312 @param IpIo Pointer to an IP_IO instance used for sending IP
313 packet.
314 @param Pkt Pointer to the IP packet to be sent.
315 @param Sender The IP protocol instance used for sending.
316 @param Context Optional context data
317 @param NotifyData Optional notify data
318 @param Dest The destination IP address to send this packet to.
319 @param OverrideData The data to override some configuration of the IP
320 instance used for sending.
321
322 @retval EFI_SUCCESS The operation is completed successfully.
323 @retval EFI_NOT_STARTED The IpIo is not configured.
324 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
325
326 **/
327 EFI_STATUS
328 EFIAPI
329 IpIoSend (
330 IN IP_IO *IpIo,
331 IN NET_BUF *Pkt,
332 IN IP_IO_IP_INFO *Sender OPTIONAL,
333 IN VOID *Context OPTIONAL,
334 IN VOID *NotifyData OPTIONAL,
335 IN IP4_ADDR Dest,
336 IN IP_IO_OVERRIDE *OverrideData OPTIONAL
337 );
338
339 /**
340 Cancel the IP transmit token which wraps this Packet.
341
342 @param IpIo Pointer to the IP_IO instance.
343 @param Packet Pointer to the packet of NET_BUF to cancel.
344
345 **/
346 VOID
347 EFIAPI
348 IpIoCancelTxToken (
349 IN IP_IO *IpIo,
350 IN VOID *Packet
351 );
352
353 /**
354 Add a new IP instance for sending data.
355
356 The function is used to add the IP_IO to the IP_IO sending list. The caller
357 can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to send
358 data.
359
360 @param IpIo Pointer to a IP_IO instance to add a new IP
361 instance for sending purpose.
362
363 @return Pointer to the created IP_IO_IP_INFO structure, NULL if failed.
364
365 **/
366 IP_IO_IP_INFO *
367 EFIAPI
368 IpIoAddIp (
369 IN IP_IO *IpIo
370 );
371
372 /**
373 Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData
374 is not NULL.
375
376 @param IpInfo Pointer to the IP_IO_IP_INFO instance.
377 @param Ip4ConfigData The IP4 configure data used to configure the IP
378 instance, if NULL the IP instance is reset. If
379 UseDefaultAddress is set to TRUE, and the configure
380 operation succeeds, the default address information
381 is written back in this Ip4ConfigData.
382
383 @retval EFI_STATUS The status returned by IP4->Configure or
384 IP4->Receive.
385 @retval Other Configuration fails.
386
387 **/
388 EFI_STATUS
389 EFIAPI
390 IpIoConfigIp (
391 IN IP_IO_IP_INFO *IpInfo,
392 IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData OPTIONAL
393 );
394
395 /**
396 Destroy an IP instance maintained in IpIo->IpList for
397 sending purpose.
398
399 This function pairs with IpIoAddIp(). The IpInfo is previously created by
400 IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance
401 will be dstroyed if the RefCnt is zero.
402
403 @param IpIo Pointer to the IP_IO instance.
404 @param IpInfo Pointer to the IpInfo to be removed.
405
406 **/
407 VOID
408 EFIAPI
409 IpIoRemoveIp (
410 IN IP_IO *IpIo,
411 IN IP_IO_IP_INFO *IpInfo
412 );
413
414 /**
415 Find the first IP protocol maintained in IpIo whose local
416 address is the same with Src.
417
418 This function is called when the caller needs the IpIo to send data to the
419 specified Src. The IpIo was added previously by IpIoAddIp().
420
421 @param IpIo Pointer to the pointer of the IP_IO instance.
422 @param Src The local IP address.
423
424 @return Pointer to the IP protocol can be used for sending purpose and its local
425 address is the same with Src.
426
427 **/
428 IP_IO_IP_INFO *
429 EFIAPI
430 IpIoFindSender (
431 IN OUT IP_IO **IpIo,
432 IN IP4_ADDR Src
433 );
434
435 /**
436 Get the ICMP error map information.
437
438 The ErrorStatus will be returned. The IsHard and Notify are optional. If they
439 are not NULL, this routine will fill them.
440
441 @param IcmpError IcmpError Type
442 @param IsHard Whether it is a hard error
443 @param Notify Whether it need to notify SockError
444
445 @return ICMP Error Status
446
447 **/
448 EFI_STATUS
449 EFIAPI
450 IpIoGetIcmpErrStatus (
451 IN ICMP_ERROR IcmpError,
452 OUT BOOLEAN *IsHard OPTIONAL,
453 OUT BOOLEAN *Notify OPTIONAL
454 );
455
456 #endif