]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Include/Library/IpIoLib.h
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Include / Library / IpIoLib.h
1 /** @file
2 This library is only intended to be used by UEFI network stack modules.
3 It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6 protocol.
4
5 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _IP_IO_H_
11 #define _IP_IO_H_
12
13 #include <Protocol/Ip4.h>
14 #include <Protocol/Ip6.h>
15
16 #include <Library/NetLib.h>
17
18 //
19 // type and code define for ICMP protocol error
20 // from IP
21 //
22 #define ICMP_TYPE_UNREACH 3
23 #define ICMP_TYPE_TIMXCEED 11
24 #define ICMP_TYPE_PARAMPROB 12
25 #define ICMP_TYPE_SOURCEQUENCH 4
26
27 #define ICMP_CODE_UNREACH_NET 0
28 #define ICMP_CODE_UNREACH_HOST 1
29 #define ICMP_CODE_UNREACH_PROTOCOL 2
30 #define ICMP_CODE_UNREACH_PORT 3
31 #define ICMP_CODE_UNREACH_NEEDFRAG 4
32 #define ICMP_CODE_UNREACH_SRCFAIL 5
33 #define ICMP_CODE_UNREACH_NET_UNKNOWN 6
34 #define ICMP_CODE_UNREACH_HOST_UNKNOWN 7
35 #define ICMP_CODE_UNREACH_ISOLATED 8
36 #define ICMP_CODE_UNREACH_NET_PROHIB 9
37 #define ICMP_CODE_UNREACH_HOST_PROHIB 10
38 #define ICMP_CODE_UNREACH_TOSNET 11
39 #define ICMP_CODE_UNREACH_TOSHOST 12
40
41 /**
42 Get the IP header length from the struct EFI_IP4_HEADER. HeaderLength is
43 Internet header length in 32-bit words, so HeaderLength<<2 is the real
44 length of IP header.
45
46 @param[out] HdrPtr A pointer to EFI_IP4_HEADER.
47
48 @return The IP header length.
49 **/
50 #define EFI_IP4_HEADER_LEN(HdrPtr) ((HdrPtr)->HeaderLength << 2)
51
52 /**
53 To types of ICMP error which consist of ICMP header, IP header and original
54 datagram's data, get length from sum of ICMP header length, IP header length
55 and first 64 bits of datagram's data length.
56
57 @param[in] IpHdr A pointer to EFI_IP4_HEADER.
58
59 @return The ICMP error length.
60 **/
61 #define ICMP_ERRLEN(IpHdr) \
62 (sizeof(IP4_ICMP_HEAD) + EFI_IP4_HEADER_LEN(IpHdr) + 8)
63
64 /**
65 Get the packet header from NET_BUF.
66
67 @param[out] Buf A pointer to NET_BUF.
68 @param[in] Type Header type.
69
70 @return The pointer to packet header.
71 **/
72 #define NET_PROTO_HDR(Buf, Type) ((Type *) ((Buf)->BlockOp[0].Head))
73
74 extern EFI_IP4_CONFIG_DATA mIp4IoDefaultIpConfigData;
75 extern EFI_IP6_CONFIG_DATA mIp6IoDefaultIpConfigData;
76
77 ///
78 /// This error will be delivered to the
79 /// listening transportation layer protocol
80 /// that consumes IpIO.
81 ///
82
83 #define ICMP_ERR_UNREACH_NET 0
84 #define ICMP_ERR_UNREACH_HOST 1
85 #define ICMP_ERR_UNREACH_PROTOCOL 2
86 #define ICMP_ERR_UNREACH_PORT 3
87 #define ICMP_ERR_MSGSIZE 4
88 #define ICMP_ERR_UNREACH_SRCFAIL 5
89 #define ICMP_ERR_TIMXCEED_INTRANS 6
90 #define ICMP_ERR_TIMXCEED_REASS 7
91 #define ICMP_ERR_QUENCH 8
92 #define ICMP_ERR_PARAMPROB 9
93
94 #define ICMP6_ERR_UNREACH_NET 0
95 #define ICMP6_ERR_UNREACH_HOST 1
96 #define ICMP6_ERR_UNREACH_PROTOCOL 2
97 #define ICMP6_ERR_UNREACH_PORT 3
98 #define ICMP6_ERR_PACKAGE_TOOBIG 4
99 #define ICMP6_ERR_TIMXCEED_HOPLIMIT 5
100 #define ICMP6_ERR_TIMXCEED_REASS 6
101 #define ICMP6_ERR_PARAMPROB_HEADER 7
102 #define ICMP6_ERR_PARAMPROB_NEXHEADER 8
103 #define ICMP6_ERR_PARAMPROB_IPV6OPTION 9
104
105 ///
106 /// The helper struct for IpIoGetIcmpErrStatus(). It is for internal use only.
107 ///
108 typedef struct {
109 BOOLEAN IsHard;
110 BOOLEAN Notify;
111 } ICMP_ERROR_INFO;
112
113 typedef union {
114 EFI_IP4_COMPLETION_TOKEN Ip4Token;
115 EFI_IP6_COMPLETION_TOKEN Ip6Token;
116 } IP_IO_IP_COMPLETION_TOKEN;
117
118 typedef union {
119 EFI_IP4_TRANSMIT_DATA Ip4TxData;
120 EFI_IP6_TRANSMIT_DATA Ip6TxData;
121 } IP_IO_IP_TX_DATA;
122
123 typedef union {
124 EFI_IP4_RECEIVE_DATA Ip4RxData;
125 EFI_IP6_RECEIVE_DATA Ip6RxData;
126 } IP_IO_IP_RX_DATA;
127
128 typedef union {
129 EFI_IP4_OVERRIDE_DATA Ip4OverrideData;
130 EFI_IP6_OVERRIDE_DATA Ip6OverrideData;
131 } IP_IO_OVERRIDE;
132
133 typedef union {
134 EFI_IP4_CONFIG_DATA Ip4CfgData;
135 EFI_IP6_CONFIG_DATA Ip6CfgData;
136 } IP_IO_IP_CONFIG_DATA;
137
138 typedef union {
139 EFI_IP4_HEADER *Ip4Hdr;
140 EFI_IP6_HEADER *Ip6Hdr;
141 } IP_IO_IP_HEADER;
142
143 typedef union {
144 IP4_ADDR SubnetMask;
145 UINT8 PrefixLength;
146 } IP_IO_IP_MASK;
147
148 typedef union {
149 EFI_IP4_PROTOCOL *Ip4;
150 EFI_IP6_PROTOCOL *Ip6;
151 } IP_IO_IP_PROTOCOL;
152
153 ///
154 /// The IP session for an IP receive packet.
155 ///
156 typedef struct _EFI_NET_SESSION_DATA {
157 EFI_IP_ADDRESS Source; ///< Source IP of the received packet.
158 EFI_IP_ADDRESS Dest; ///< Destination IP of the received packet.
159 IP_IO_IP_HEADER IpHdr; ///< IP header of the received packet.
160 UINT32 IpHdrLen; ///< IP header length of the received packet.
161 ///< For IPv6, it includes the IP6 header
162 ///< length and extension header length. For
163 ///< IPv4, it includes the IP4 header length
164 ///< and options length.
165 UINT8 IpVersion; ///< The IP version of the received packet.
166 } EFI_NET_SESSION_DATA;
167
168 /**
169 The prototype is called back when an IP packet is received.
170
171 @param[in] Status The result of the receive request.
172 @param[in] IcmpErr Valid when Status is EFI_ICMP_ERROR.
173 @param[in] NetSession The IP session for the received packet.
174 @param[in] Pkt The packet received.
175 @param[in] Context The data provided by the user for the received packet when
176 the callback is registered in IP_IO_OPEN_DATA::RcvdContext.
177
178 **/
179 typedef
180 VOID
181 (EFIAPI *PKT_RCVD_NOTIFY)(
182 IN EFI_STATUS Status,
183 IN UINT8 IcmpErr,
184 IN EFI_NET_SESSION_DATA *NetSession,
185 IN NET_BUF *Pkt,
186 IN VOID *Context
187 );
188
189 /**
190 The prototype is called back when an IP packet is sent.
191
192 @param[in] Status Result of the IP packet being sent.
193 @param[in] Context The data provided by user for the received packet when
194 the callback is registered in IP_IO_OPEN_DATA::SndContext.
195 @param[in] Sender A Union type to specify a pointer of EFI_IP4_PROTOCOL
196 or EFI_IP6_PROTOCOL.
197 @param[in] NotifyData The Context data specified when calling IpIoSend()
198
199 **/
200 typedef
201 VOID
202 (EFIAPI *PKT_SENT_NOTIFY)(
203 IN EFI_STATUS Status,
204 IN VOID *Context,
205 IN IP_IO_IP_PROTOCOL Sender,
206 IN VOID *NotifyData
207 );
208
209 ///
210 /// This data structure wraps Ip4/Ip6 instances. The IpIo Library uses it for all
211 /// Ip4/Ip6 operations.
212 ///
213 typedef struct _IP_IO {
214 ///
215 /// The node used to link this IpIo to the active IpIo list.
216 ///
217 LIST_ENTRY Entry;
218
219 ///
220 /// The list used to maintain the IP instance for different sending purpose.
221 ///
222 LIST_ENTRY IpList;
223
224 EFI_HANDLE Controller;
225 EFI_HANDLE Image;
226 EFI_HANDLE ChildHandle;
227 //
228 // The IP instance consumed by this IP_IO
229 //
230 IP_IO_IP_PROTOCOL Ip;
231 BOOLEAN IsConfigured;
232
233 ///
234 /// Some ip configuration data can be changed.
235 ///
236 UINT8 Protocol;
237
238 ///
239 /// Token and event used to get data from IP.
240 ///
241 IP_IO_IP_COMPLETION_TOKEN RcvToken;
242
243 ///
244 /// List entry used to link the token passed to IP_IO.
245 ///
246 LIST_ENTRY PendingSndList;
247
248 //
249 // User interface used to get notify from IP_IO
250 //
251 VOID *RcvdContext; ///< See IP_IO_OPEN_DATA::RcvdContext.
252 VOID *SndContext; ///< See IP_IO_OPEN_DATA::SndContext.
253 PKT_RCVD_NOTIFY PktRcvdNotify; ///< See IP_IO_OPEN_DATA::PktRcvdNotify.
254 PKT_SENT_NOTIFY PktSentNotify; ///< See IP_IO_OPEN_DATA::PktSentNotify.
255 UINT8 IpVersion;
256 IP4_ADDR StationIp;
257 IP4_ADDR SubnetMask;
258 } IP_IO;
259
260 ///
261 /// The struct is for the user to pass IP configuration and callbacks to IP_IO.
262 /// It is used by IpIoOpen().
263 ///
264 typedef struct _IP_IO_OPEN_DATA {
265 IP_IO_IP_CONFIG_DATA IpConfigData; ///< Configuration of the IP instance.
266 VOID *RcvdContext; ///< Context data used by receive callback.
267 VOID *SndContext; ///< Context data used by send callback.
268 PKT_RCVD_NOTIFY PktRcvdNotify; ///< Receive callback.
269 PKT_SENT_NOTIFY PktSentNotify; ///< Send callback.
270 } IP_IO_OPEN_DATA;
271
272 ///
273 /// Internal struct book-keeping send request of IP_IO.
274 ///
275 /// An IP_IO_SEND_ENTRY will be created each time a send request is issued to
276 /// IP_IO via IpIoSend().
277 ///
278 typedef struct _IP_IO_SEND_ENTRY {
279 LIST_ENTRY Entry;
280 IP_IO *IpIo;
281 VOID *Context;
282 VOID *NotifyData;
283 IP_IO_IP_PROTOCOL Ip;
284 NET_BUF *Pkt;
285 IP_IO_IP_COMPLETION_TOKEN SndToken;
286 } IP_IO_SEND_ENTRY;
287
288 ///
289 /// The IP_IO_IP_INFO is used in IpIoSend() to override the default IP instance
290 /// in IP_IO.
291 ///
292 typedef struct _IP_IO_IP_INFO {
293 EFI_IP_ADDRESS Addr;
294 IP_IO_IP_MASK PreMask;
295 LIST_ENTRY Entry;
296 EFI_HANDLE ChildHandle;
297 IP_IO_IP_PROTOCOL Ip;
298 IP_IO_IP_COMPLETION_TOKEN DummyRcvToken;
299 INTN RefCnt;
300 UINT8 IpVersion;
301 } IP_IO_IP_INFO;
302
303 /**
304 Create a new IP_IO instance.
305
306 If IpVersion is not IP_VERSION_4 or IP_VERSION_6, then ASSERT().
307
308 This function uses IP4/IP6 service binding protocol in Controller to create
309 an IP4/IP6 child (aka IP4/IP6 instance).
310
311 @param[in] Image The image handle of the driver or application that
312 consumes IP_IO.
313 @param[in] Controller The controller handle that has IP4 or IP6 service
314 binding protocol installed.
315 @param[in] IpVersion The version of the IP protocol to use, either
316 IPv4 or IPv6.
317
318 @return The pointer to a newly created IP_IO instance, or NULL if failed.
319
320 **/
321 IP_IO *
322 EFIAPI
323 IpIoCreate (
324 IN EFI_HANDLE Image,
325 IN EFI_HANDLE Controller,
326 IN UINT8 IpVersion
327 );
328
329 /**
330 Destroy an IP_IO instance.
331
332 This function is paired with IpIoCreate(). The IP_IO will be closed first.
333 Resource will be freed afterwards. See IpIoClose().
334
335 @param[in, out] IpIo The pointer to the IP_IO instance that needs to be
336 destroyed.
337
338 @retval EFI_SUCCESS The IP_IO instance was destroyed successfully.
339 @retval Others An error condition occurred.
340
341 **/
342 EFI_STATUS
343 EFIAPI
344 IpIoDestroy (
345 IN OUT IP_IO *IpIo
346 );
347
348 /**
349 Stop an IP_IO instance.
350
351 If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT().
352
353 This function is paired with IpIoOpen(). The IP_IO will be unconfigured, and all
354 pending send/receive tokens will be canceled.
355
356 @param[in, out] IpIo The pointer to the IP_IO instance that needs to stop.
357
358 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
359 @retval EFI_INVALID_PARAMETER Invalid input parameter.
360 @retval Others Anrror condition occurred.
361
362 **/
363 EFI_STATUS
364 EFIAPI
365 IpIoStop (
366 IN OUT IP_IO *IpIo
367 );
368
369 /**
370 Open an IP_IO instance for use.
371
372 If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT().
373
374 This function is called after IpIoCreate(). It is used for configuring the IP
375 instance and register the callbacks and their context data for sending and
376 receiving IP packets.
377
378 @param[in, out] IpIo The pointer to an IP_IO instance that needs
379 to open.
380 @param[in] OpenData The configuration data and callbacks for
381 the IP_IO instance.
382
383 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
384 successfully.
385 @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to
386 reopen it.
387 @retval EFI_UNSUPPORTED IPv4 RawData mode is no supported.
388 @retval EFI_INVALID_PARAMETER Invalid input parameter.
389 @retval Others Error condition occurred.
390
391 **/
392 EFI_STATUS
393 EFIAPI
394 IpIoOpen (
395 IN OUT IP_IO *IpIo,
396 IN IP_IO_OPEN_DATA *OpenData
397 );
398
399 /**
400 Send out an IP packet.
401
402 This function is called after IpIoOpen(). The data to be sent is wrapped in
403 Pkt. The IP instance wrapped in IpIo is used for sending by default but can be
404 overridden by Sender. Other sending configs, like source address and gateway
405 address etc., are specified in OverrideData.
406
407 @param[in, out] IpIo Pointer to an IP_IO instance used for sending IP
408 packet.
409 @param[in, out] Pkt Pointer to the IP packet to be sent.
410 @param[in] Sender The IP protocol instance used for sending.
411 @param[in] Context Optional context data.
412 @param[in] NotifyData Optional notify data.
413 @param[in] Dest The destination IP address to send this packet to.
414 This parameter is optional when using IPv6.
415 @param[in] OverrideData The data to override some configuration of the IP
416 instance used for sending.
417
418 @retval EFI_SUCCESS The operation is completed successfully.
419 @retval EFI_INVALID_PARAMETER The input parameter is not correct.
420 @retval EFI_NOT_STARTED The IpIo is not configured.
421 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
422 @retval Others Error condition occurred.
423
424 **/
425 EFI_STATUS
426 EFIAPI
427 IpIoSend (
428 IN OUT IP_IO *IpIo,
429 IN OUT NET_BUF *Pkt,
430 IN IP_IO_IP_INFO *Sender OPTIONAL,
431 IN VOID *Context OPTIONAL,
432 IN VOID *NotifyData OPTIONAL,
433 IN EFI_IP_ADDRESS *Dest OPTIONAL,
434 IN IP_IO_OVERRIDE *OverrideData OPTIONAL
435 );
436
437 /**
438 Cancel the IP transmit token that wraps this Packet.
439
440 If IpIo is NULL, then ASSERT().
441 If Packet is NULL, then ASSERT().
442
443 @param[in] IpIo The pointer to the IP_IO instance.
444 @param[in] Packet The pointer to the packet of NET_BUF to cancel.
445
446 **/
447 VOID
448 EFIAPI
449 IpIoCancelTxToken (
450 IN IP_IO *IpIo,
451 IN VOID *Packet
452 );
453
454 /**
455 Add a new IP instance for sending data.
456
457 If IpIo is NULL, then ASSERT().
458 If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT().
459
460 The function is used to add the IP_IO to the IP_IO sending list. The caller
461 can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to send
462 data.
463
464 @param[in, out] IpIo The pointer to an IP_IO instance to add a new IP
465 instance for sending purposes.
466
467 @return The pointer to the created IP_IO_IP_INFO structure; NULL if failed.
468
469 **/
470 IP_IO_IP_INFO *
471 EFIAPI
472 IpIoAddIp (
473 IN OUT IP_IO *IpIo
474 );
475
476 /**
477 Configure the IP instance of this IpInfo and start the receiving if IpConfigData
478 is not NULL.
479
480 If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT().
481
482 @param[in, out] IpInfo The pointer to the IP_IO_IP_INFO instance.
483 @param[in, out] IpConfigData The IP4 or IP6 configure data used to configure
484 the IP instance. If NULL, the IP instance is reset.
485 If UseDefaultAddress is set to TRUE, and the configure
486 operation succeeds, the default address information
487 is written back in this IpConfigData.
488
489 @retval EFI_SUCCESS The IP instance of this IpInfo was configured successfully,
490 or there is no need to reconfigure it.
491 @retval Others The configuration failed.
492
493 **/
494 EFI_STATUS
495 EFIAPI
496 IpIoConfigIp (
497 IN OUT IP_IO_IP_INFO *IpInfo,
498 IN OUT VOID *IpConfigData OPTIONAL
499 );
500
501 /**
502 Destroy an IP instance maintained in IpIo->IpList for
503 sending purpose.
504
505 If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT().
506
507 This function pairs with IpIoAddIp(). The IpInfo is previously created by
508 IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance
509 will be destroyed if the RefCnt is zero.
510
511 @param[in] IpIo The pointer to the IP_IO instance.
512 @param[in] IpInfo The pointer to the IpInfo to be removed.
513
514 **/
515 VOID
516 EFIAPI
517 IpIoRemoveIp (
518 IN IP_IO *IpIo,
519 IN IP_IO_IP_INFO *IpInfo
520 );
521
522 /**
523 Find the first IP protocol maintained in IpIo whose local
524 address is the same as Src.
525
526 This function is called when the caller needs the IpIo to send data to the
527 specified Src. The IpIo was added previously by IpIoAddIp().
528
529 @param[in, out] IpIo The pointer to the pointer of the IP_IO instance.
530 @param[in] IpVersion The version of the IP protocol to use, either
531 IPv4 or IPv6.
532 @param[in] Src The local IP address.
533
534 @return The pointer to the IP protocol can be used for sending purpose and its local
535 address is the same with Src. NULL if failed.
536
537 **/
538 IP_IO_IP_INFO *
539 EFIAPI
540 IpIoFindSender (
541 IN OUT IP_IO **IpIo,
542 IN UINT8 IpVersion,
543 IN EFI_IP_ADDRESS *Src
544 );
545
546 /**
547 Get the ICMP error map information.
548
549 The ErrorStatus will be returned. The IsHard and Notify are optional. If they
550 are not NULL, this routine will fill them.
551
552 @param[in] IcmpError IcmpError Type.
553 @param[in] IpVersion The version of the IP protocol to use,
554 either IPv4 or IPv6.
555 @param[out] IsHard If TRUE, indicates that it is a hard error.
556 @param[out] Notify If TRUE, SockError needs to be notified.
557
558 @retval EFI_UNSUPPORTED Unrecognizable ICMP error code
559 @return The ICMP Error Status, such as EFI_NETWORK_UNREACHABLE.
560
561 **/
562 EFI_STATUS
563 EFIAPI
564 IpIoGetIcmpErrStatus (
565 IN UINT8 IcmpError,
566 IN UINT8 IpVersion,
567 OUT BOOLEAN *IsHard OPTIONAL,
568 OUT BOOLEAN *Notify OPTIONAL
569 );
570
571 /**
572 Refresh the remote peer's Neighbor Cache entries.
573
574 This function is called when the caller needs the IpIo to refresh the existing
575 IPv6 neighbor cache entries since the neighbor is considered reachable by the
576 node has recently received a confirmation that packets sent recently to the
577 neighbor were received by its IP layer.
578
579 @param[in] IpIo The pointer to an IP_IO instance
580 @param[in] Neighbor The IP address of the neighbor
581 @param[in] Timeout The time in 100-ns units that this entry will
582 remain in the neighbor cache. A value of
583 zero means that the entry is permanent.
584 A value of non-zero means that the entry is
585 dynamic and will be deleted after Timeout.
586
587 @retval EFI_SUCCESS The operation completed successfully.
588 @retval EFI_NOT_STARTED The IpIo is not configured.
589 @retval EFI_INVALID_PARAMETER The Neighbor Address is invalid.
590 @retval EFI_NOT_FOUND The neighbor cache entry is not in the
591 neighbor table.
592 @retval EFI_UNSUPPORTED IP version is IPv4, which doesn't support neighbor cache refresh.
593 @retval EFI_OUT_OF_RESOURCES Failed due to resource limitations.
594
595 **/
596 EFI_STATUS
597 EFIAPI
598 IpIoRefreshNeighbor (
599 IN IP_IO *IpIo,
600 IN EFI_IP_ADDRESS *Neighbor,
601 IN UINT32 Timeout
602 );
603
604 #endif