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