]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Library/IpIoLib.h
Committing changes to the comments, to improve code documentation.
[mirror_edk2.git] / MdeModulePkg / Include / Library / IpIoLib.h
CommitLineData
97b38d4e 1/** @file\r
e4b99ad9 2 Ihis library is only intended to be used by UEFI network stack modules.\r
e9b67286 3 It provides the IpIo layer on the EFI IP4 Protocol.\r
97b38d4e 4\r
cdfdbb97 5Copyright (c) 2005 - 2008, Intel Corporation.<BR>\r
97b38d4e 6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _IP_IO_H_\r
17#define _IP_IO_H_\r
18\r
19#include <Protocol/Ip4.h>\r
cdfdbb97 20\r
97b38d4e 21#include <Library/NetLib.h>\r
22\r
23//\r
e9b67286 24// type and code define for ICMP protocol error \r
97b38d4e 25// from IP\r
26//\r
27#define ICMP_TYPE_UNREACH 3\r
cdfdbb97 28#define ICMP_TYPE_TIMXCEED 11\r
97b38d4e 29#define ICMP_TYPE_PARAMPROB 12\r
30#define ICMP_TYPE_SOURCEQUENCH 4\r
31\r
32#define ICMP_CODE_UNREACH_NET 0\r
33#define ICMP_CODE_UNREACH_HOST 1\r
34#define ICMP_CODE_UNREACH_PROTOCOL 2\r
35#define ICMP_CODE_UNREACH_PORT 3\r
36#define ICMP_CODE_UNREACH_NEEDFRAG 4\r
37#define ICMP_CODE_UNREACH_SRCFAIL 5\r
38#define ICMP_CODE_UNREACH_NET_UNKNOWN 6\r
39#define ICMP_CODE_UNREACH_HOST_UNKNOWN 7\r
40#define ICMP_CODE_UNREACH_ISOLATED 8\r
41#define ICMP_CODE_UNREACH_NET_PROHIB 9\r
42#define ICMP_CODE_UNREACH_HOST_PROHIB 10\r
43#define ICMP_CODE_UNREACH_TOSNET 11\r
44#define ICMP_CODE_UNREACH_TOSHOST 12\r
45\r
cdfdbb97 46/**\r
e9b67286 47 Get the IP header length from the struct EFI_IP4_HEADER. HeaderLength is\r
cdfdbb97 48 Internet header length in 32-bit words, so HeaderLength<<2 is the real\r
49 length of IP header.\r
50 \r
51 @param[out] HdrPtr A pointer to EFI_IP4_HEADER\r
52 \r
53 @return The IP header length\r
54**/\r
55#define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)\r
56\r
57/**\r
58 To types of ICMP error which consist of ICMP header, IP header and original \r
59 datagram's data, get length from sum of ICMP header length, IP header length \r
60 and first 64 bits of datagram's data length.\r
61 \r
62 @param[in] IpHdr A pointer to EFI_IP4_HEADER\r
63 \r
64 @return The ICMP error length\r
65**/\r
66#define ICMP_ERRLEN(IpHdr) \\r
67 (sizeof(IP4_ICMP_HEAD) + EFI_IP4_HEADER_LEN(IpHdr) + 8)\r
68\r
69/**\r
70 Get the packet header from NET_BUF.\r
71 \r
72 @param[out] Buf A pointer to NET_BUF\r
73 @param[in] Type Header type\r
74 \r
75 @return The pointer to packet header\r
76**/\r
77#define NET_PROTO_HDR(Buf, Type) ((Type *) ((Buf)->BlockOp[0].Head))\r
78\r
79 \r
80extern EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData;\r
81\r
e29a2e7e 82///\r
83/// This error will be delivered to the\r
84/// listening transportation layer protocol\r
85/// that consumes IpIO.\r
86///\r
97b38d4e 87typedef enum {\r
88 ICMP_ERR_UNREACH_NET = 0,\r
89 ICMP_ERR_UNREACH_HOST,\r
90 ICMP_ERR_UNREACH_PROTOCOL,\r
91 ICMP_ERR_UNREACH_PORT,\r
92 ICMP_ERR_MSGSIZE,\r
93 ICMP_ERR_UNREACH_SRCFAIL,\r
94 ICMP_ERR_TIMXCEED_INTRANS,\r
95 ICMP_ERR_TIMXCEED_REASS,\r
96 ICMP_ERR_QUENCH,\r
97 ICMP_ERR_PARAMPROB\r
98} ICMP_ERROR;\r
99\r
e29a2e7e 100///\r
e9b67286 101/// The helper struct for IpIoGetIcmpErrStatus(). It is for internal use only.\r
e29a2e7e 102///\r
cdfdbb97 103typedef struct {\r
97b38d4e 104 BOOLEAN IsHard;\r
105 BOOLEAN Notify;\r
106} ICMP_ERROR_INFO;\r
107\r
e29a2e7e 108///\r
109/// The IP session for an IP receive packet.\r
110///\r
97b38d4e 111typedef struct _EFI_NET_SESSION_DATA {\r
e29a2e7e 112 IP4_ADDR Source; ///< Source IP of the received packet\r
113 IP4_ADDR Dest; ///< Destination IP of the received packet\r
114 EFI_IP4_HEADER *IpHdr; ///< IP4 header of the received packet\r
97b38d4e 115} EFI_NET_SESSION_DATA;\r
116\r
e29a2e7e 117/**\r
118 The prototype is called back when an IP packet is received.\r
119 \r
cdfdbb97 120 @param[in] Status Result of the receive request\r
121 @param[in] IcmpErr Valid when Status is EFI_ICMP_ERROR\r
122 @param[in] NetSession The IP session for the received packet\r
123 @param[in] Pkt Packet received\r
e9b67286 124 @param[in] Context The data provided by the user for the received packet when\r
cdfdbb97 125 the callback is registered in IP_IO_OPEN_DATA::RcvdContext.\r
e29a2e7e 126 \r
127**/\r
97b38d4e 128typedef\r
129VOID\r
130(*PKT_RCVD_NOTIFY) (\r
e29a2e7e 131 IN EFI_STATUS Status, \r
132 IN ICMP_ERROR IcmpErr,\r
133 IN EFI_NET_SESSION_DATA *NetSession,\r
134 IN NET_BUF *Pkt,\r
135 IN VOID *Context\r
97b38d4e 136 );\r
137\r
e29a2e7e 138/**\r
139 The prototype is called back when an IP packet is sent.\r
140 \r
cdfdbb97 141 @param[in] Status Result of the sending\r
142 @param[in] Context The data provided by user for the received packet when\r
143 the callback is registered in IP_IO_OPEN_DATA::SndContext.\r
144 @param[in] Sender A pointer to EFI_IP4_PROTOCOL for sender\r
145 @param[in] NotifyData Context data specified when calling IpIoSend()\r
e29a2e7e 146 \r
147**/\r
97b38d4e 148typedef\r
149VOID\r
150(*PKT_SENT_NOTIFY) (\r
e29a2e7e 151 IN EFI_STATUS Status,\r
152 IN VOID *Context,\r
153 IN VOID *Sender,\r
154 IN VOID *NotifyData\r
97b38d4e 155 );\r
156\r
e29a2e7e 157///\r
e9b67286 158/// This data structure wraps Ip4 instances. The IpIo Library uses it for all\r
e29a2e7e 159/// Ip4 operations.\r
160///\r
97b38d4e 161typedef struct _IP_IO {\r
e29a2e7e 162 ///\r
163 /// The node used to link this IpIo to the active IpIo list.\r
164 ///\r
97b38d4e 165 LIST_ENTRY Entry;\r
166\r
e29a2e7e 167 ///\r
168 /// The list used to maintain the IP instance for different sending purpose.\r
169 ///\r
97b38d4e 170 LIST_ENTRY IpList;\r
e29a2e7e 171 \r
97b38d4e 172 EFI_HANDLE Controller;\r
173 EFI_HANDLE Image;\r
174 EFI_HANDLE ChildHandle;\r
e29a2e7e 175 //\r
176 // The IP instance consumed by this IP_IO\r
177 //\r
97b38d4e 178 EFI_IP4_PROTOCOL *Ip;\r
179 BOOLEAN IsConfigured;\r
180\r
e29a2e7e 181 ///\r
cdfdbb97 182 /// Some ip config data can be changed\r
e29a2e7e 183 ///\r
97b38d4e 184 UINT8 Protocol;\r
185\r
e29a2e7e 186 ///\r
187 /// Token and event used to get data from IP\r
188 ///\r
97b38d4e 189 EFI_IP4_COMPLETION_TOKEN RcvToken;\r
190\r
e29a2e7e 191 ///\r
192 /// List entry used to link the token passed to IP_IO\r
193 ///\r
97b38d4e 194 LIST_ENTRY PendingSndList;\r
195\r
196 //\r
197 // User interface used to get notify from IP_IO\r
198 //\r
e29a2e7e 199 VOID *RcvdContext; ///< See IP_IO_OPEN_DATA::RcvdContext\r
200 VOID *SndContext; ///< See IP_IO_OPEN_DATA::SndContext\r
201 PKT_RCVD_NOTIFY PktRcvdNotify; ///< See IP_IO_OPEN_DATA::PktRcvdNotify\r
202 PKT_SENT_NOTIFY PktSentNotify; ///< See IP_IO_OPEN_DATA::PktSentNotify\r
97b38d4e 203} IP_IO;\r
204\r
e29a2e7e 205///\r
e9b67286 206/// The struct is for the user to pass IP configuration and callbacks to IP_IO.\r
e29a2e7e 207/// It is used by IpIoOpen().\r
208///\r
97b38d4e 209typedef struct _IP_IO_OPEN_DATA {\r
e29a2e7e 210 EFI_IP4_CONFIG_DATA IpConfigData; ///< Configuration of the IP instance\r
211 VOID *RcvdContext; ///< Context data used by receive callback\r
212 VOID *SndContext; ///< Context data used by send callback\r
213 PKT_RCVD_NOTIFY PktRcvdNotify; ///< Receive callback\r
214 PKT_SENT_NOTIFY PktSentNotify; ///< Send callback\r
97b38d4e 215} IP_IO_OPEN_DATA;\r
216\r
e29a2e7e 217///\r
218/// Internal struct book-keeping send request of IP_IO.\r
219///\r
220/// An IP_IO_SEND_ENTRY will be created each time a send request is issued to\r
221/// IP_IO via IpIoSend().\r
222///\r
97b38d4e 223typedef struct _IP_IO_SEND_ENTRY {\r
224 LIST_ENTRY Entry;\r
225 IP_IO *IpIo;\r
226 VOID *Context;\r
227 VOID *NotifyData;\r
228 EFI_IP4_PROTOCOL *Ip;\r
229 NET_BUF *Pkt;\r
230 EFI_IP4_COMPLETION_TOKEN *SndToken;\r
231} IP_IO_SEND_ENTRY;\r
232\r
233typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE;\r
234\r
e29a2e7e 235///\r
236/// The IP_IO_IP_INFO is used in IpIoSend() to override the default IP instance\r
237/// in IP_IO.\r
238///\r
97b38d4e 239typedef struct _IP_IO_IP_INFO {\r
240 IP4_ADDR Addr;\r
241 IP4_ADDR SubnetMask;\r
242 LIST_ENTRY Entry;\r
243 EFI_HANDLE ChildHandle;\r
244 EFI_IP4_PROTOCOL *Ip;\r
245 EFI_IP4_COMPLETION_TOKEN DummyRcvToken;\r
246 INTN RefCnt;\r
247} IP_IO_IP_INFO;\r
248\r
249/**\r
250 Create a new IP_IO instance.\r
e29a2e7e 251 \r
252 This function uses IP4 service binding protocol in Controller to create an IP4\r
253 child (aka IP4 instance).\r
97b38d4e 254\r
cdfdbb97 255 @param[in] Image The image handle of the driver or application that\r
e29a2e7e 256 consumes IP_IO.\r
cdfdbb97 257 @param[in] Controller The controller handle that has IP4 service binding\r
e29a2e7e 258 protocol installed.\r
97b38d4e 259\r
e29a2e7e 260 @return Pointer to a newly created IP_IO instance, or NULL if failed.\r
97b38d4e 261\r
262**/\r
263IP_IO *\r
264EFIAPI\r
265IpIoCreate (\r
266 IN EFI_HANDLE Image,\r
267 IN EFI_HANDLE Controller\r
268 );\r
269\r
270/**\r
271 Destroy an IP_IO instance.\r
e29a2e7e 272 \r
273 This function is paired with IpIoCreate(). The IP_IO will be closed first.\r
274 Resource will be freed afterwards. See IpIoClose().\r
97b38d4e 275\r
cdfdbb97 276 @param[in, out] IpIo Pointer to the IP_IO instance that needs to be\r
e29a2e7e 277 destroyed.\r
97b38d4e 278\r
cdfdbb97 279 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.\r
280 @retval Others Error condition occurred.\r
97b38d4e 281\r
282**/\r
283EFI_STATUS\r
284EFIAPI\r
285IpIoDestroy (\r
cdfdbb97 286 IN OUT IP_IO *IpIo\r
97b38d4e 287 );\r
288\r
289/**\r
290 Stop an IP_IO instance.\r
e29a2e7e 291 \r
e9b67286 292 This function is paired with IpIoOpen(). The IP_IO will be unconfigured, and all\r
293 pending send/receive tokens will be canceled.\r
97b38d4e 294\r
cdfdbb97 295 @param[in, out] IpIo Pointer to the IP_IO instance that needs to stop.\r
97b38d4e 296\r
cdfdbb97 297 @retval EFI_SUCCESS The IP_IO instance stopped successfully.\r
298 @retval Others Error condition occurred.\r
97b38d4e 299\r
300**/\r
301EFI_STATUS\r
302EFIAPI\r
303IpIoStop (\r
cdfdbb97 304 IN OUT IP_IO *IpIo\r
97b38d4e 305 );\r
306\r
307/**\r
308 Open an IP_IO instance for use.\r
e29a2e7e 309 \r
310 This function is called after IpIoCreate(). It is used for configuring the IP\r
311 instance and register the callbacks and their context data for sending and\r
312 receiving IP packets.\r
97b38d4e 313\r
cdfdbb97 314 @param[in, out] IpIo Pointer to an IP_IO instance that needs\r
315 to open.\r
316 @param[in] OpenData The configuration data and callbacks for\r
317 the IP_IO instance.\r
97b38d4e 318\r
cdfdbb97 319 @retval EFI_SUCCESS The IP_IO instance opened with OpenData\r
320 successfully.\r
321 @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to \r
322 reopen it.\r
323 @retval Others Error condition occurred.\r
97b38d4e 324\r
325**/\r
326EFI_STATUS\r
e29a2e7e 327EFIAPI\r
97b38d4e 328IpIoOpen (\r
cdfdbb97 329 IN OUT IP_IO *IpIo,\r
330 IN IP_IO_OPEN_DATA *OpenData\r
97b38d4e 331 );\r
332\r
333/**\r
334 Send out an IP packet.\r
e29a2e7e 335 \r
336 This function is called after IpIoOpen(). The data to be sent are wrapped in\r
e9b67286 337 Pkt. The IP instance wrapped in IpIo is used for sending by default, but can be\r
338 overriden by Sender. Other sending configurations, such as source address and gateway\r
339 address, are specified in OverrideData.\r
97b38d4e 340\r
cdfdbb97 341 @param[in, out] IpIo Pointer to an IP_IO instance used for sending IP\r
342 packet.\r
343 @param[in, out] Pkt Pointer to the IP packet to be sent.\r
e9b67286 344 @param[in] Sender Optional. The IP protocol instance used for sending.\r
3a1ab4bc 345 @param[in] Context Optional context data.\r
346 @param[in] NotifyData Optional notify data.\r
cdfdbb97 347 @param[in] Dest The destination IP address to send this packet to.\r
348 @param[in] OverrideData The data to override some configuration of the IP\r
349 instance used for sending.\r
97b38d4e 350\r
cdfdbb97 351 @retval EFI_SUCCESS The operation is completed successfully.\r
352 @retval EFI_NOT_STARTED The IpIo is not configured.\r
353 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.\r
97b38d4e 354\r
355**/\r
356EFI_STATUS\r
357EFIAPI\r
358IpIoSend (\r
cdfdbb97 359 IN OUT IP_IO *IpIo,\r
360 IN OUT NET_BUF *Pkt,\r
361 IN IP_IO_IP_INFO *Sender OPTIONAL,\r
362 IN VOID *Context OPTIONAL,\r
363 IN VOID *NotifyData OPTIONAL,\r
364 IN IP4_ADDR Dest,\r
365 IN IP_IO_OVERRIDE *OverrideData OPTIONAL\r
97b38d4e 366 );\r
367\r
368/**\r
369 Cancel the IP transmit token which wraps this Packet.\r
370\r
cdfdbb97 371 @param[in] IpIo Pointer to the IP_IO instance.\r
372 @param[in] Packet Pointer to the packet of NET_BUF to cancel.\r
97b38d4e 373\r
374**/\r
375VOID\r
376EFIAPI\r
377IpIoCancelTxToken (\r
378 IN IP_IO *IpIo,\r
379 IN VOID *Packet\r
380 );\r
381\r
382/**\r
383 Add a new IP instance for sending data.\r
e29a2e7e 384 \r
385 The function is used to add the IP_IO to the IP_IO sending list. The caller\r
386 can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to send\r
387 data.\r
97b38d4e 388\r
e9b67286 389 @param[in, out] IpIo Pointer to an IP_IO instance to add a new IP\r
390 instance for sending purposes.\r
97b38d4e 391\r
e29a2e7e 392 @return Pointer to the created IP_IO_IP_INFO structure, NULL if failed.\r
97b38d4e 393\r
394**/\r
395IP_IO_IP_INFO *\r
396EFIAPI\r
397IpIoAddIp (\r
cdfdbb97 398 IN OUT IP_IO *IpIo\r
97b38d4e 399 );\r
400\r
401/**\r
402 Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData\r
403 is not NULL.\r
404\r
cdfdbb97 405 @param[in, out] IpInfo Pointer to the IP_IO_IP_INFO instance.\r
406 @param[in, out] Ip4ConfigData The IP4 configure data used to configure the IP\r
e9b67286 407 instance. If NULL, the IP instance is reset. If\r
cdfdbb97 408 UseDefaultAddress is set to TRUE, and the configure\r
409 operation succeeds, the default address information\r
410 is written back in this Ip4ConfigData.\r
97b38d4e 411\r
e9b67286 412 @retval EFI_SUCCESS The IP instance of this IpInfo is configured successfully,\r
413 or there is no need to reconfigure it.\r
414 @retval Others Configuration failed.\r
97b38d4e 415\r
416**/\r
417EFI_STATUS\r
418EFIAPI\r
419IpIoConfigIp (\r
cdfdbb97 420 IN OUT IP_IO_IP_INFO *IpInfo,\r
97b38d4e 421 IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData OPTIONAL\r
422 );\r
423\r
424/**\r
425 Destroy an IP instance maintained in IpIo->IpList for\r
426 sending purpose.\r
e29a2e7e 427 \r
428 This function pairs with IpIoAddIp(). The IpInfo is previously created by\r
429 IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance\r
430 will be dstroyed if the RefCnt is zero.\r
97b38d4e 431\r
cdfdbb97 432 @param[in] IpIo Pointer to the IP_IO instance.\r
433 @param[in] IpInfo Pointer to the IpInfo to be removed.\r
97b38d4e 434\r
97b38d4e 435**/\r
436VOID\r
437EFIAPI\r
438IpIoRemoveIp (\r
439 IN IP_IO *IpIo,\r
440 IN IP_IO_IP_INFO *IpInfo\r
441 );\r
442\r
443/**\r
444 Find the first IP protocol maintained in IpIo whose local\r
e9b67286 445 address is the same as Src.\r
e29a2e7e 446 \r
447 This function is called when the caller needs the IpIo to send data to the\r
448 specified Src. The IpIo was added previously by IpIoAddIp().\r
97b38d4e 449\r
cdfdbb97 450 @param[in, out] IpIo Pointer to the pointer of the IP_IO instance.\r
451 @param[in] Src The local IP address.\r
97b38d4e 452\r
453 @return Pointer to the IP protocol can be used for sending purpose and its local\r
e29a2e7e 454 address is the same with Src.\r
97b38d4e 455\r
456**/\r
457IP_IO_IP_INFO *\r
458EFIAPI\r
459IpIoFindSender (\r
460 IN OUT IP_IO **IpIo,\r
461 IN IP4_ADDR Src\r
462 );\r
463\r
464/**\r
e29a2e7e 465 Get the ICMP error map information.\r
466 \r
467 The ErrorStatus will be returned. The IsHard and Notify are optional. If they\r
468 are not NULL, this routine will fill them.\r
97b38d4e 469\r
3a1ab4bc 470 @param[in] IcmpError IcmpError Type.\r
471 @param[out] IsHard Whether it is a hard error.\r
472 @param[out] Notify Whether it need to notify SockError.\r
97b38d4e 473\r
cdfdbb97 474 @return ICMP Error Status, such as EFI_NETWORK_UNREACHABLE.\r
97b38d4e 475\r
476**/\r
477EFI_STATUS\r
478EFIAPI\r
479IpIoGetIcmpErrStatus (\r
480 IN ICMP_ERROR IcmpError,\r
e29a2e7e 481 OUT BOOLEAN *IsHard OPTIONAL,\r
482 OUT BOOLEAN *Notify OPTIONAL\r
97b38d4e 483 );\r
484\r
485#endif\r