]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
032545b32baed319c1e1b1313926e63be3d67b0e
[mirror_edk2.git] / MdeModulePkg / Library / DxeIpIoLib / DxeIpIoLib.c
1 /** @file
2 IpIo Library.
3
4 Copyright (c) 2005 - 2009, Intel Corporation.<BR>
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 #include <Uefi.h>
15
16 #include <Protocol/Udp4.h>
17
18 #include <Library/IpIoLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/DpcLib.h>
25
26
27 LIST_ENTRY mActiveIpIoList = {
28 &mActiveIpIoList,
29 &mActiveIpIoList
30 };
31
32 EFI_IP4_CONFIG_DATA mIp4IoDefaultIpConfigData = {
33 EFI_IP_PROTO_UDP,
34 FALSE,
35 TRUE,
36 FALSE,
37 FALSE,
38 FALSE,
39 {{0, 0, 0, 0}},
40 {{0, 0, 0, 0}},
41 0,
42 255,
43 FALSE,
44 FALSE,
45 0,
46 0
47 };
48
49 EFI_IP6_CONFIG_DATA mIp6IoDefaultIpConfigData = {
50 EFI_IP_PROTO_UDP,
51 FALSE,
52 TRUE,
53 FALSE,
54 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
55 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
56 0,
57 255,
58 0,
59 0,
60 0
61 };
62
63 ICMP_ERROR_INFO mIcmpErrMap[10] = {
64 {FALSE, TRUE }, // ICMP_ERR_UNREACH_NET
65 {FALSE, TRUE }, // ICMP_ERR_UNREACH_HOST
66 {TRUE, TRUE }, // ICMP_ERR_UNREACH_PROTOCOL
67 {TRUE, TRUE }, // ICMP_ERR_UNREACH_PORT
68 {TRUE, TRUE }, // ICMP_ERR_MSGSIZE
69 {FALSE, TRUE }, // ICMP_ERR_UNREACH_SRCFAIL
70 {FALSE, TRUE }, // ICMP_ERR_TIMXCEED_INTRANS
71 {FALSE, TRUE }, // ICMP_ERR_TIMEXCEED_REASS
72 {FALSE, FALSE}, // ICMP_ERR_QUENCH
73 {FALSE, TRUE } // ICMP_ERR_PARAMPROB
74 };
75
76 ICMP_ERROR_INFO mIcmp6ErrMap[10] = {
77 {FALSE, TRUE}, // ICMP6_ERR_UNREACH_NET
78 {FALSE, TRUE}, // ICMP6_ERR_UNREACH_HOST
79 {TRUE, TRUE}, // ICMP6_ERR_UNREACH_PROTOCOL
80 {TRUE, TRUE}, // ICMP6_ERR_UNREACH_PORT
81 {TRUE, TRUE}, // ICMP6_ERR_PACKAGE_TOOBIG
82 {FALSE, TRUE}, // ICMP6_ERR_TIMXCEED_HOPLIMIT
83 {FALSE, TRUE}, // ICMP6_ERR_TIMXCEED_REASS
84 {FALSE, TRUE}, // ICMP6_ERR_PARAMPROB_HEADER
85 {FALSE, TRUE}, // ICMP6_ERR_PARAMPROB_NEXHEADER
86 {FALSE, TRUE} // ICMP6_ERR_PARAMPROB_IPV6OPTION
87 };
88
89
90 /**
91 Notify function for IP transmit token.
92
93 @param[in] Context The context passed in by the event notifier.
94
95 **/
96 VOID
97 EFIAPI
98 IpIoTransmitHandlerDpc (
99 IN VOID *Context
100 );
101
102
103 /**
104 Notify function for IP transmit token.
105
106 @param[in] Event The event signaled.
107 @param[in] Context The context passed in by the event notifier.
108
109 **/
110 VOID
111 EFIAPI
112 IpIoTransmitHandler (
113 IN EFI_EVENT Event,
114 IN VOID *Context
115 );
116
117
118 /**
119 This function create an IP child ,open the IP protocol, and return the opened
120 IP protocol as Interface.
121
122 @param[in] ControllerHandle The controller handle.
123 @param[in] ImageHandle The image handle.
124 @param[in] ChildHandle Pointer to the buffer to save the IP child handle.
125 @param[in] IpVersion The version of the IP protocol to use, either
126 IPv4 or IPv6.
127 @param[out] Interface Pointer used to get the IP protocol interface.
128
129 @retval EFI_SUCCESS The IP child is created and the IP protocol
130 interface is retrieved.
131 @retval Others The required operation failed.
132
133 **/
134 EFI_STATUS
135 IpIoCreateIpChildOpenProtocol (
136 IN EFI_HANDLE ControllerHandle,
137 IN EFI_HANDLE ImageHandle,
138 IN EFI_HANDLE *ChildHandle,
139 IN UINT8 IpVersion,
140 OUT VOID **Interface
141 )
142 {
143 EFI_STATUS Status;
144 EFI_GUID *ServiceBindingGuid;
145 EFI_GUID *IpProtocolGuid;
146
147 if (IpVersion == IP_VERSION_4) {
148 ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;
149 IpProtocolGuid = &gEfiIp4ProtocolGuid;
150 } else if (IpVersion == IP_VERSION_6){
151 ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;
152 IpProtocolGuid = &gEfiIp6ProtocolGuid;
153 } else {
154 return EFI_UNSUPPORTED;
155 }
156
157 //
158 // Create an IP child.
159 //
160 Status = NetLibCreateServiceChild (
161 ControllerHandle,
162 ImageHandle,
163 ServiceBindingGuid,
164 ChildHandle
165 );
166 if (EFI_ERROR (Status)) {
167 return Status;
168 }
169
170 //
171 // Open the IP protocol installed on the *ChildHandle.
172 //
173 Status = gBS->OpenProtocol (
174 *ChildHandle,
175 IpProtocolGuid,
176 Interface,
177 ImageHandle,
178 ControllerHandle,
179 EFI_OPEN_PROTOCOL_BY_DRIVER
180 );
181 if (EFI_ERROR (Status)) {
182 //
183 // On failure, destroy the IP child.
184 //
185 NetLibDestroyServiceChild (
186 ControllerHandle,
187 ImageHandle,
188 ServiceBindingGuid,
189 *ChildHandle
190 );
191 }
192
193 return Status;
194 }
195
196
197 /**
198 This function close the previously openned IP protocol and destroy the IP child.
199
200 @param[in] ControllerHandle The controller handle.
201 @param[in] ImageHandle The image handle.
202 @param[in] ChildHandle The child handle of the IP child.
203 @param[in] IpVersion The version of the IP protocol to use, either
204 IPv4 or IPv6.
205
206 @retval EFI_SUCCESS The IP protocol is closed and the relevant IP child
207 is destroyed.
208 @retval Others The required operation failed.
209
210 **/
211 EFI_STATUS
212 IpIoCloseProtocolDestroyIpChild (
213 IN EFI_HANDLE ControllerHandle,
214 IN EFI_HANDLE ImageHandle,
215 IN EFI_HANDLE ChildHandle,
216 IN UINT8 IpVersion
217 )
218 {
219 EFI_STATUS Status;
220 EFI_GUID *ServiceBindingGuid;
221 EFI_GUID *IpProtocolGuid;
222
223 if (IpVersion == IP_VERSION_4) {
224 ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;
225 IpProtocolGuid = &gEfiIp4ProtocolGuid;
226 } else if (IpVersion == IP_VERSION_6) {
227 ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;
228 IpProtocolGuid = &gEfiIp6ProtocolGuid;
229 } else {
230 return EFI_UNSUPPORTED;
231 }
232
233 //
234 // Close the previously openned IP protocol.
235 //
236 gBS->CloseProtocol (
237 ChildHandle,
238 IpProtocolGuid,
239 ImageHandle,
240 ControllerHandle
241 );
242
243 //
244 // Destroy the IP child.
245 //
246 Status = NetLibDestroyServiceChild (
247 ControllerHandle,
248 ImageHandle,
249 ServiceBindingGuid,
250 ChildHandle
251 );
252
253 return Status;
254 }
255
256 /**
257 This function handles ICMPv4 packets. It is the worker function of
258 IpIoIcmpHandler.
259
260 @param[in] IpIo Pointer to the IP_IO instance.
261 @param[in, out] Pkt Pointer to the ICMPv4 packet.
262 @param[in] Session Pointer to the net session of this ICMPv4 packet.
263
264 @retval EFI_SUCCESS The ICMPv4 packet is handled successfully.
265 @retval EFI_ABORTED This type of ICMPv4 packet is not supported.
266
267 **/
268 EFI_STATUS
269 IpIoIcmpv4Handler (
270 IN IP_IO *IpIo,
271 IN OUT NET_BUF *Pkt,
272 IN EFI_NET_SESSION_DATA *Session
273 )
274 {
275 IP4_ICMP_ERROR_HEAD *IcmpHdr;
276 EFI_IP4_HEADER *IpHdr;
277 UINT8 IcmpErr;
278 UINT8 *PayLoadHdr;
279 UINT8 Type;
280 UINT8 Code;
281 UINT32 TrimBytes;
282
283 ASSERT (IpIo->IpVersion == IP_VERSION_4);
284
285 IcmpHdr = NET_PROTO_HDR (Pkt, IP4_ICMP_ERROR_HEAD);
286 IpHdr = (EFI_IP4_HEADER *) (&IcmpHdr->IpHead);
287
288 //
289 // Check the ICMP packet length.
290 //
291 if (Pkt->TotalSize < ICMP_ERRLEN (IpHdr)) {
292
293 return EFI_ABORTED;
294 }
295
296 Type = IcmpHdr->Head.Type;
297 Code = IcmpHdr->Head.Code;
298
299 //
300 // Analyze the ICMP Error in this ICMP pkt
301 //
302 switch (Type) {
303 case ICMP_TYPE_UNREACH:
304 switch (Code) {
305 case ICMP_CODE_UNREACH_NET:
306 case ICMP_CODE_UNREACH_HOST:
307 case ICMP_CODE_UNREACH_PROTOCOL:
308 case ICMP_CODE_UNREACH_PORT:
309 case ICMP_CODE_UNREACH_SRCFAIL:
310 IcmpErr = (UINT8) (ICMP_ERR_UNREACH_NET + Code);
311
312 break;
313
314 case ICMP_CODE_UNREACH_NEEDFRAG:
315 IcmpErr = ICMP_ERR_MSGSIZE;
316
317 break;
318
319 case ICMP_CODE_UNREACH_NET_UNKNOWN:
320 case ICMP_CODE_UNREACH_NET_PROHIB:
321 case ICMP_CODE_UNREACH_TOSNET:
322 IcmpErr = ICMP_ERR_UNREACH_NET;
323
324 break;
325
326 case ICMP_CODE_UNREACH_HOST_UNKNOWN:
327 case ICMP_CODE_UNREACH_ISOLATED:
328 case ICMP_CODE_UNREACH_HOST_PROHIB:
329 case ICMP_CODE_UNREACH_TOSHOST:
330 IcmpErr = ICMP_ERR_UNREACH_HOST;
331
332 break;
333
334 default:
335 return EFI_ABORTED;
336 }
337
338 break;
339
340 case ICMP_TYPE_TIMXCEED:
341 if (Code > 1) {
342 return EFI_ABORTED;
343 }
344
345 IcmpErr = (UINT8) (Code + ICMP_ERR_TIMXCEED_INTRANS);
346
347 break;
348
349 case ICMP_TYPE_PARAMPROB:
350 if (Code > 1) {
351 return EFI_ABORTED;
352 }
353
354 IcmpErr = ICMP_ERR_PARAMPROB;
355
356 break;
357
358 case ICMP_TYPE_SOURCEQUENCH:
359 if (Code != 0) {
360 return EFI_ABORTED;
361 }
362
363 IcmpErr = ICMP_ERR_QUENCH;
364
365 break;
366
367 default:
368 return EFI_ABORTED;
369 }
370
371 //
372 // Notify user the ICMP pkt only containing payload except
373 // IP and ICMP header
374 //
375 PayLoadHdr = (UINT8 *) ((UINT8 *) IpHdr + EFI_IP4_HEADER_LEN (IpHdr));
376 TrimBytes = (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr);
377
378 NetbufTrim (Pkt, TrimBytes, TRUE);
379
380 IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);
381
382 return EFI_SUCCESS;
383 }
384
385 /**
386 This function handles ICMPv6 packets. It is the worker function of
387 IpIoIcmpHandler.
388
389 @param[in] IpIo Pointer to the IP_IO instance.
390 @param[in, out] Pkt Pointer to the ICMPv6 packet.
391 @param[in] Session Pointer to the net session of this ICMPv6 packet.
392
393 @retval EFI_SUCCESS The ICMPv6 packet is handled successfully.
394 @retval EFI_ABORTED This type of ICMPv6 packet is not supported.
395
396 **/
397 EFI_STATUS
398 IpIoIcmpv6Handler (
399 IN IP_IO *IpIo,
400 IN OUT NET_BUF *Pkt,
401 IN EFI_NET_SESSION_DATA *Session
402 )
403 {
404 IP6_ICMP_ERROR_HEAD *IcmpHdr;
405 EFI_IP6_HEADER *IpHdr;
406 UINT8 IcmpErr;
407 UINT8 *PayLoadHdr;
408 UINT8 Type;
409 UINT8 Code;
410 UINT8 NextHeader;
411 UINT32 TrimBytes;
412 BOOLEAN Flag;
413
414 ASSERT (IpIo->IpVersion == IP_VERSION_6);
415
416 //
417 // Check the ICMPv6 packet length.
418 //
419 if (Pkt->TotalSize < sizeof (IP6_ICMP_ERROR_HEAD)) {
420
421 return EFI_ABORTED;
422 }
423
424 IcmpHdr = NET_PROTO_HDR (Pkt, IP6_ICMP_ERROR_HEAD);
425 Type = IcmpHdr->Head.Type;
426 Code = IcmpHdr->Head.Code;
427
428 //
429 // Analyze the ICMPv6 Error in this ICMPv6 packet
430 //
431 switch (Type) {
432 case ICMP_V6_DEST_UNREACHABLE:
433 switch (Code) {
434 case ICMP_V6_NO_ROUTE_TO_DEST:
435 case ICMP_V6_BEYOND_SCOPE:
436 case ICMP_V6_ROUTE_REJECTED:
437 IcmpErr = ICMP6_ERR_UNREACH_NET;
438
439 break;
440
441 case ICMP_V6_COMM_PROHIBITED:
442 case ICMP_V6_ADDR_UNREACHABLE:
443 case ICMP_V6_SOURCE_ADDR_FAILED:
444 IcmpErr = ICMP6_ERR_UNREACH_HOST;
445
446 break;
447
448 case ICMP_V6_PORT_UNREACHABLE:
449 IcmpErr = ICMP6_ERR_UNREACH_PORT;
450
451 break;
452
453 default:
454 return EFI_ABORTED;
455 }
456
457 break;
458
459 case ICMP_V6_PACKET_TOO_BIG:
460 if (Code >= 1) {
461 return EFI_ABORTED;
462 }
463
464 IcmpErr = ICMP6_ERR_PACKAGE_TOOBIG;
465
466 break;
467
468 case ICMP_V6_TIME_EXCEEDED:
469 if (Code > 1) {
470 return EFI_ABORTED;
471 }
472
473 IcmpErr = (UINT8) (ICMP6_ERR_TIMXCEED_HOPLIMIT + Code);
474
475 break;
476
477 case ICMP_V6_PARAMETER_PROBLEM:
478 if (Code > 3) {
479 return EFI_ABORTED;
480 }
481
482 IcmpErr = (UINT8) (ICMP6_ERR_PARAMPROB_HEADER + Code);
483
484 break;
485
486 default:
487
488 return EFI_ABORTED;
489 }
490
491 //
492 // Notify user the ICMPv6 packet only containing payload except
493 // IPv6 basic header, extension header and ICMP header
494 //
495
496 IpHdr = (EFI_IP6_HEADER *) (&IcmpHdr->IpHead);
497 NextHeader = IpHdr->NextHeader;
498 PayLoadHdr = (UINT8 *) ((UINT8 *) IcmpHdr + sizeof (IP6_ICMP_ERROR_HEAD));
499 Flag = TRUE;
500
501 do {
502 switch (NextHeader) {
503 case EFI_IP_PROTO_UDP:
504 case EFI_IP_PROTO_TCP:
505 case EFI_IP_PROTO_ICMP:
506 case IP6_NO_NEXT_HEADER:
507 Flag = FALSE;
508
509 break;
510
511 case IP6_HOP_BY_HOP:
512 case IP6_DESTINATION:
513 //
514 // The Hdr Ext Len is 8-bit unsigned integer in 8-octet units, not including
515 // the first 8 octets.
516 //
517 NextHeader = *(PayLoadHdr);
518 PayLoadHdr = (UINT8 *) (PayLoadHdr + (*(PayLoadHdr + 1) + 1) * 8);
519
520 break;
521
522 case IP6_FRAGMENT:
523 //
524 // The Fragment Header Length is 8 octets.
525 //
526 NextHeader = *(PayLoadHdr);
527 PayLoadHdr = (UINT8 *) (PayLoadHdr + 8);
528
529 break;
530
531 default:
532
533 return EFI_ABORTED;
534 }
535 } while (Flag);
536
537 TrimBytes = (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr);
538
539 NetbufTrim (Pkt, TrimBytes, TRUE);
540
541 IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);
542
543 return EFI_SUCCESS;
544 }
545
546 /**
547 This function handles ICMP packets.
548
549 @param[in] IpIo Pointer to the IP_IO instance.
550 @param[in, out] Pkt Pointer to the ICMP packet.
551 @param[in] Session Pointer to the net session of this ICMP packet.
552
553 @retval EFI_SUCCESS The ICMP packet is handled successfully.
554 @retval EFI_ABORTED This type of ICMP packet is not supported.
555 @retval EFI_UNSUPPORTED The IP protocol version in IP_IO is not supported.
556
557 **/
558 EFI_STATUS
559 IpIoIcmpHandler (
560 IN IP_IO *IpIo,
561 IN OUT NET_BUF *Pkt,
562 IN EFI_NET_SESSION_DATA *Session
563 )
564 {
565
566 if (IpIo->IpVersion == IP_VERSION_4) {
567
568 return IpIoIcmpv4Handler (IpIo, Pkt, Session);
569
570 } else if (IpIo->IpVersion == IP_VERSION_6) {
571
572 return IpIoIcmpv6Handler (IpIo, Pkt, Session);
573
574 } else {
575
576 return EFI_UNSUPPORTED;
577 }
578 }
579
580
581 /**
582 Free function for receive token of IP_IO. It is used to
583 signal the recycle event to notify IP to recycle the
584 data buffer.
585
586 @param[in] Event The event to be signaled.
587
588 **/
589 VOID
590 IpIoExtFree (
591 IN VOID *Event
592 )
593 {
594 gBS->SignalEvent ((EFI_EVENT) Event);
595 }
596
597
598 /**
599 Create a send entry to wrap a packet before sending
600 out it through IP.
601
602 @param[in, out] IpIo Pointer to the IP_IO instance.
603 @param[in, out] Pkt Pointer to the packet.
604 @param[in] Sender Pointer to the IP sender.
605 @param[in] Context Pointer to the context.
606 @param[in] NotifyData Pointer to the notify data.
607 @param[in] Dest Pointer to the destination IP address.
608 @param[in] Override Pointer to the overriden IP_IO data.
609
610 @return Pointer to the data structure created to wrap the packet. If NULL,
611 @return resource limit occurred.
612
613 **/
614 IP_IO_SEND_ENTRY *
615 IpIoCreateSndEntry (
616 IN OUT IP_IO *IpIo,
617 IN OUT NET_BUF *Pkt,
618 IN VOID *Sender,
619 IN VOID *Context OPTIONAL,
620 IN VOID *NotifyData OPTIONAL,
621 IN EFI_IP_ADDRESS *Dest OPTIONAL,
622 IN IP_IO_OVERRIDE *Override
623 )
624 {
625 IP_IO_SEND_ENTRY *SndEntry;
626 EFI_EVENT Event;
627 EFI_STATUS Status;
628 NET_FRAGMENT *ExtFragment;
629 UINT32 FragmentCount;
630 IP_IO_OVERRIDE *OverrideData;
631 IP_IO_IP_TX_DATA *TxData;
632 EFI_IP4_TRANSMIT_DATA *Ip4TxData;
633 EFI_IP6_TRANSMIT_DATA *Ip6TxData;
634
635 if ((IpIo->IpVersion != IP_VERSION_4) && (IpIo->IpVersion != IP_VERSION_6)) {
636 return NULL;
637 }
638
639 Event = NULL;
640 TxData = NULL;
641 OverrideData = NULL;
642
643 //
644 // Allocate resource for SndEntry
645 //
646 SndEntry = AllocatePool (sizeof (IP_IO_SEND_ENTRY));
647 if (NULL == SndEntry) {
648 return NULL;
649 }
650
651 Status = gBS->CreateEvent (
652 EVT_NOTIFY_SIGNAL,
653 TPL_NOTIFY,
654 IpIoTransmitHandler,
655 SndEntry,
656 &Event
657 );
658 if (EFI_ERROR (Status)) {
659 goto ON_ERROR;
660 }
661
662 FragmentCount = Pkt->BlockOpNum;
663
664 //
665 // Allocate resource for TxData
666 //
667 TxData = (IP_IO_IP_TX_DATA *) AllocatePool (
668 sizeof (IP_IO_IP_TX_DATA) + sizeof (NET_FRAGMENT) * (FragmentCount - 1)
669 );
670
671 if (NULL == TxData) {
672 goto ON_ERROR;
673 }
674
675 //
676 // Build a fragment table to contain the fragments in the packet.
677 //
678 if (IpIo->IpVersion == IP_VERSION_4) {
679 ExtFragment = (NET_FRAGMENT *) TxData->Ip4TxData.FragmentTable;
680 } else {
681 ExtFragment = (NET_FRAGMENT *) TxData->Ip6TxData.FragmentTable;
682 }
683
684 NetbufBuildExt (Pkt, ExtFragment, &FragmentCount);
685
686
687 //
688 // Allocate resource for OverrideData if needed
689 //
690 if (NULL != Override) {
691
692 OverrideData = AllocateCopyPool (sizeof (IP_IO_OVERRIDE), Override);
693 if (NULL == OverrideData) {
694 goto ON_ERROR;
695 }
696 }
697
698 //
699 // Set other fields of TxData except the fragment table
700 //
701 if (IpIo->IpVersion == IP_VERSION_4) {
702
703 Ip4TxData = &TxData->Ip4TxData;
704
705 CopyMem (&Ip4TxData->DestinationAddress, Dest, sizeof (EFI_IPv4_ADDRESS));
706
707 Ip4TxData->OverrideData = &OverrideData->Ip4OverrideData;
708 Ip4TxData->OptionsLength = 0;
709 Ip4TxData->OptionsBuffer = NULL;
710 Ip4TxData->TotalDataLength = Pkt->TotalSize;
711 Ip4TxData->FragmentCount = FragmentCount;
712
713 //
714 // Set the fields of SndToken
715 //
716 SndEntry->SndToken.Ip4Token.Event = Event;
717 SndEntry->SndToken.Ip4Token.Packet.TxData = Ip4TxData;
718 } else {
719
720 Ip6TxData = &TxData->Ip6TxData;
721
722 if (Dest != NULL) {
723 CopyMem (&Ip6TxData->DestinationAddress, Dest, sizeof (EFI_IPv6_ADDRESS));
724 } else {
725 ZeroMem (&Ip6TxData->DestinationAddress, sizeof (EFI_IPv6_ADDRESS));
726 }
727
728 Ip6TxData->OverrideData = &OverrideData->Ip6OverrideData;
729 Ip6TxData->DataLength = Pkt->TotalSize;
730 Ip6TxData->FragmentCount = FragmentCount;
731 Ip6TxData->ExtHdrsLength = 0;
732 Ip6TxData->ExtHdrs = NULL;
733
734 //
735 // Set the fields of SndToken
736 //
737 SndEntry->SndToken.Ip6Token.Event = Event;
738 SndEntry->SndToken.Ip6Token.Packet.TxData = Ip6TxData;
739 }
740
741 //
742 // Set the fields of SndEntry
743 //
744 SndEntry->IpIo = IpIo;
745 SndEntry->Ip = Sender;
746 SndEntry->Context = Context;
747 SndEntry->NotifyData = NotifyData;
748
749 SndEntry->Pkt = Pkt;
750 NET_GET_REF (Pkt);
751
752 InsertTailList (&IpIo->PendingSndList, &SndEntry->Entry);
753
754 return SndEntry;
755
756 ON_ERROR:
757
758 if (OverrideData != NULL) {
759 FreePool (OverrideData);
760 }
761
762 if (TxData != NULL) {
763 FreePool (TxData);
764 }
765
766 if (SndEntry != NULL) {
767 FreePool (SndEntry);
768 }
769
770 if (Event != NULL) {
771 gBS->CloseEvent (Event);
772 }
773
774 return NULL;
775 }
776
777
778 /**
779 Destroy the SndEntry.
780
781 This function pairs with IpIoCreateSndEntry().
782
783 @param[in] SndEntry Pointer to the send entry to be destroyed.
784
785 **/
786 VOID
787 IpIoDestroySndEntry (
788 IN IP_IO_SEND_ENTRY *SndEntry
789 )
790 {
791 EFI_EVENT Event;
792 IP_IO_IP_TX_DATA *TxData;
793 IP_IO_OVERRIDE *Override;
794
795 if (SndEntry->IpIo->IpVersion == IP_VERSION_4) {
796 Event = SndEntry->SndToken.Ip4Token.Event;
797 TxData = (IP_IO_IP_TX_DATA *) SndEntry->SndToken.Ip4Token.Packet.TxData;
798 Override = (IP_IO_OVERRIDE *) TxData->Ip4TxData.OverrideData;
799 } else if (SndEntry->IpIo->IpVersion == IP_VERSION_6) {
800 Event = SndEntry->SndToken.Ip6Token.Event;
801 TxData = (IP_IO_IP_TX_DATA *) SndEntry->SndToken.Ip6Token.Packet.TxData;
802 Override = (IP_IO_OVERRIDE *) TxData->Ip6TxData.OverrideData;
803 } else {
804 return ;
805 }
806
807 gBS->CloseEvent (Event);
808
809 FreePool (TxData);
810
811 if (NULL != Override) {
812 FreePool (Override);
813 }
814
815 NetbufFree (SndEntry->Pkt);
816
817 RemoveEntryList (&SndEntry->Entry);
818
819 FreePool (SndEntry);
820 }
821
822
823 /**
824 Notify function for IP transmit token.
825
826 @param[in] Context The context passed in by the event notifier.
827
828 **/
829 VOID
830 EFIAPI
831 IpIoTransmitHandlerDpc (
832 IN VOID *Context
833 )
834 {
835 IP_IO *IpIo;
836 IP_IO_SEND_ENTRY *SndEntry;
837 EFI_STATUS Status;
838
839 SndEntry = (IP_IO_SEND_ENTRY *) Context;
840
841 IpIo = SndEntry->IpIo;
842
843 if (IpIo->IpVersion == IP_VERSION_4) {
844 Status = SndEntry->SndToken.Ip4Token.Status;
845 } else if (IpIo->IpVersion == IP_VERSION_6){
846 Status = SndEntry->SndToken.Ip6Token.Status;
847 } else {
848 return ;
849 }
850
851 if ((IpIo->PktSentNotify != NULL) && (SndEntry->NotifyData != NULL)) {
852 IpIo->PktSentNotify (
853 Status,
854 SndEntry->Context,
855 SndEntry->Ip,
856 SndEntry->NotifyData
857 );
858 }
859
860 IpIoDestroySndEntry (SndEntry);
861 }
862
863
864 /**
865 Notify function for IP transmit token.
866
867 @param[in] Event The event signaled.
868 @param[in] Context The context passed in by the event notifier.
869
870 **/
871 VOID
872 EFIAPI
873 IpIoTransmitHandler (
874 IN EFI_EVENT Event,
875 IN VOID *Context
876 )
877 {
878 //
879 // Request IpIoTransmitHandlerDpc as a DPC at TPL_CALLBACK
880 //
881 QueueDpc (TPL_CALLBACK, IpIoTransmitHandlerDpc, Context);
882 }
883
884
885 /**
886 The dummy handler for the dummy IP receive token.
887
888 @param[in] Context The context passed in by the event notifier.
889
890 **/
891 VOID
892 EFIAPI
893 IpIoDummyHandlerDpc (
894 IN VOID *Context
895 )
896 {
897 IP_IO_IP_INFO *IpInfo;
898 EFI_STATUS Status;
899 EFI_EVENT RecycleEvent;
900
901 IpInfo = (IP_IO_IP_INFO *) Context;
902
903 if ((IpInfo->IpVersion != IP_VERSION_4) && (IpInfo->IpVersion != IP_VERSION_6)) {
904 return ;
905 }
906
907 RecycleEvent = NULL;
908
909 if (IpInfo->IpVersion == IP_VERSION_4) {
910 Status = IpInfo->DummyRcvToken.Ip4Token.Status;
911
912 if (IpInfo->DummyRcvToken.Ip4Token.Packet.RxData != NULL) {
913 RecycleEvent = IpInfo->DummyRcvToken.Ip4Token.Packet.RxData->RecycleSignal;
914 }
915 } else {
916 Status = IpInfo->DummyRcvToken.Ip6Token.Status;
917
918 if (IpInfo->DummyRcvToken.Ip6Token.Packet.RxData != NULL) {
919 RecycleEvent = IpInfo->DummyRcvToken.Ip6Token.Packet.RxData->RecycleSignal;
920 }
921 }
922
923
924
925 if (EFI_ABORTED == Status) {
926 //
927 // The reception is actively aborted by the consumer, directly return.
928 //
929 return;
930 } else if (EFI_SUCCESS == Status) {
931 //
932 // Recycle the RxData.
933 //
934 ASSERT (RecycleEvent != NULL);
935
936 gBS->SignalEvent (RecycleEvent);
937 }
938
939 //
940 // Continue the receive.
941 //
942 if (IpInfo->IpVersion == IP_VERSION_4) {
943 ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Receive (
944 (EFI_IP4_PROTOCOL *) (IpInfo->Ip),
945 &IpInfo->DummyRcvToken.Ip4Token
946 );
947 } else {
948 ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Receive (
949 (EFI_IP6_PROTOCOL *) (IpInfo->Ip),
950 &IpInfo->DummyRcvToken.Ip6Token
951 );
952 }
953 }
954
955
956 /**
957 This function add IpIoDummyHandlerDpc to the end of the DPC queue.
958
959 @param[in] Event The event signaled.
960 @param[in] Context The context passed in by the event notifier.
961
962 **/
963 VOID
964 EFIAPI
965 IpIoDummyHandler (
966 IN EFI_EVENT Event,
967 IN VOID *Context
968 )
969 {
970 //
971 // Request IpIoDummyHandlerDpc as a DPC at TPL_CALLBACK
972 //
973 QueueDpc (TPL_CALLBACK, IpIoDummyHandlerDpc, Context);
974 }
975
976
977 /**
978 Notify function for the IP receive token, used to process
979 the received IP packets.
980
981 @param[in] Context The context passed in by the event notifier.
982
983 **/
984 VOID
985 EFIAPI
986 IpIoListenHandlerDpc (
987 IN VOID *Context
988 )
989 {
990 IP_IO *IpIo;
991 EFI_STATUS Status;
992 IP_IO_IP_RX_DATA *RxData;
993 VOID *Ip;
994 EFI_NET_SESSION_DATA Session;
995 NET_BUF *Pkt;
996
997 IpIo = (IP_IO *) Context;
998 Ip = IpIo->Ip;
999
1000 if (IpIo->IpVersion == IP_VERSION_4) {
1001 Status = IpIo->RcvToken.Ip4Token.Status;
1002 RxData = (IP_IO_IP_RX_DATA *) IpIo->RcvToken.Ip4Token.Packet.RxData;
1003 } else if (IpIo->IpVersion == IP_VERSION_6) {
1004 Status = IpIo->RcvToken.Ip6Token.Status;
1005 RxData = (IP_IO_IP_RX_DATA *) IpIo->RcvToken.Ip6Token.Packet.RxData;
1006 } else {
1007 return;
1008 }
1009
1010 if (EFI_ABORTED == Status) {
1011 //
1012 // The reception is actively aborted by the consumer, directly return.
1013 //
1014 return;
1015 }
1016
1017 if (((EFI_SUCCESS != Status) && (EFI_ICMP_ERROR != Status)) || (NULL == RxData)) {
1018 //
1019 // @bug Only process the normal packets and the icmp error packets, if RxData is NULL
1020 // @bug with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although
1021 // @bug this should be a bug of the low layer (IP).
1022 //
1023 goto Resume;
1024 }
1025
1026 if (NULL == IpIo->PktRcvdNotify) {
1027 goto CleanUp;
1028 }
1029
1030 if (IpIo->IpVersion == IP_VERSION_4) {
1031 if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&
1032 !Ip4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) {
1033 //
1034 // The source address is not zero and it's not a unicast IP address, discard it.
1035 //
1036 goto CleanUp;
1037 }
1038
1039 //
1040 // Create a netbuffer representing IPv4 packet
1041 //
1042 Pkt = NetbufFromExt (
1043 (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,
1044 RxData->Ip4RxData.FragmentCount,
1045 0,
1046 0,
1047 IpIoExtFree,
1048 RxData->Ip4RxData.RecycleSignal
1049 );
1050 if (NULL == Pkt) {
1051 goto CleanUp;
1052 }
1053
1054 //
1055 // Create a net session
1056 //
1057 Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress);
1058 Session.Dest.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress);
1059 Session.IpHdr.Ip4Hdr = RxData->Ip4RxData.Header;
1060 Session.IpVersion = IP_VERSION_4;
1061 } else {
1062
1063 if (!Ip6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) {
1064 goto CleanUp;
1065 }
1066
1067 //
1068 // Create a netbuffer representing IPv6 packet
1069 //
1070 Pkt = NetbufFromExt (
1071 (NET_FRAGMENT *) RxData->Ip6RxData.FragmentTable,
1072 RxData->Ip6RxData.FragmentCount,
1073 0,
1074 0,
1075 IpIoExtFree,
1076 RxData->Ip6RxData.RecycleSignal
1077 );
1078 if (NULL == Pkt) {
1079 goto CleanUp;
1080 }
1081
1082 //
1083 // Create a net session
1084 //
1085 CopyMem (
1086 &Session.Source,
1087 &RxData->Ip6RxData.Header->SourceAddress,
1088 sizeof(EFI_IPv6_ADDRESS)
1089 );
1090 CopyMem (
1091 &Session.Dest,
1092 &RxData->Ip6RxData.Header->DestinationAddress,
1093 sizeof(EFI_IPv6_ADDRESS)
1094 );
1095 Session.IpHdr.Ip6Hdr = RxData->Ip6RxData.Header;
1096 Session.IpVersion = IP_VERSION_6;
1097 }
1098
1099 if (EFI_SUCCESS == Status) {
1100
1101 IpIo->PktRcvdNotify (EFI_SUCCESS, 0, &Session, Pkt, IpIo->RcvdContext);
1102 } else {
1103 //
1104 // Status is EFI_ICMP_ERROR
1105 //
1106 Status = IpIoIcmpHandler (IpIo, Pkt, &Session);
1107 if (EFI_ERROR (Status)) {
1108 NetbufFree (Pkt);
1109 }
1110 }
1111
1112 goto Resume;
1113
1114 CleanUp:
1115
1116 if (IpIo->IpVersion == IP_VERSION_4){
1117 gBS->SignalEvent (RxData->Ip4RxData.RecycleSignal);
1118 } else {
1119 gBS->SignalEvent (RxData->Ip6RxData.RecycleSignal);
1120 }
1121
1122 Resume:
1123
1124 if (IpIo->IpVersion == IP_VERSION_4){
1125 ((EFI_IP4_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip4Token));
1126 } else {
1127 ((EFI_IP6_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip6Token));
1128 }
1129 }
1130
1131 /**
1132 This function add IpIoListenHandlerDpc to the end of the DPC queue.
1133
1134 @param[in] Event The event signaled.
1135 @param[in] Context The context passed in by the event notifier.
1136
1137 **/
1138 VOID
1139 EFIAPI
1140 IpIoListenHandler (
1141 IN EFI_EVENT Event,
1142 IN VOID *Context
1143 )
1144 {
1145 //
1146 // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK
1147 //
1148 QueueDpc (TPL_CALLBACK, IpIoListenHandlerDpc, Context);
1149 }
1150
1151
1152 /**
1153 Create a new IP_IO instance.
1154
1155 This function uses IP4/IP6 service binding protocol in Controller to create
1156 an IP4/IP6 child (aka IP4/IP6 instance).
1157
1158 @param[in] Image The image handle of the driver or application that
1159 consumes IP_IO.
1160 @param[in] Controller The controller handle that has IP4 or IP6 service
1161 binding protocol installed.
1162 @param[in] IpVersion The version of the IP protocol to use, either
1163 IPv4 or IPv6.
1164
1165 @return Pointer to a newly created IP_IO instance, or NULL if failed.
1166
1167 **/
1168 IP_IO *
1169 EFIAPI
1170 IpIoCreate (
1171 IN EFI_HANDLE Image,
1172 IN EFI_HANDLE Controller,
1173 IN UINT8 IpVersion
1174 )
1175 {
1176 EFI_STATUS Status;
1177 IP_IO *IpIo;
1178 EFI_EVENT Event;
1179
1180 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
1181
1182 IpIo = AllocateZeroPool (sizeof (IP_IO));
1183 if (NULL == IpIo) {
1184 return NULL;
1185 }
1186
1187 InitializeListHead (&(IpIo->PendingSndList));
1188 InitializeListHead (&(IpIo->IpList));
1189 IpIo->Controller = Controller;
1190 IpIo->Image = Image;
1191 IpIo->IpVersion = IpVersion;
1192 Event = NULL;
1193
1194 Status = gBS->CreateEvent (
1195 EVT_NOTIFY_SIGNAL,
1196 TPL_NOTIFY,
1197 IpIoListenHandler,
1198 IpIo,
1199 &Event
1200 );
1201 if (EFI_ERROR (Status)) {
1202 goto ReleaseIpIo;
1203 }
1204
1205 if (IpVersion == IP_VERSION_4) {
1206 IpIo->RcvToken.Ip4Token.Event = Event;
1207 } else {
1208 IpIo->RcvToken.Ip6Token.Event = Event;
1209 }
1210
1211 //
1212 // Create an IP child and open IP protocol
1213 //
1214 Status = IpIoCreateIpChildOpenProtocol (
1215 Controller,
1216 Image,
1217 &IpIo->ChildHandle,
1218 IpVersion,
1219 (VOID **)&(IpIo->Ip)
1220 );
1221 if (EFI_ERROR (Status)) {
1222 goto ReleaseIpIo;
1223 }
1224
1225 return IpIo;
1226
1227 ReleaseIpIo:
1228
1229 if (Event != NULL) {
1230 gBS->CloseEvent (Event);
1231 }
1232
1233 gBS->FreePool (IpIo);
1234
1235 return NULL;
1236 }
1237
1238
1239 /**
1240 Open an IP_IO instance for use.
1241
1242 This function is called after IpIoCreate(). It is used for configuring the IP
1243 instance and register the callbacks and their context data for sending and
1244 receiving IP packets.
1245
1246 @param[in, out] IpIo Pointer to an IP_IO instance that needs
1247 to open.
1248 @param[in] OpenData The configuration data and callbacks for
1249 the IP_IO instance.
1250
1251 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
1252 successfully.
1253 @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to
1254 reopen it.
1255 @retval Others Error condition occurred.
1256
1257 **/
1258 EFI_STATUS
1259 EFIAPI
1260 IpIoOpen (
1261 IN OUT IP_IO *IpIo,
1262 IN IP_IO_OPEN_DATA *OpenData
1263 )
1264 {
1265 EFI_STATUS Status;
1266 VOID *Ip;
1267 UINT8 IpVersion;
1268
1269 if (IpIo->IsConfigured) {
1270 return EFI_ACCESS_DENIED;
1271 }
1272
1273 IpVersion = IpIo->IpVersion;
1274
1275 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
1276
1277 Ip = IpIo->Ip;
1278
1279 //
1280 // configure ip
1281 //
1282 if (IpVersion == IP_VERSION_4){
1283 Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure (
1284 (EFI_IP4_PROTOCOL *) Ip,
1285 &OpenData->IpConfigData.Ip4CfgData
1286 );
1287 } else {
1288
1289 Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure (
1290 (EFI_IP6_PROTOCOL *) Ip,
1291 &OpenData->IpConfigData.Ip6CfgData
1292 );
1293 }
1294
1295 if (EFI_ERROR (Status)) {
1296 return Status;
1297 }
1298
1299 //
1300 // @bug To delete the default route entry in this Ip, if it is:
1301 // @bug (0.0.0.0, 0.0.0.0, 0.0.0.0). Delete this statement if Ip modified
1302 // @bug its code
1303 //
1304 if (IpVersion == IP_VERSION_4){
1305 Status = ((EFI_IP4_PROTOCOL *) Ip)->Routes (
1306 (EFI_IP4_PROTOCOL *) Ip,
1307 TRUE,
1308 &mZeroIp4Addr,
1309 &mZeroIp4Addr,
1310 &mZeroIp4Addr
1311 );
1312
1313 if (EFI_ERROR (Status) && (EFI_NOT_FOUND != Status)) {
1314 return Status;
1315 }
1316 }
1317
1318 IpIo->PktRcvdNotify = OpenData->PktRcvdNotify;
1319 IpIo->PktSentNotify = OpenData->PktSentNotify;
1320
1321 IpIo->RcvdContext = OpenData->RcvdContext;
1322 IpIo->SndContext = OpenData->SndContext;
1323
1324 if (IpVersion == IP_VERSION_4){
1325 IpIo->Protocol = OpenData->IpConfigData.Ip4CfgData.DefaultProtocol;
1326
1327 //
1328 // start to listen incoming packet
1329 //
1330 Status = ((EFI_IP4_PROTOCOL *) Ip)->Receive (
1331 (EFI_IP4_PROTOCOL *) Ip,
1332 &(IpIo->RcvToken.Ip4Token)
1333 );
1334 if (EFI_ERROR (Status)) {
1335 ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL);
1336 goto ErrorExit;
1337 }
1338
1339 } else {
1340
1341 IpIo->Protocol = OpenData->IpConfigData.Ip6CfgData.DefaultProtocol;
1342 Status = ((EFI_IP6_PROTOCOL *) Ip)->Receive (
1343 (EFI_IP6_PROTOCOL *) Ip,
1344 &(IpIo->RcvToken.Ip6Token)
1345 );
1346 if (EFI_ERROR (Status)) {
1347 ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);
1348 goto ErrorExit;
1349 }
1350 }
1351
1352 IpIo->IsConfigured = TRUE;
1353 InsertTailList (&mActiveIpIoList, &IpIo->Entry);
1354
1355 ErrorExit:
1356
1357 return Status;
1358 }
1359
1360
1361 /**
1362 Stop an IP_IO instance.
1363
1364 This function is paired with IpIoOpen(). The IP_IO will be unconfigured and all
1365 the pending send/receive tokens will be canceled.
1366
1367 @param[in, out] IpIo Pointer to the IP_IO instance that needs to stop.
1368
1369 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
1370 @retval Others Error condition occurred.
1371
1372 **/
1373 EFI_STATUS
1374 EFIAPI
1375 IpIoStop (
1376 IN OUT IP_IO *IpIo
1377 )
1378 {
1379 EFI_STATUS Status;
1380 VOID *Ip;
1381 IP_IO_IP_INFO *IpInfo;
1382 UINT8 IpVersion;
1383
1384 if (!IpIo->IsConfigured) {
1385 return EFI_SUCCESS;
1386 }
1387
1388 IpVersion = IpIo->IpVersion;
1389
1390 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
1391
1392 //
1393 // Remove the IpIo from the active IpIo list.
1394 //
1395 RemoveEntryList (&IpIo->Entry);
1396
1397 Ip = IpIo->Ip;
1398
1399 //
1400 // Configure NULL Ip
1401 //
1402 if (IpVersion == IP_VERSION_4) {
1403 Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL);
1404 } else {
1405 Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);
1406 }
1407 if (EFI_ERROR (Status)) {
1408 return Status;
1409 }
1410
1411 IpIo->IsConfigured = FALSE;
1412
1413 //
1414 // Detroy the Ip List used by IpIo
1415 //
1416
1417 while (!IsListEmpty (&(IpIo->IpList))) {
1418 IpInfo = NET_LIST_HEAD (&(IpIo->IpList), IP_IO_IP_INFO, Entry);
1419
1420 IpIoRemoveIp (IpIo, IpInfo);
1421 }
1422
1423 //
1424 // All pending send tokens should be flushed by reseting the IP instances.
1425 //
1426 ASSERT (IsListEmpty (&IpIo->PendingSndList));
1427
1428 //
1429 // Close the receive event.
1430 //
1431 if (IpVersion == IP_VERSION_4){
1432 gBS->CloseEvent (IpIo->RcvToken.Ip4Token.Event);
1433 } else {
1434 gBS->CloseEvent (IpIo->RcvToken.Ip6Token.Event);
1435 }
1436
1437 return EFI_SUCCESS;
1438 }
1439
1440
1441 /**
1442 Destroy an IP_IO instance.
1443
1444 This function is paired with IpIoCreate(). The IP_IO will be closed first.
1445 Resource will be freed afterwards. See IpIoCloseProtocolDestroyIpChild().
1446
1447 @param[in, out] IpIo Pointer to the IP_IO instance that needs to be
1448 destroyed.
1449
1450 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
1451 @retval Others Error condition occurred.
1452
1453 **/
1454 EFI_STATUS
1455 EFIAPI
1456 IpIoDestroy (
1457 IN OUT IP_IO *IpIo
1458 )
1459 {
1460 //
1461 // Stop the IpIo.
1462 //
1463 IpIoStop (IpIo);
1464
1465 //
1466 // Close the IP protocol and destroy the child.
1467 //
1468 IpIoCloseProtocolDestroyIpChild (
1469 IpIo->Controller,
1470 IpIo->Image,
1471 IpIo->ChildHandle,
1472 IpIo->IpVersion
1473 );
1474
1475 gBS->FreePool (IpIo);
1476
1477 return EFI_SUCCESS;
1478 }
1479
1480
1481 /**
1482 Send out an IP packet.
1483
1484 This function is called after IpIoOpen(). The data to be sent are wrapped in
1485 Pkt. The IP instance wrapped in IpIo is used for sending by default but can be
1486 overriden by Sender. Other sending configs, like source address and gateway
1487 address etc., are specified in OverrideData.
1488
1489 @param[in, out] IpIo Pointer to an IP_IO instance used for sending IP
1490 packet.
1491 @param[in, out] Pkt Pointer to the IP packet to be sent.
1492 @param[in] Sender The IP protocol instance used for sending.
1493 @param[in] Context Optional context data.
1494 @param[in] NotifyData Optional notify data.
1495 @param[in] Dest The destination IP address to send this packet to.
1496 @param[in] OverrideData The data to override some configuration of the IP
1497 instance used for sending.
1498
1499 @retval EFI_SUCCESS The operation is completed successfully.
1500 @retval EFI_NOT_STARTED The IpIo is not configured.
1501 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
1502
1503 **/
1504 EFI_STATUS
1505 EFIAPI
1506 IpIoSend (
1507 IN OUT IP_IO *IpIo,
1508 IN OUT NET_BUF *Pkt,
1509 IN IP_IO_IP_INFO *Sender OPTIONAL,
1510 IN VOID *Context OPTIONAL,
1511 IN VOID *NotifyData OPTIONAL,
1512 IN EFI_IP_ADDRESS *Dest,
1513 IN IP_IO_OVERRIDE *OverrideData OPTIONAL
1514 )
1515 {
1516 EFI_STATUS Status;
1517 VOID *Ip;
1518 IP_IO_SEND_ENTRY *SndEntry;
1519
1520 ASSERT ((IpIo->IpVersion != IP_VERSION_4) || (Dest != NULL));
1521
1522 if (!IpIo->IsConfigured) {
1523 return EFI_NOT_STARTED;
1524 }
1525
1526 Ip = (NULL == Sender) ? IpIo->Ip : Sender->Ip;
1527
1528 //
1529 // create a new SndEntry
1530 //
1531 SndEntry = IpIoCreateSndEntry (IpIo, Pkt, Ip, Context, NotifyData, Dest, OverrideData);
1532 if (NULL == SndEntry) {
1533 return EFI_OUT_OF_RESOURCES;
1534 }
1535
1536 //
1537 // Send this Packet
1538 //
1539 if (IpIo->IpVersion == IP_VERSION_4){
1540 Status = ((EFI_IP4_PROTOCOL *) Ip)->Transmit (
1541 (EFI_IP4_PROTOCOL *) Ip,
1542 &SndEntry->SndToken.Ip4Token
1543 );
1544 } else {
1545 Status = ((EFI_IP6_PROTOCOL *) Ip)->Transmit (
1546 (EFI_IP6_PROTOCOL *) Ip,
1547 &SndEntry->SndToken.Ip6Token
1548 );
1549 }
1550
1551 if (EFI_ERROR (Status)) {
1552 IpIoDestroySndEntry (SndEntry);
1553 }
1554
1555 return Status;
1556 }
1557
1558
1559 /**
1560 Cancel the IP transmit token which wraps this Packet.
1561
1562 @param[in] IpIo Pointer to the IP_IO instance.
1563 @param[in] Packet Pointer to the packet of NET_BUF to cancel.
1564
1565 **/
1566 VOID
1567 EFIAPI
1568 IpIoCancelTxToken (
1569 IN IP_IO *IpIo,
1570 IN VOID *Packet
1571 )
1572 {
1573 LIST_ENTRY *Node;
1574 IP_IO_SEND_ENTRY *SndEntry;
1575 VOID *Ip;
1576
1577 ASSERT ((IpIo != NULL) && (Packet != NULL));
1578
1579 NET_LIST_FOR_EACH (Node, &IpIo->PendingSndList) {
1580
1581 SndEntry = NET_LIST_USER_STRUCT (Node, IP_IO_SEND_ENTRY, Entry);
1582
1583 if (SndEntry->Pkt == Packet) {
1584
1585 Ip = SndEntry->Ip;
1586
1587 if (IpIo->IpVersion == IP_VERSION_4) {
1588 ((EFI_IP4_PROTOCOL *) Ip)->Cancel (
1589 (EFI_IP4_PROTOCOL *) Ip,
1590 &SndEntry->SndToken.Ip4Token
1591 );
1592 } else {
1593 ((EFI_IP6_PROTOCOL *) Ip)->Cancel (
1594 (EFI_IP6_PROTOCOL *) Ip,
1595 &SndEntry->SndToken.Ip6Token
1596 );
1597 }
1598
1599 break;
1600 }
1601 }
1602
1603 }
1604
1605
1606 /**
1607 Add a new IP instance for sending data.
1608
1609 The function is used to add the IP_IO to the IP_IO sending list. The caller
1610 can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to send
1611 data.
1612
1613 @param[in, out] IpIo Pointer to a IP_IO instance to add a new IP
1614 instance for sending purpose.
1615
1616 @return Pointer to the created IP_IO_IP_INFO structure, NULL if failed.
1617
1618 **/
1619 IP_IO_IP_INFO *
1620 EFIAPI
1621 IpIoAddIp (
1622 IN OUT IP_IO *IpIo
1623 )
1624 {
1625 EFI_STATUS Status;
1626 IP_IO_IP_INFO *IpInfo;
1627 EFI_EVENT Event;
1628
1629 ASSERT (IpIo != NULL);
1630
1631 IpInfo = AllocatePool (sizeof (IP_IO_IP_INFO));
1632 if (IpInfo == NULL) {
1633 return NULL;
1634 }
1635
1636 //
1637 // Init this IpInfo, set the Addr and SubnetMask to 0 before we configure the IP
1638 // instance.
1639 //
1640 InitializeListHead (&IpInfo->Entry);
1641 IpInfo->ChildHandle = NULL;
1642 ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr));
1643 ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask));
1644
1645 IpInfo->RefCnt = 1;
1646 IpInfo->IpVersion = IpIo->IpVersion;
1647
1648 //
1649 // Create the IP instance and open the IP protocol.
1650 //
1651 Status = IpIoCreateIpChildOpenProtocol (
1652 IpIo->Controller,
1653 IpIo->Image,
1654 &IpInfo->ChildHandle,
1655 IpInfo->IpVersion,
1656 (VOID **) &IpInfo->Ip
1657 );
1658 if (EFI_ERROR (Status)) {
1659 goto ReleaseIpInfo;
1660 }
1661
1662 //
1663 // Create the event for the DummyRcvToken.
1664 //
1665 Status = gBS->CreateEvent (
1666 EVT_NOTIFY_SIGNAL,
1667 TPL_NOTIFY,
1668 IpIoDummyHandler,
1669 IpInfo,
1670 &Event
1671 );
1672 if (EFI_ERROR (Status)) {
1673 goto ReleaseIpChild;
1674 }
1675
1676 if (IpInfo->IpVersion == IP_VERSION_4) {
1677 IpInfo->DummyRcvToken.Ip4Token.Event = Event;
1678 } else {
1679 IpInfo->DummyRcvToken.Ip6Token.Event = Event;
1680 }
1681
1682 //
1683 // Link this IpInfo into the IpIo.
1684 //
1685 InsertTailList (&IpIo->IpList, &IpInfo->Entry);
1686
1687 return IpInfo;
1688
1689 ReleaseIpChild:
1690
1691 IpIoCloseProtocolDestroyIpChild (
1692 IpIo->Controller,
1693 IpIo->Image,
1694 IpInfo->ChildHandle,
1695 IpInfo->IpVersion
1696 );
1697
1698 ReleaseIpInfo:
1699
1700 gBS->FreePool (IpInfo);
1701
1702 return NULL;
1703 }
1704
1705
1706 /**
1707 Configure the IP instance of this IpInfo and start the receiving if IpConfigData
1708 is not NULL.
1709
1710 @param[in, out] IpInfo Pointer to the IP_IO_IP_INFO instance.
1711 @param[in, out] IpConfigData The IP configure data used to configure the IP
1712 instance, if NULL the IP instance is reset. If
1713 UseDefaultAddress is set to TRUE, and the configure
1714 operation succeeds, the default address information
1715 is written back in this IpConfigData.
1716
1717 @retval EFI_SUCCESS The IP instance of this IpInfo is configured successfully
1718 or no need to reconfigure it.
1719 @retval Others Configuration fails.
1720
1721 **/
1722 EFI_STATUS
1723 EFIAPI
1724 IpIoConfigIp (
1725 IN OUT IP_IO_IP_INFO *IpInfo,
1726 IN OUT VOID *IpConfigData OPTIONAL
1727 )
1728 {
1729 EFI_STATUS Status;
1730 VOID *Ip;
1731 UINT8 IpVersion;
1732 EFI_IP4_MODE_DATA Ip4ModeData;
1733 EFI_IP6_MODE_DATA Ip6ModeData;
1734
1735 ASSERT (IpInfo != NULL);
1736
1737 if (IpInfo->RefCnt > 1) {
1738 //
1739 // This IP instance is shared, don't reconfigure it until it has only one
1740 // consumer. Currently, only the tcp children cloned from their passive parent
1741 // will share the same IP. So this cases only happens while IpConfigData is NULL,
1742 // let the last consumer clean the IP instance.
1743 //
1744 return EFI_SUCCESS;
1745 }
1746
1747 IpVersion = IpInfo->IpVersion;
1748 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
1749
1750 Ip = IpInfo->Ip;
1751
1752 if (IpInfo->IpVersion == IP_VERSION_4) {
1753 Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, IpConfigData);
1754 } else {
1755 Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, IpConfigData);
1756 }
1757
1758 if (EFI_ERROR (Status)) {
1759 goto OnExit;
1760 }
1761
1762 if (IpConfigData != NULL) {
1763 if (IpInfo->IpVersion == IP_VERSION_4){
1764
1765 if (((EFI_IP4_CONFIG_DATA *) IpConfigData)->UseDefaultAddress) {
1766 ((EFI_IP4_PROTOCOL *) Ip)->GetModeData (
1767 (EFI_IP4_PROTOCOL *) Ip,
1768 &Ip4ModeData,
1769 NULL,
1770 NULL
1771 );
1772
1773 ((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress = Ip4ModeData.ConfigData.StationAddress;
1774 ((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask = Ip4ModeData.ConfigData.SubnetMask;
1775 }
1776
1777 CopyMem (
1778 &IpInfo->Addr.Addr,
1779 &((EFI_IP4_CONFIG_DATA *) IpConfigData)->StationAddress,
1780 sizeof (IP4_ADDR)
1781 );
1782 CopyMem (
1783 &IpInfo->PreMask.SubnetMask,
1784 &((EFI_IP4_CONFIG_DATA *) IpConfigData)->SubnetMask,
1785 sizeof (IP4_ADDR)
1786 );
1787
1788 Status = ((EFI_IP4_PROTOCOL *) Ip)->Receive (
1789 (EFI_IP4_PROTOCOL *) Ip,
1790 &IpInfo->DummyRcvToken.Ip4Token
1791 );
1792 if (EFI_ERROR (Status)) {
1793 ((EFI_IP4_PROTOCOL*)Ip)->Configure (Ip, NULL);
1794 }
1795 } else {
1796
1797 ((EFI_IP6_PROTOCOL *) Ip)->GetModeData (
1798 (EFI_IP6_PROTOCOL *) Ip,
1799 &Ip6ModeData,
1800 NULL,
1801 NULL
1802 );
1803
1804 if (Ip6ModeData.IsConfigured) {
1805 CopyMem (
1806 &((EFI_IP6_CONFIG_DATA *) IpConfigData)->StationAddress,
1807 &Ip6ModeData.ConfigData.StationAddress,
1808 sizeof (EFI_IPv6_ADDRESS)
1809 );
1810
1811 if (Ip6ModeData.AddressList != NULL) {
1812 FreePool (Ip6ModeData.AddressList);
1813 }
1814
1815 if (Ip6ModeData.GroupTable != NULL) {
1816 FreePool (Ip6ModeData.GroupTable);
1817 }
1818
1819 if (Ip6ModeData.RouteTable != NULL) {
1820 FreePool (Ip6ModeData.RouteTable);
1821 }
1822
1823 if (Ip6ModeData.NeighborCache != NULL) {
1824 FreePool (Ip6ModeData.NeighborCache);
1825 }
1826
1827 if (Ip6ModeData.PrefixTable != NULL) {
1828 FreePool (Ip6ModeData.PrefixTable);
1829 }
1830
1831 if (Ip6ModeData.IcmpTypeList != NULL) {
1832 FreePool (Ip6ModeData.IcmpTypeList);
1833 }
1834
1835 } else {
1836 Status = EFI_NO_MAPPING;
1837 goto OnExit;
1838 }
1839
1840 CopyMem (
1841 &IpInfo->Addr,
1842 &Ip6ModeData.ConfigData.StationAddress,
1843 sizeof (EFI_IPv6_ADDRESS)
1844 );
1845
1846 Status = ((EFI_IP6_PROTOCOL *) Ip)->Receive (
1847 (EFI_IP6_PROTOCOL *) Ip,
1848 &IpInfo->DummyRcvToken.Ip6Token
1849 );
1850 if (EFI_ERROR (Status)) {
1851 ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);
1852 }
1853 }
1854 } else {
1855 //
1856 // The IP instance is reset, set the stored Addr and SubnetMask to zero.
1857 //
1858 ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr));
1859 ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask));
1860 }
1861
1862 OnExit:
1863
1864 return Status;
1865 }
1866
1867
1868 /**
1869 Destroy an IP instance maintained in IpIo->IpList for
1870 sending purpose.
1871
1872 This function pairs with IpIoAddIp(). The IpInfo is previously created by
1873 IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance
1874 will be dstroyed if the RefCnt is zero.
1875
1876 @param[in] IpIo Pointer to the IP_IO instance.
1877 @param[in] IpInfo Pointer to the IpInfo to be removed.
1878
1879 **/
1880 VOID
1881 EFIAPI
1882 IpIoRemoveIp (
1883 IN IP_IO *IpIo,
1884 IN IP_IO_IP_INFO *IpInfo
1885 )
1886 {
1887
1888 UINT8 IpVersion;
1889
1890 ASSERT (IpInfo->RefCnt > 0);
1891
1892 NET_PUT_REF (IpInfo);
1893
1894 if (IpInfo->RefCnt > 0) {
1895
1896 return;
1897 }
1898
1899 IpVersion = IpIo->IpVersion;
1900
1901 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
1902
1903 RemoveEntryList (&IpInfo->Entry);
1904
1905 if (IpVersion == IP_VERSION_4){
1906 ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Configure (
1907 (EFI_IP4_PROTOCOL *) (IpInfo->Ip),
1908 NULL
1909 );
1910 IpIoCloseProtocolDestroyIpChild (
1911 IpIo->Controller,
1912 IpIo->Image,
1913 IpInfo->ChildHandle,
1914 IP_VERSION_4
1915 );
1916
1917 gBS->CloseEvent (IpInfo->DummyRcvToken.Ip4Token.Event);
1918
1919 } else {
1920
1921 ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Configure (
1922 (EFI_IP6_PROTOCOL *) (IpInfo->Ip),
1923 NULL
1924 );
1925
1926 IpIoCloseProtocolDestroyIpChild (
1927 IpIo->Controller,
1928 IpIo->Image,
1929 IpInfo->ChildHandle,
1930 IP_VERSION_6
1931 );
1932
1933 gBS->CloseEvent (IpInfo->DummyRcvToken.Ip6Token.Event);
1934 }
1935
1936 FreePool (IpInfo);
1937 }
1938
1939
1940 /**
1941 Find the first IP protocol maintained in IpIo whose local
1942 address is the same as Src.
1943
1944 This function is called when the caller needs the IpIo to send data to the
1945 specified Src. The IpIo was added previously by IpIoAddIp().
1946
1947 @param[in, out] IpIo Pointer to the pointer of the IP_IO instance.
1948 @param[in] IpVersion The version of the IP protocol to use, either
1949 IPv4 or IPv6.
1950 @param[in] Src The local IP address.
1951
1952 @return Pointer to the IP protocol can be used for sending purpose and its local
1953 address is the same with Src.
1954
1955 **/
1956 IP_IO_IP_INFO *
1957 EFIAPI
1958 IpIoFindSender (
1959 IN OUT IP_IO **IpIo,
1960 IN UINT8 IpVersion,
1961 IN EFI_IP_ADDRESS *Src
1962 )
1963 {
1964 LIST_ENTRY *IpIoEntry;
1965 IP_IO *IpIoPtr;
1966 LIST_ENTRY *IpInfoEntry;
1967 IP_IO_IP_INFO *IpInfo;
1968
1969 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
1970
1971 NET_LIST_FOR_EACH (IpIoEntry, &mActiveIpIoList) {
1972 IpIoPtr = NET_LIST_USER_STRUCT (IpIoEntry, IP_IO, Entry);
1973
1974 if (((*IpIo != NULL) && (*IpIo != IpIoPtr)) || (IpIoPtr->IpVersion != IpVersion)) {
1975 continue;
1976 }
1977
1978 NET_LIST_FOR_EACH (IpInfoEntry, &IpIoPtr->IpList) {
1979 IpInfo = NET_LIST_USER_STRUCT (IpInfoEntry, IP_IO_IP_INFO, Entry);
1980 if (IpInfo->IpVersion == IP_VERSION_4){
1981
1982 if (EFI_IP4_EQUAL (&IpInfo->Addr.v4, &Src->v4)) {
1983 *IpIo = IpIoPtr;
1984 return IpInfo;
1985 }
1986
1987 } else {
1988
1989 if (EFI_IP6_EQUAL (&IpInfo->Addr.v6, &Src->v6)) {
1990 *IpIo = IpIoPtr;
1991 return IpInfo;
1992 }
1993 }
1994
1995 }
1996 }
1997
1998 //
1999 // No match.
2000 //
2001 return NULL;
2002 }
2003
2004
2005 /**
2006 Get the ICMP error map information.
2007
2008 The ErrorStatus will be returned. The IsHard and Notify are optional. If they
2009 are not NULL, this routine will fill them.
2010
2011 @param[in] IcmpError IcmpError Type.
2012 @param[in] IpVersion The version of the IP protocol to use,
2013 either IPv4 or IPv6.
2014
2015 @param[out] IsHard Whether it is a hard error.
2016 @param[out] Notify Whether it need to notify SockError.
2017
2018 @return ICMP Error Status, such as EFI_NETWORK_UNREACHABLE.
2019
2020 **/
2021 EFI_STATUS
2022 EFIAPI
2023 IpIoGetIcmpErrStatus (
2024 IN UINT8 IcmpError,
2025 IN UINT8 IpVersion,
2026 OUT BOOLEAN *IsHard OPTIONAL,
2027 OUT BOOLEAN *Notify OPTIONAL
2028 )
2029 {
2030 if (IpVersion == IP_VERSION_4 ) {
2031 ASSERT (IcmpError <= ICMP_ERR_PARAMPROB);
2032
2033 if (IsHard != NULL) {
2034 *IsHard = mIcmpErrMap[IcmpError].IsHard;
2035 }
2036
2037 if (Notify != NULL) {
2038 *Notify = mIcmpErrMap[IcmpError].Notify;
2039 }
2040
2041 switch (IcmpError) {
2042 case ICMP_ERR_UNREACH_NET:
2043 return EFI_NETWORK_UNREACHABLE;
2044
2045 case ICMP_ERR_TIMXCEED_INTRANS:
2046 case ICMP_ERR_TIMXCEED_REASS:
2047 case ICMP_ERR_UNREACH_HOST:
2048 return EFI_HOST_UNREACHABLE;
2049
2050 case ICMP_ERR_UNREACH_PROTOCOL:
2051 return EFI_PROTOCOL_UNREACHABLE;
2052
2053 case ICMP_ERR_UNREACH_PORT:
2054 return EFI_PORT_UNREACHABLE;
2055
2056 case ICMP_ERR_MSGSIZE:
2057 case ICMP_ERR_UNREACH_SRCFAIL:
2058 case ICMP_ERR_QUENCH:
2059 case ICMP_ERR_PARAMPROB:
2060 return EFI_ICMP_ERROR;
2061
2062 default:
2063 ASSERT (FALSE);
2064 return EFI_UNSUPPORTED;
2065 }
2066
2067 } else if (IpVersion == IP_VERSION_6) {
2068
2069 ASSERT (IcmpError <= ICMP6_ERR_PARAMPROB_IPV6OPTION);
2070
2071 if (IsHard != NULL) {
2072 *IsHard = mIcmp6ErrMap[IcmpError].IsHard;
2073 }
2074
2075 if (Notify != NULL) {
2076 *Notify = mIcmp6ErrMap[IcmpError].Notify;
2077 }
2078
2079 switch (IcmpError) {
2080 case ICMP6_ERR_UNREACH_NET:
2081 return EFI_NETWORK_UNREACHABLE;
2082
2083 case ICMP6_ERR_UNREACH_HOST:
2084 case ICMP6_ERR_TIMXCEED_HOPLIMIT:
2085 case ICMP6_ERR_TIMXCEED_REASS:
2086 return EFI_HOST_UNREACHABLE;
2087
2088 case ICMP6_ERR_UNREACH_PROTOCOL:
2089 return EFI_PROTOCOL_UNREACHABLE;
2090
2091 case ICMP6_ERR_UNREACH_PORT:
2092 return EFI_PORT_UNREACHABLE;
2093
2094 case ICMP6_ERR_PACKAGE_TOOBIG:
2095 case ICMP6_ERR_PARAMPROB_HEADER:
2096 case ICMP6_ERR_PARAMPROB_NEXHEADER:
2097 case ICMP6_ERR_PARAMPROB_IPV6OPTION:
2098 return EFI_ICMP_ERROR;
2099
2100 default:
2101 ASSERT (FALSE);
2102 return EFI_UNSUPPORTED;
2103 }
2104
2105 } else {
2106 //
2107 // Should never be here
2108 //
2109 ASSERT (FALSE);
2110 return EFI_UNSUPPORTED;
2111 }
2112 }
2113
2114
2115 /**
2116 Refresh the remote peer's Neighbor Cache entries.
2117
2118 This function is called when the caller needs the IpIo to refresh the existing
2119 IPv6 neighbor cache entries since the neighbor is considered reachable by the
2120 node has recently received a confirmation that packets sent recently to the
2121 neighbor were received by its IP layer.
2122
2123 @param[in] IpIo Pointer to an IP_IO instance
2124 @param[in] Neighbor The IP address of the neighbor
2125 @param[in] Timeout Time in 100-ns units that this entry will
2126 remain in the neighbor cache. A value of
2127 zero means that the entry is permanent.
2128 A value of non-zero means that the entry is
2129 dynamic and will be deleted after Timeout.
2130
2131 @retval EFI_SUCCESS The operation is completed successfully.
2132 @retval EFI_NOT_STARTED The IpIo is not configured.
2133 @retval EFI_INVALID_PARAMETER Neighbor Address is invalid.
2134 @retval EFI_NOT_FOUND The neighbor cache entry is not in the
2135 neighbor table.
2136 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
2137
2138 **/
2139 EFI_STATUS
2140 IpIoRefreshNeighbor (
2141 IN IP_IO *IpIo,
2142 IN EFI_IP_ADDRESS *Neighbor,
2143 IN UINT32 Timeout
2144 )
2145 {
2146 EFI_IP6_PROTOCOL *Ip;
2147
2148 if (!IpIo->IsConfigured || IpIo->IpVersion != IP_VERSION_6) {
2149 return EFI_NOT_STARTED;
2150 }
2151
2152 Ip = (EFI_IP6_PROTOCOL *) (IpIo->Ip);
2153
2154 return Ip->Neighbors (Ip, FALSE, &Neighbor->v6, NULL, Timeout, TRUE);
2155 }
2156