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