2 Udp6 driver's whole implementation.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 UINT16 mUdp6RandomPort
;
15 This function checks and timeouts the I/O datagrams holding by the corresponding
18 @param[in] Event The event this function is registered to.
19 @param[in] Context The context data registered during the creation of
31 This function finds the udp instance by the specified <Address, Port> pair.
33 @param[in] InstanceList Pointer to the head of the list linking the udp
35 @param[in] Address Pointer to the specified IPv6 address.
36 @param[in] Port The udp port number.
38 @retval TRUE The specified <Address, Port> pair is found.
39 @retval FALSE Otherwise.
43 Udp6FindInstanceByPort (
44 IN LIST_ENTRY
*InstanceList
,
45 IN EFI_IPv6_ADDRESS
*Address
,
50 This function is the packet transmitting notify function registered to the IpIo
51 interface. It's called to signal the udp TxToken when the IpIo layer completes
52 transmitting of the udp datagram.
54 If Context is NULL, then ASSERT().
55 If NotifyData is NULL, then ASSERT().
57 @param[in] Status The completion status of the output udp datagram.
58 @param[in] Context Pointer to the context data.
59 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
60 @param[in] NotifyData Pointer to the notify data.
68 IN IP_IO_IP_PROTOCOL Sender
,
73 This function processes the received datagram passed up by the IpIo layer.
75 If NetSession is NULL, then ASSERT().
76 If Packet is NULL, then ASSERT().
77 If Context is NULL, then ASSERT().
79 @param[in] Status The status of this udp datagram.
80 @param[in] IcmpError The IcmpError code, only available when Status is
82 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
83 @param[in] Packet Pointer to the NET_BUF containing the received udp
85 @param[in] Context Pointer to the context data.
93 IN EFI_NET_SESSION_DATA
*NetSession
,
99 This function cancel the token specified by Arg in the Map.
101 @param[in] Map Pointer to the NET_MAP.
102 @param[in] Item Pointer to the NET_MAP_ITEM.
103 @param[in] Arg Pointer to the token to be cancelled, if NULL, all
104 the tokens in this Map will be cancelled.
105 This parameter is optional and may be NULL.
107 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
108 is not the same as that in the Item if Arg is not
110 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
118 IN NET_MAP_ITEM
*Item
,
119 IN VOID
*Arg OPTIONAL
123 This function check if the received udp datagram matches with the Instance.
125 @param[in] Instance Pointer to the udp instance context data.
126 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
127 from the received udp datagram.
129 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
130 @retval FALSE The udp datagram doe not match the receiving requirements of the Instance.
135 IN UDP6_INSTANCE_DATA
*Instance
,
136 IN EFI_UDP6_SESSION_DATA
*Udp6Session
140 This function removes the Wrap specified by Context and releases relevant resources.
142 @param[in] Event The Event this notify function is registered to.
143 @param[in] Context Pointer to the context data.
148 Udp6RecycleRxDataWrap (
154 This function wraps the Packet into RxData.
156 @param[in] Instance Pointer to the instance context data.
157 @param[in] Packet Pointer to the buffer containing the received
159 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
162 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
163 be returned if any error occurs.
168 IN UDP6_INSTANCE_DATA
*Instance
,
170 IN EFI_UDP6_RECEIVE_DATA
*RxData
174 This function enqueues the received datagram into the instances' receiving queues.
176 @param[in] Udp6Service Pointer to the udp service context data.
177 @param[in] Packet Pointer to the buffer containing the received
179 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
182 @return The times this datagram is enqueued.
187 IN UDP6_SERVICE_DATA
*Udp6Service
,
189 IN EFI_UDP6_RECEIVE_DATA
*RxData
193 This function delivers the datagrams enqueued in the instances.
195 @param[in] Udp6Service Pointer to the udp service context data.
200 IN UDP6_SERVICE_DATA
*Udp6Service
204 This function demultiplexes the received udp datagram to the appropriate instances.
206 @param[in] Udp6Service Pointer to the udp service context data.
207 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
208 the received datagram.
209 @param[in] Packet Pointer to the buffer containing the received udp
215 IN UDP6_SERVICE_DATA
*Udp6Service
,
216 IN EFI_NET_SESSION_DATA
*NetSession
,
221 This function handles the received Icmp Error message and demultiplexes it to the
224 @param[in] Udp6Service Pointer to the udp service context data.
225 @param[in] IcmpError The icmp error code.
226 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
227 from the received Icmp Error packet.
228 @param[in, out] Packet Pointer to the Icmp Error packet.
233 IN UDP6_SERVICE_DATA
*Udp6Service
,
235 IN EFI_NET_SESSION_DATA
*NetSession
,
236 IN OUT NET_BUF
*Packet
240 This function builds and sends out a icmp port unreachable message.
242 @param[in] IpIo Pointer to the IP_IO instance.
243 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
244 causes this icmp error message.
245 @param[in] Udp6Header Pointer to the udp header of the datagram causes
246 this icmp error message.
250 Udp6SendPortUnreach (
252 IN EFI_NET_SESSION_DATA
*NetSession
,
257 Find the key in the netmap
259 @param[in] Map The netmap to search within.
260 @param[in] Key The key to search.
262 @return The point to the item contains the Key, or NULL if Key isn't in the map.
266 Udp6MapMultiCastAddr (
272 Create the Udp service context data.
274 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
275 @param[in] ImageHandle The image handle of this udp6 driver.
276 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
278 @retval EFI_SUCCESS The udp6 service context data was created and
280 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
281 @retval Others An error condition occurred.
286 IN UDP6_SERVICE_DATA
*Udp6Service
,
287 IN EFI_HANDLE ImageHandle
,
288 IN EFI_HANDLE ControllerHandle
292 IP_IO_OPEN_DATA OpenData
;
294 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
296 Udp6Service
->Signature
= UDP6_SERVICE_DATA_SIGNATURE
;
297 Udp6Service
->ServiceBinding
= mUdp6ServiceBinding
;
298 Udp6Service
->ImageHandle
= ImageHandle
;
299 Udp6Service
->ControllerHandle
= ControllerHandle
;
300 Udp6Service
->ChildrenNumber
= 0;
302 InitializeListHead (&Udp6Service
->ChildrenList
);
305 // Create the IpIo for this service context.
307 Udp6Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
, IP_VERSION_6
);
308 if (Udp6Service
->IpIo
== NULL
) {
309 return EFI_OUT_OF_RESOURCES
;
313 // Set the OpenData used to open the IpIo.
316 &OpenData
.IpConfigData
.Ip6CfgData
,
317 &mIp6IoDefaultIpConfigData
,
318 sizeof (EFI_IP6_CONFIG_DATA
)
320 OpenData
.RcvdContext
= (VOID
*)Udp6Service
;
321 OpenData
.SndContext
= NULL
;
322 OpenData
.PktRcvdNotify
= Udp6DgramRcvd
;
323 OpenData
.PktSentNotify
= Udp6DgramSent
;
326 // Configure and start the IpIo.
328 Status
= IpIoOpen (Udp6Service
->IpIo
, &OpenData
);
329 if (EFI_ERROR (Status
)) {
334 // Create the event for Udp timeout checking.
336 Status
= gBS
->CreateEvent (
337 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
341 &Udp6Service
->TimeoutEvent
343 if (EFI_ERROR (Status
)) {
348 // Start the timeout timer event.
350 Status
= gBS
->SetTimer (
351 Udp6Service
->TimeoutEvent
,
353 UDP6_TIMEOUT_INTERVAL
355 if (EFI_ERROR (Status
)) {
363 if (Udp6Service
->TimeoutEvent
!= NULL
) {
364 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
367 IpIoDestroy (Udp6Service
->IpIo
);
368 Udp6Service
->IpIo
= NULL
;
374 Clean the Udp service context data.
376 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
381 IN OUT UDP6_SERVICE_DATA
*Udp6Service
385 // Close the TimeoutEvent timer.
387 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
392 IpIoDestroy (Udp6Service
->IpIo
);
393 Udp6Service
->IpIo
= NULL
;
395 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
399 This function checks and times out the I/O datagrams listed in the
400 UDP6_SERVICE_DATA which is specified by the input parameter Context.
403 @param[in] Event The event this function registered to.
404 @param[in] Context The context data registered during the creation of
415 UDP6_SERVICE_DATA
*Udp6Service
;
417 UDP6_INSTANCE_DATA
*Instance
;
418 LIST_ENTRY
*WrapEntry
;
419 LIST_ENTRY
*NextEntry
;
420 UDP6_RXDATA_WRAP
*Wrap
;
422 Udp6Service
= (UDP6_SERVICE_DATA
*)Context
;
423 NET_CHECK_SIGNATURE (Udp6Service
, UDP6_SERVICE_DATA_SIGNATURE
);
425 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
427 // Iterate all the instances belonging to this service context.
429 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
430 NET_CHECK_SIGNATURE (Instance
, UDP6_INSTANCE_DATA_SIGNATURE
);
432 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
434 // Skip this instance if it's not configured or no receive timeout.
439 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
441 // Iterate all the rxdatas belonging to this udp instance.
443 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP6_RXDATA_WRAP
, Link
);
445 if (Wrap
->TimeoutTick
< UDP6_TIMEOUT_INTERVAL
/ 10) {
447 // Remove this RxData if it timeouts.
449 Udp6RecycleRxDataWrap (NULL
, (VOID
*)Wrap
);
451 Wrap
->TimeoutTick
-= UDP6_TIMEOUT_INTERVAL
/ 10;
458 This function initializes the new created udp instance.
460 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
461 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
466 IN UDP6_SERVICE_DATA
*Udp6Service
,
467 IN OUT UDP6_INSTANCE_DATA
*Instance
471 // Set the signature.
473 Instance
->Signature
= UDP6_INSTANCE_DATA_SIGNATURE
;
478 InitializeListHead (&Instance
->Link
);
479 InitializeListHead (&Instance
->RcvdDgramQue
);
480 InitializeListHead (&Instance
->DeliveredDgramQue
);
483 // Init the NET_MAPs.
485 NetMapInit (&Instance
->TxTokens
);
486 NetMapInit (&Instance
->RxTokens
);
487 NetMapInit (&Instance
->McastIps
);
490 // Save the pointer to the UDP6_SERVICE_DATA, and initialize other members.
492 Instance
->Udp6Service
= Udp6Service
;
493 CopyMem (&Instance
->Udp6Proto
, &mUdp6Protocol
, sizeof (EFI_UDP6_PROTOCOL
));
494 Instance
->IcmpError
= EFI_SUCCESS
;
495 Instance
->Configured
= FALSE
;
496 Instance
->IsNoMapping
= FALSE
;
497 Instance
->InDestroy
= FALSE
;
501 This function cleans the udp instance.
503 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
508 IN OUT UDP6_INSTANCE_DATA
*Instance
511 NetMapClean (&Instance
->McastIps
);
512 NetMapClean (&Instance
->RxTokens
);
513 NetMapClean (&Instance
->TxTokens
);
517 This function finds the udp instance by the specified <Address, Port> pair.
519 @param[in] InstanceList Pointer to the head of the list linking the udp
521 @param[in] Address Pointer to the specified IPv6 address.
522 @param[in] Port The udp port number.
524 @retval TRUE The specified <Address, Port> pair is found.
525 @retval FALSE Otherwise.
529 Udp6FindInstanceByPort (
530 IN LIST_ENTRY
*InstanceList
,
531 IN EFI_IPv6_ADDRESS
*Address
,
536 UDP6_INSTANCE_DATA
*Instance
;
537 EFI_UDP6_CONFIG_DATA
*ConfigData
;
539 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
541 // Iterate all the udp instances.
543 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
544 ConfigData
= &Instance
->ConfigData
;
546 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
548 // If the instance is not configured, or the configdata of the instance indicates
549 // this instance accepts any port, skip it.
554 if (EFI_IP6_EQUAL (&ConfigData
->StationAddress
, Address
) &&
555 (ConfigData
->StationPort
== Port
)
559 // If both the address and the port are the same, return TRUE.
566 // Return FALSE when matching fails.
572 This function tries to bind the udp instance according to the configured port
575 @param[in] InstanceList Pointer to the head of the list linking the udp
577 @param[in] ConfigData Pointer to the ConfigData of the instance to be
580 @retval EFI_SUCCESS The bound operation completed successfully.
581 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
582 already used by other instance.
583 @retval EFI_OUT_OF_RESOURCES No available port resources.
588 IN LIST_ENTRY
*InstanceList
,
589 IN EFI_UDP6_CONFIG_DATA
*ConfigData
592 EFI_IPv6_ADDRESS
*StationAddress
;
595 if (ConfigData
->AcceptAnyPort
) {
599 StationAddress
= &ConfigData
->StationAddress
;
601 if (ConfigData
->StationPort
!= 0) {
602 if (!ConfigData
->AllowDuplicatePort
&&
603 Udp6FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)
607 // Do not allow duplicate ports and the port is already used by other instance.
609 return EFI_ACCESS_DENIED
;
613 // Select a random port for this instance.
615 if (ConfigData
->AllowDuplicatePort
) {
617 // Just pick up the random port if the instance allows duplicate port.
619 ConfigData
->StationPort
= mUdp6RandomPort
;
621 StartPort
= mUdp6RandomPort
;
623 while (Udp6FindInstanceByPort (InstanceList
, StationAddress
, mUdp6RandomPort
)) {
625 if (mUdp6RandomPort
== 0) {
626 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
629 if (mUdp6RandomPort
== StartPort
) {
631 // No available port.
633 return EFI_OUT_OF_RESOURCES
;
637 ConfigData
->StationPort
= mUdp6RandomPort
;
641 if (mUdp6RandomPort
== 0) {
642 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
650 This function is used to check whether the NewConfigData has any un-reconfigurable
651 parameters changed compared to the OldConfigData.
653 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
655 @param[in] NewConfigData Pointer to the new ConfigData.
657 @retval TRUE The instance is reconfigurable according to the NewConfigData.
658 @retval FALSE Otherwise.
662 Udp6IsReconfigurable (
663 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
664 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
667 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
668 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
669 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)
673 // The receiving filter parameters cannot be changed.
678 if ((!NewConfigData
->AcceptAnyPort
) &&
679 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)
683 // The port is not changeable.
688 if (!EFI_IP6_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
)) {
690 // The StationAddress is not the same.
695 if (!EFI_IP6_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
697 // The remoteaddress is not the same.
702 if (!NetIp6IsUnspecifiedAddr (&NewConfigData
->RemoteAddress
) &&
703 (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)
707 // The RemotePort differs if it's designated in the configdata.
713 // All checks pass, return TRUE.
719 This function builds the Ip6 configdata from the Udp6ConfigData.
721 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
722 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
726 Udp6BuildIp6ConfigData (
727 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
728 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
733 &mIp6IoDefaultIpConfigData
,
734 sizeof (EFI_IP6_CONFIG_DATA
)
736 Ip6ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
737 Ip6ConfigData
->AcceptPromiscuous
= Udp6ConfigData
->AcceptPromiscuous
;
738 IP6_COPY_ADDRESS (&Ip6ConfigData
->StationAddress
, &Udp6ConfigData
->StationAddress
);
739 IP6_COPY_ADDRESS (&Ip6ConfigData
->DestinationAddress
, &Udp6ConfigData
->RemoteAddress
);
741 // Use the -1 magic number to disable the receiving process of the ip instance.
743 Ip6ConfigData
->ReceiveTimeout
= (UINT32
)(-1);
747 This function validates the TxToken. It returns the error code according to the spec.
749 @param[in] Instance Pointer to the udp instance context data.
750 @param[in] TxToken Pointer to the token to be checked.
752 @retval EFI_SUCCESS The TxToken is valid.
753 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
755 Token.Packet.TxData is NULL;
756 Token.Packet.TxData.FragmentCount is zero;
757 Token.Packet.TxData.DataLength is not equal to the
758 sum of fragment lengths;
760 Token.Packet.TxData.FragmentTable[].FragmentLength
763 Token.Packet.TxData.FragmentTable[].FragmentBuffer
765 UdpSessionData.DestinationAddress are not valid
766 unicast IPv6 addresses if the UdpSessionData is
768 UdpSessionData.DestinationPort and
769 ConfigData.RemotePort are all zero if the
770 UdpSessionData is not NULL.
771 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
776 Udp6ValidateTxToken (
777 IN UDP6_INSTANCE_DATA
*Instance
,
778 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
781 EFI_UDP6_TRANSMIT_DATA
*TxData
;
784 EFI_UDP6_CONFIG_DATA
*ConfigData
;
785 EFI_UDP6_SESSION_DATA
*UdpSessionData
;
787 if (TxToken
->Event
== NULL
) {
788 return EFI_INVALID_PARAMETER
;
791 TxData
= TxToken
->Packet
.TxData
;
793 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
794 return EFI_INVALID_PARAMETER
;
798 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
799 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
800 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)
804 // If the FragmentBuffer is NULL, or the FragmentLeng is zero.
806 return EFI_INVALID_PARAMETER
;
809 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
812 if (TotalLen
!= TxData
->DataLength
) {
814 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
817 return EFI_INVALID_PARAMETER
;
820 ConfigData
= &Instance
->ConfigData
;
821 UdpSessionData
= TxData
->UdpSessionData
;
823 if (UdpSessionData
!= NULL
) {
824 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
826 // Ambiguous; no available DestinationPort for this token.
828 return EFI_INVALID_PARAMETER
;
831 if (NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
832 NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
836 // The DestinationAddress is not specified.
838 return EFI_INVALID_PARAMETER
;
841 if (!NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
842 !NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
846 // The ConfigData.RemoteAddress is not zero and the UdpSessionData.DestinationAddress
849 return EFI_INVALID_PARAMETER
;
851 } else if (NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)) {
853 // The configured RemoteAddress is all zero, and the user doesn't override the
854 // destination address.
856 return EFI_INVALID_PARAMETER
;
859 if (TxData
->DataLength
> UDP6_MAX_DATA_SIZE
) {
860 return EFI_BAD_BUFFER_SIZE
;
867 This function checks whether the specified Token duplicates the one in the Map.
869 @param[in] Map Pointer to the NET_MAP.
870 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
872 @param[in] Context Pointer to the Token to be checked.
874 @retval EFI_SUCCESS The Token specified by Context differs from the
876 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
883 IN NET_MAP_ITEM
*Item
,
887 EFI_UDP6_COMPLETION_TOKEN
*Token
;
888 EFI_UDP6_COMPLETION_TOKEN
*TokenInItem
;
890 Token
= (EFI_UDP6_COMPLETION_TOKEN
*)Context
;
891 TokenInItem
= (EFI_UDP6_COMPLETION_TOKEN
*)Item
->Key
;
893 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
895 // The Token duplicates with the TokenInItem in case either the two pointers are the
896 // same, or the Events of these two tokens are the same.
898 return EFI_ACCESS_DENIED
;
905 This function calculates the checksum for the Packet, utilizing the pre-calculated
906 pseudo HeadSum to reduce some overhead.
908 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
909 @param[in] HeadSum Checksum of the pseudo header, except the length
912 @return The 16-bit checksum of this udp datagram.
923 Checksum
= NetbufChecksum (Packet
);
924 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
926 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
)Packet
->TotalSize
));
927 Checksum
= (UINT16
)(~Checksum
);
932 This function removes the specified Token from the TokenMap.
934 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
935 @param[in] Token Pointer to the Token to be removed.
937 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
938 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
943 IN NET_MAP
*TokenMap
,
944 IN EFI_UDP6_COMPLETION_TOKEN
*Token
950 // Find the Token first.
952 Item
= NetMapFindKey (TokenMap
, (VOID
*)Token
);
956 // Remove the token if it's found in the map.
958 NetMapRemoveItem (TokenMap
, Item
, NULL
);
963 return EFI_NOT_FOUND
;
967 This function is the packet transmitting notify function registered to the IpIo
968 interface. It's called to signal the udp TxToken when IpIo layer completes the
969 transmitting of the udp datagram.
971 If Context is NULL, then ASSERT().
972 If NotifyData is NULL, then ASSERT().
974 @param[in] Status The completion status of the output udp datagram.
975 @param[in] Context Pointer to the context data.
976 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
977 @param[in] NotifyData Pointer to the notify data.
983 IN EFI_STATUS Status
,
985 IN IP_IO_IP_PROTOCOL Sender
,
989 UDP6_INSTANCE_DATA
*Instance
;
990 EFI_UDP6_COMPLETION_TOKEN
*Token
;
992 ASSERT (Context
!= NULL
&& NotifyData
!= NULL
);
994 Instance
= (UDP6_INSTANCE_DATA
*)Context
;
995 Token
= (EFI_UDP6_COMPLETION_TOKEN
*)NotifyData
;
997 if (Udp6RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
999 // The token may be cancelled. Only signal it if the remove operation succeeds.
1001 Token
->Status
= Status
;
1002 gBS
->SignalEvent (Token
->Event
);
1008 This function processes the received datagram passed up by the IpIo layer.
1010 If NetSession is NULL, then ASSERT().
1011 If Packet is NULL, then ASSERT().
1012 If Context is NULL, then ASSERT().
1014 @param[in] Status The status of this udp datagram.
1015 @param[in] IcmpError The IcmpError code, only available when Status is
1017 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
1018 @param[in] Packet Pointer to the NET_BUF containing the received udp
1020 @param[in] Context Pointer to the context data.
1026 IN EFI_STATUS Status
,
1028 IN EFI_NET_SESSION_DATA
*NetSession
,
1033 ASSERT (NetSession
!= NULL
&& Packet
!= NULL
&& Context
!= NULL
);
1034 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
1037 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
1039 if (Status
== EFI_SUCCESS
) {
1041 // Demultiplex the received datagram.
1043 Udp6Demultiplex ((UDP6_SERVICE_DATA
*)Context
, NetSession
, Packet
);
1046 // Handle the ICMP6 Error packet.
1048 Udp6IcmpHandler ((UDP6_SERVICE_DATA
*)Context
, IcmpError
, NetSession
, Packet
);
1052 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
1053 // that are signaled with received data.
1059 This function removes the multicast group specified by Arg from the Map.
1061 @param[in] Map Pointer to the NET_MAP.
1062 @param[in] Item Pointer to the NET_MAP_ITEM.
1063 @param[in] Arg Pointer to the Arg, it's the pointer to a
1064 multicast IPv6 Address. This parameter is
1065 optional and may be NULL.
1067 @retval EFI_SUCCESS The multicast address is removed.
1068 @retval EFI_ABORTED The specified multicast address is removed, and the
1076 IN NET_MAP_ITEM
*Item
,
1077 IN VOID
*Arg OPTIONAL
1080 EFI_IPv6_ADDRESS
*McastIp
;
1084 if ((McastIp
!= NULL
) &&
1085 !EFI_IP6_EQUAL (McastIp
, ((EFI_IPv6_ADDRESS
*)Item
->Key
))
1089 // McastIp is not NULL and the multicast address contained in the Item
1090 // is not the same as McastIp.
1095 FreePool (Item
->Key
);
1098 // Remove this Item.
1100 NetMapRemoveItem (Map
, Item
, NULL
);
1102 if (McastIp
!= NULL
) {
1104 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
1113 This function cancel the token specified by Arg in the Map.
1115 @param[in] Map Pointer to the NET_MAP.
1116 @param[in] Item Pointer to the NET_MAP_ITEM.
1117 @param[in] Arg Pointer to the token to be cancelled. If NULL, all
1118 the tokens in this Map will be cancelled.
1119 This parameter is optional and may be NULL.
1121 @retval EFI_SUCCESS The token is cancelled if Arg is NULL, or the token
1122 is not the same as that in the Item, if Arg is not
1124 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1132 IN NET_MAP_ITEM
*Item
,
1133 IN VOID
*Arg OPTIONAL
1136 EFI_UDP6_COMPLETION_TOKEN
*TokenToCancel
;
1140 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1144 if (Item
->Value
!= NULL
) {
1146 // If the token is a transmit token, the corresponding Packet is recorded in
1147 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1148 // will invoke Udp6DgramSent, the token will be signaled and this Item will
1149 // be removed from the Map there.
1151 Packet
= (NET_BUF
*)(Item
->Value
);
1152 IpIo
= (IP_IO
*)(*((UINTN
*)&Packet
->ProtoData
[0]));
1154 IpIoCancelTxToken (IpIo
, Packet
);
1157 // The token is a receive token. Abort it and remove it from the Map.
1159 TokenToCancel
= (EFI_UDP6_COMPLETION_TOKEN
*)Item
->Key
;
1160 NetMapRemoveItem (Map
, Item
, NULL
);
1162 TokenToCancel
->Status
= EFI_ABORTED
;
1163 gBS
->SignalEvent (TokenToCancel
->Event
);
1174 This function removes all the Wrap datas in the RcvdDgramQue.
1176 @param[in] Instance Pointer to the Udp6 Instance.
1180 Udp6FlushRcvdDgram (
1181 IN UDP6_INSTANCE_DATA
*Instance
1184 UDP6_RXDATA_WRAP
*Wrap
;
1186 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1188 // Iterate all the Wraps in the RcvdDgramQue.
1190 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1193 // The Wrap will be removed from the RcvdDgramQue by this function call.
1195 Udp6RecycleRxDataWrap (NULL
, (VOID
*)Wrap
);
1200 Cancel Udp6 tokens from the Udp6 instance.
1202 @param[in] Instance Pointer to the udp instance context data.
1203 @param[in] Token Pointer to the token to be canceled. If NULL, all
1204 tokens in this instance will be cancelled.
1205 This parameter is optional and may be NULL.
1207 @retval EFI_SUCCESS The Token is cancelled.
1208 @retval EFI_NOT_FOUND The Token is not found.
1212 Udp6InstanceCancelToken (
1213 IN UDP6_INSTANCE_DATA
*Instance
,
1214 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
1220 // Cancel this token from the TxTokens map.
1222 Status
= NetMapIterate (&Instance
->TxTokens
, Udp6CancelTokens
, Token
);
1224 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1226 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1227 // the TxTokens and returns success.
1233 // Try to cancel this token from the RxTokens map in condition either the Token
1234 // is NULL or the specified Token is not in TxTokens.
1236 Status
= NetMapIterate (&Instance
->RxTokens
, Udp6CancelTokens
, Token
);
1238 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1240 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1241 // TxTokens nor the RxTokens, or say, it's not found.
1243 return EFI_NOT_FOUND
;
1248 ((0 == NetMapGetCount (&Instance
->TxTokens
)) &&
1249 (0 == NetMapGetCount (&Instance
->RxTokens
)))
1256 This function checks if the received udp datagram matches with the Instance.
1258 @param[in] Instance Pointer to the udp instance context data.
1259 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
1260 from the received udp datagram.
1262 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
1263 @retval FALSE The udp datagram does not match the receiving requirements of the Instance.
1268 IN UDP6_INSTANCE_DATA
*Instance
,
1269 IN EFI_UDP6_SESSION_DATA
*Udp6Session
1272 EFI_UDP6_CONFIG_DATA
*ConfigData
;
1273 EFI_IPv6_ADDRESS Destination
;
1275 ConfigData
= &Instance
->ConfigData
;
1277 if (ConfigData
->AcceptPromiscuous
) {
1279 // Always matches if this instance is in the promiscuous state.
1284 if ((!ConfigData
->AcceptAnyPort
&& (Udp6Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1285 ((ConfigData
->RemotePort
!= 0) && (Udp6Session
->SourcePort
!= ConfigData
->RemotePort
))
1289 // The local port or the remote port doesn't match.
1294 if (!NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
) &&
1295 !EFI_IP6_EQUAL (&ConfigData
->RemoteAddress
, &Udp6Session
->SourceAddress
)
1299 // This datagram doesn't come from the instance's specified sender.
1304 if (NetIp6IsUnspecifiedAddr (&ConfigData
->StationAddress
) ||
1305 EFI_IP6_EQUAL (&Udp6Session
->DestinationAddress
, &ConfigData
->StationAddress
)
1309 // The instance is configured to receive datagrams destinated to any station IP or
1310 // the destination address of this datagram matches the configured station IP.
1315 IP6_COPY_ADDRESS (&Destination
, &Udp6Session
->DestinationAddress
);
1317 if (IP6_IS_MULTICAST (&Destination
) &&
1318 (NULL
!= Udp6MapMultiCastAddr (&Instance
->McastIps
, &Destination
))
1322 // It's a multicast packet and the multicast address is accepted by this instance.
1331 This function removes the Wrap specified by Context and release relevant resources.
1333 @param[in] Event The Event this notify function registered to.
1334 @param[in] Context Pointer to the context data.
1339 Udp6RecycleRxDataWrap (
1344 UDP6_RXDATA_WRAP
*Wrap
;
1346 Wrap
= (UDP6_RXDATA_WRAP
*)Context
;
1349 // Remove the Wrap from the list it belongs to.
1351 RemoveEntryList (&Wrap
->Link
);
1354 // Free the Packet associated with this Wrap.
1356 NetbufFree (Wrap
->Packet
);
1361 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1367 This function wraps the Packet into RxData.
1369 @param[in] Instance Pointer to the instance context data.
1370 @param[in] Packet Pointer to the buffer containing the received
1372 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1375 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
1376 be returned if any error occurs.
1381 IN UDP6_INSTANCE_DATA
*Instance
,
1383 IN EFI_UDP6_RECEIVE_DATA
*RxData
1387 UDP6_RXDATA_WRAP
*Wrap
;
1390 // Allocate buffer for the Wrap.
1392 Wrap
= AllocateZeroPool (
1393 sizeof (UDP6_RXDATA_WRAP
) +
1394 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP6_FRAGMENT_DATA
)
1400 InitializeListHead (&Wrap
->Link
);
1402 CopyMem (&Wrap
->RxData
, RxData
, sizeof (EFI_UDP6_RECEIVE_DATA
));
1404 // Create the Recycle event.
1406 Status
= gBS
->CreateEvent (
1409 Udp6RecycleRxDataWrap
,
1411 &Wrap
->RxData
.RecycleSignal
1413 if (EFI_ERROR (Status
)) {
1418 Wrap
->Packet
= Packet
;
1419 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1425 This function enqueues the received datagram into the instances' receiving queues.
1427 @param[in] Udp6Service Pointer to the udp service context data.
1428 @param[in] Packet Pointer to the buffer containing the received
1430 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1433 @return The times this datagram is enqueued.
1438 IN UDP6_SERVICE_DATA
*Udp6Service
,
1440 IN EFI_UDP6_RECEIVE_DATA
*RxData
1444 UDP6_INSTANCE_DATA
*Instance
;
1445 UDP6_RXDATA_WRAP
*Wrap
;
1450 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1452 // Iterate the instances.
1454 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1456 if (!Instance
->Configured
) {
1460 if (Udp6MatchDgram (Instance
, &RxData
->UdpSession
)) {
1462 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1464 Wrap
= Udp6WrapRxData (Instance
, Packet
, RxData
);
1469 NET_GET_REF (Packet
);
1471 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1481 This function delivers the received datagrams to the specified instance.
1483 @param[in] Instance Pointer to the instance context data.
1487 Udp6InstanceDeliverDgram (
1488 IN UDP6_INSTANCE_DATA
*Instance
1491 UDP6_RXDATA_WRAP
*Wrap
;
1492 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1494 EFI_UDP6_RECEIVE_DATA
*RxData
;
1497 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1498 !NetMapIsEmpty (&Instance
->RxTokens
)
1501 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1503 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1505 // Duplicate the Packet if it is shared between instances.
1507 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1512 NetbufFree (Wrap
->Packet
);
1517 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1519 Token
= (EFI_UDP6_COMPLETION_TOKEN
*)NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1522 // Build the FragmentTable and set the FragmentCount in RxData.
1524 RxData
= &Wrap
->RxData
;
1525 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1529 (NET_FRAGMENT
*)RxData
->FragmentTable
,
1530 &RxData
->FragmentCount
1533 Token
->Status
= EFI_SUCCESS
;
1534 Token
->Packet
.RxData
= &Wrap
->RxData
;
1536 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1537 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1538 gBS
->RestoreTPL (OldTpl
);
1540 gBS
->SignalEvent (Token
->Event
);
1545 This function delivers the datagrams enqueued in the instances.
1547 @param[in] Udp6Service Pointer to the udp service context data.
1552 IN UDP6_SERVICE_DATA
*Udp6Service
1556 UDP6_INSTANCE_DATA
*Instance
;
1558 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1560 // Iterate the instances.
1562 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1564 if (!Instance
->Configured
) {
1569 // Deliver the datagrams of this instance.
1571 Udp6InstanceDeliverDgram (Instance
);
1576 This function demultiplexes the received udp datagram to the appropriate instances.
1578 @param[in] Udp6Service Pointer to the udp service context data.
1579 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
1580 the received datagram.
1581 @param[in] Packet Pointer to the buffer containing the received udp
1587 IN UDP6_SERVICE_DATA
*Udp6Service
,
1588 IN EFI_NET_SESSION_DATA
*NetSession
,
1592 EFI_UDP_HEADER
*Udp6Header
;
1594 EFI_UDP6_RECEIVE_DATA RxData
;
1595 EFI_UDP6_SESSION_DATA
*Udp6Session
;
1598 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1599 NetbufFree (Packet
);
1604 // Get the datagram header from the packet buffer.
1606 Udp6Header
= (EFI_UDP_HEADER
*)NetbufGetByte (Packet
, 0, NULL
);
1607 ASSERT (Udp6Header
!= NULL
);
1608 if (Udp6Header
== NULL
) {
1609 NetbufFree (Packet
);
1613 if (Udp6Header
->Checksum
!= 0) {
1615 // check the checksum.
1617 HeadSum
= NetIp6PseudoHeadChecksum (
1618 &NetSession
->Source
.v6
,
1619 &NetSession
->Dest
.v6
,
1624 if (Udp6Checksum (Packet
, HeadSum
) != 0) {
1628 NetbufFree (Packet
);
1633 Udp6Session
= &RxData
.UdpSession
;
1634 Udp6Session
->SourcePort
= NTOHS (Udp6Header
->SrcPort
);
1635 Udp6Session
->DestinationPort
= NTOHS (Udp6Header
->DstPort
);
1637 IP6_COPY_ADDRESS (&Udp6Session
->SourceAddress
, &NetSession
->Source
);
1638 IP6_COPY_ADDRESS (&Udp6Session
->DestinationAddress
, &NetSession
->Dest
);
1641 // Trim the UDP header.
1643 NetbufTrim (Packet
, UDP6_HEADER_SIZE
, TRUE
);
1645 RxData
.DataLength
= (UINT32
)Packet
->TotalSize
;
1648 // Try to enqueue this datagram into the instances.
1650 Enqueued
= Udp6EnqueueDgram (Udp6Service
, Packet
, &RxData
);
1652 if (Enqueued
== 0) {
1654 // Send the port unreachable ICMP packet before we free this NET_BUF
1656 Udp6SendPortUnreach (Udp6Service
->IpIo
, NetSession
, Udp6Header
);
1660 // Try to free the packet before deliver it.
1662 NetbufFree (Packet
);
1666 // Deliver the datagram.
1668 Udp6DeliverDgram (Udp6Service
);
1673 This function builds and sends out a icmp port unreachable message.
1675 @param[in] IpIo Pointer to the IP_IO instance.
1676 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1677 causes this icmp error message.
1678 @param[in] Udp6Header Pointer to the udp header of the datagram causes
1679 this icmp error message.
1683 Udp6SendPortUnreach (
1685 IN EFI_NET_SESSION_DATA
*NetSession
,
1691 IP6_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1693 IP_IO_OVERRIDE Override
;
1694 IP_IO_IP_INFO
*IpSender
;
1695 EFI_IP6_MODE_DATA
*Ip6ModeData
;
1697 EFI_IP6_PROTOCOL
*Ip6Protocol
;
1702 // An ICMPv6 error message MUST NOT be originated as A packet destined to
1703 // 1) an IPv6 multicast address 2) The IPv6 Unspecified Address
1705 if (NetSession
->IpVersion
== IP_VERSION_6
) {
1706 if (NetIp6IsUnspecifiedAddr (&NetSession
->Dest
.v6
) ||
1707 IP6_IS_MULTICAST (&NetSession
->Dest
.v6
)
1714 IpSender
= IpIoFindSender (&IpIo
, NetSession
->IpVersion
, &NetSession
->Dest
);
1717 // Get the Ipv6 Mode Data.
1719 Ip6ModeData
= AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA
));
1720 ASSERT (Ip6ModeData
!= NULL
);
1721 if (Ip6ModeData
== NULL
) {
1726 // If not finding the related IpSender use the default IpIo to send out
1727 // the port unreachable ICMP message.
1729 if (IpSender
== NULL
) {
1730 Ip6Protocol
= IpIo
->Ip
.Ip6
;
1732 Ip6Protocol
= IpSender
->Ip
.Ip6
;
1735 Status
= Ip6Protocol
->GetModeData (
1742 if (EFI_ERROR (Status
)) {
1747 // The ICMP6 packet length, includes whole invoking packet and ICMP6 error header.
1749 Len
= NetSession
->IpHdrLen
+
1750 NTOHS (((EFI_UDP_HEADER
*)Udp6Header
)->Length
) +
1751 sizeof (IP6_ICMP_ERROR_HEAD
);
1754 // If the ICMP6 packet length larger than IP MTU, adjust its length to MTU.
1756 if (Ip6ModeData
->MaxPacketSize
< Len
) {
1757 Len
= Ip6ModeData
->MaxPacketSize
;
1761 // Allocate buffer for the icmp error message.
1763 Packet
= NetbufAlloc (Len
);
1764 if (Packet
== NULL
) {
1769 // Allocate space for the IP6_ICMP_ERROR_HEAD.
1771 IcmpErrHdr
= (IP6_ICMP_ERROR_HEAD
*)NetbufAllocSpace (Packet
, Len
, FALSE
);
1772 ASSERT (IcmpErrHdr
!= NULL
);
1773 if (IcmpErrHdr
== NULL
) {
1778 // Set the required fields for the icmp port unreachable message.
1780 IcmpErrHdr
->Head
.Type
= ICMP_V6_DEST_UNREACHABLE
;
1781 IcmpErrHdr
->Head
.Code
= ICMP_V6_PORT_UNREACHABLE
;
1782 IcmpErrHdr
->Head
.Checksum
= 0;
1783 IcmpErrHdr
->Fourth
= 0;
1786 // Copy as much of invoking Packet as possible without the ICMPv6 packet
1787 // exceeding the minimum Ipv6 MTU. The length of IP6_ICMP_ERROR_HEAD contains
1788 // the length of EFI_IP6_HEADER, so when using the length of IP6_ICMP_ERROR_HEAD
1789 // for pointer movement that fact should be considered.
1791 Ptr
= (VOID
*)&IcmpErrHdr
->Head
;
1792 Ptr
= (UINT8
*)(UINTN
)((UINTN
)Ptr
+ sizeof (IP6_ICMP_ERROR_HEAD
) - sizeof (EFI_IP6_HEADER
));
1793 CopyMem (Ptr
, NetSession
->IpHdr
.Ip6Hdr
, NetSession
->IpHdrLen
);
1795 Ptr
+ NetSession
->IpHdrLen
,
1797 Len
- NetSession
->IpHdrLen
- sizeof (IP6_ICMP_ERROR_HEAD
) + sizeof (EFI_IP6_HEADER
)
1801 // Set the checksum as zero, and IP6 driver will calculate it with pseudo header.
1803 IcmpErrHdr
->Head
.Checksum
= 0;
1806 // Fill the override data.
1808 Override
.Ip6OverrideData
.FlowLabel
= 0;
1809 Override
.Ip6OverrideData
.HopLimit
= 255;
1810 Override
.Ip6OverrideData
.Protocol
= IP6_ICMP
;
1813 // Send out this icmp packet.
1815 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, &NetSession
->Source
, &Override
);
1817 NetbufFree (Packet
);
1820 if (Ip6ModeData
!= NULL
) {
1821 FreePool (Ip6ModeData
);
1826 This function handles the received Icmp Error message and de-multiplexes it to the
1829 @param[in] Udp6Service Pointer to the udp service context data.
1830 @param[in] IcmpError The icmp error code.
1831 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1832 from the received Icmp Error packet.
1833 @param[in, out] Packet Pointer to the Icmp Error packet.
1838 IN UDP6_SERVICE_DATA
*Udp6Service
,
1840 IN EFI_NET_SESSION_DATA
*NetSession
,
1841 IN OUT NET_BUF
*Packet
1844 EFI_UDP_HEADER
*Udp6Header
;
1845 EFI_UDP6_SESSION_DATA Udp6Session
;
1847 UDP6_INSTANCE_DATA
*Instance
;
1849 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1850 NetbufFree (Packet
);
1854 Udp6Header
= (EFI_UDP_HEADER
*)NetbufGetByte (Packet
, 0, NULL
);
1855 ASSERT (Udp6Header
!= NULL
);
1856 if (Udp6Header
== NULL
) {
1857 NetbufFree (Packet
);
1861 IP6_COPY_ADDRESS (&Udp6Session
.SourceAddress
, &NetSession
->Source
);
1862 IP6_COPY_ADDRESS (&Udp6Session
.DestinationAddress
, &NetSession
->Dest
);
1864 Udp6Session
.SourcePort
= NTOHS (Udp6Header
->DstPort
);
1865 Udp6Session
.DestinationPort
= NTOHS (Udp6Header
->SrcPort
);
1867 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1869 // Iterate all the instances.
1871 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1873 if (!Instance
->Configured
) {
1877 if (Udp6MatchDgram (Instance
, &Udp6Session
)) {
1879 // Translate the Icmp Error code according to the udp spec.
1881 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, IP_VERSION_6
, NULL
, NULL
);
1883 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1884 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1888 // Notify the instance with the received Icmp Error.
1890 Udp6ReportIcmpError (Instance
);
1896 NetbufFree (Packet
);
1900 This function reports the received ICMP error.
1902 @param[in] Instance Pointer to the udp instance context data.
1906 Udp6ReportIcmpError (
1907 IN UDP6_INSTANCE_DATA
*Instance
1910 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1912 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1914 // There are no receive tokens to deliver the ICMP error.
1919 if (EFI_ERROR (Instance
->IcmpError
)) {
1921 // Try to get a RxToken from the RxTokens map.
1923 Token
= (EFI_UDP6_COMPLETION_TOKEN
*)NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1925 if (Token
!= NULL
) {
1927 // Report the error through the Token.
1929 Token
->Status
= Instance
->IcmpError
;
1930 gBS
->SignalEvent (Token
->Event
);
1933 // Clear the IcmpError.
1935 Instance
->IcmpError
= EFI_SUCCESS
;
1941 This function is a dummy ext-free function for the NET_BUF created for the output
1944 @param[in] Context Pointer to the context data.
1949 Udp6NetVectorExtFree (
1956 Find the key in the netmap.
1958 @param[in] Map The netmap to search within.
1959 @param[in] Key The key to search.
1961 @return The point to the item contains the Key, or NULL, if Key isn't in the map.
1965 Udp6MapMultiCastAddr (
1972 EFI_IPv6_ADDRESS
*Addr
;
1974 ASSERT (Map
!= NULL
);
1975 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
1976 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1977 Addr
= (EFI_IPv6_ADDRESS
*)Item
->Key
;
1978 if (EFI_IP6_EQUAL (Addr
, Key
)) {