2 Udp6 driver's whole implementation.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UINT16 mUdp6RandomPort
;
21 This function checks and timeouts the I/O datagrams holding by the corresponding
24 @param[in] Event The event this function is registered to.
25 @param[in] Context The context data registered during the creation of
37 This function finds the udp instance by the specified <Address, Port> pair.
39 @param[in] InstanceList Pointer to the head of the list linking the udp
41 @param[in] Address Pointer to the specified IPv6 address.
42 @param[in] Port The udp port number.
44 @retval TRUE The specified <Address, Port> pair is found.
45 @retval FALSE Otherwise.
49 Udp6FindInstanceByPort (
50 IN LIST_ENTRY
*InstanceList
,
51 IN EFI_IPv6_ADDRESS
*Address
,
56 This function is the packet transmitting notify function registered to the IpIo
57 interface. It's called to signal the udp TxToken when the IpIo layer completes
58 transmitting of the udp datagram.
60 @param[in] Status The completion status of the output udp datagram.
61 @param[in] Context Pointer to the context data.
62 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
63 @param[in] NotifyData Pointer to the notify data.
71 IN IP_IO_IP_PROTOCOL Sender
,
76 This function processes the received datagram passed up by the IpIo layer.
78 @param[in] Status The status of this udp datagram.
79 @param[in] IcmpError The IcmpError code, only available when Status is
81 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
82 @param[in] Packet Pointer to the NET_BUF containing the received udp
84 @param[in] Context Pointer to the context data.
92 IN EFI_NET_SESSION_DATA
*NetSession
,
98 This function cancle the token specified by Arg in the Map.
100 @param[in] Map Pointer to the NET_MAP.
101 @param[in] Item Pointer to the NET_MAP_ITEM.
102 @param[in] Arg Pointer to the token to be cancelled, if NULL, all
103 the tokens in this Map will be cancelled.
104 This parameter is optional and may be NULL.
106 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
107 is not the same as that in the Item if Arg is not
109 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
117 IN NET_MAP_ITEM
*Item
,
118 IN VOID
*Arg OPTIONAL
122 This function check if the received udp datagram matches with the Instance.
124 @param[in] Instance Pointer to the udp instance context data.
125 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
126 from the received udp datagram.
128 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
129 @retval FALSE The udp datagram doe not match the receiving requirements of the Instance.
134 IN UDP6_INSTANCE_DATA
*Instance
,
135 IN EFI_UDP6_SESSION_DATA
*Udp6Session
139 This function removes the Wrap specified by Context and releases relevant resources.
141 @param[in] Event The Event this notify function is registered to.
142 @param[in] Context Pointer to the context data.
147 Udp6RecycleRxDataWrap (
153 This function wraps the Packet into RxData.
155 @param[in] Instance Pointer to the instance context data.
156 @param[in] Packet Pointer to the buffer containing the received
158 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
161 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
162 be returned if any error occurs.
167 IN UDP6_INSTANCE_DATA
*Instance
,
169 IN EFI_UDP6_RECEIVE_DATA
*RxData
173 This function enqueues the received datagram into the instances' receiving queues.
175 @param[in] Udp6Service Pointer to the udp service context data.
176 @param[in] Packet Pointer to the buffer containing the received
178 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
181 @return The times this datagram is enqueued.
186 IN UDP6_SERVICE_DATA
*Udp6Service
,
188 IN EFI_UDP6_RECEIVE_DATA
*RxData
192 This function delivers the datagrams enqueued in the instances.
194 @param[in] Udp6Service Pointer to the udp service context data.
199 IN UDP6_SERVICE_DATA
*Udp6Service
203 This function demultiplexes the received udp datagram to the appropriate instances.
205 @param[in] Udp6Service Pointer to the udp service context data.
206 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
207 the received datagram.
208 @param[in] Packet Pointer to the buffer containing the received udp
214 IN UDP6_SERVICE_DATA
*Udp6Service
,
215 IN EFI_NET_SESSION_DATA
*NetSession
,
220 This function handles the received Icmp Error message and demultiplexes it to the
223 @param[in] Udp6Service Pointer to the udp service context data.
224 @param[in] IcmpError The icmp error code.
225 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
226 from the received Icmp Error packet.
227 @param[in, out] Packet Pointer to the Icmp Error packet.
232 IN UDP6_SERVICE_DATA
*Udp6Service
,
234 IN EFI_NET_SESSION_DATA
*NetSession
,
235 IN OUT NET_BUF
*Packet
239 This function builds and sends out a icmp port unreachable message.
241 @param[in] IpIo Pointer to the IP_IO instance.
242 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
243 causes this icmp error message.
244 @param[in] Udp6Header Pointer to the udp header of the datagram causes
245 this icmp error message.
249 Udp6SendPortUnreach (
251 IN EFI_NET_SESSION_DATA
*NetSession
,
256 Find the key in the netmap
258 @param[in] Map The netmap to search within.
259 @param[in] Key The key to search.
261 @return The point to the item contains the Key, or NULL if Key isn't in the map.
265 Udp6MapMultiCastAddr (
271 Create the Udp service context data.
273 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
274 @param[in] ImageHandle The image handle of this udp6 driver.
275 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
277 @retval EFI_SUCCESS The udp6 service context data was created and
279 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
280 @retval Others An error condition occurred.
285 IN UDP6_SERVICE_DATA
*Udp6Service
,
286 IN EFI_HANDLE ImageHandle
,
287 IN EFI_HANDLE ControllerHandle
291 IP_IO_OPEN_DATA OpenData
;
293 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
295 Udp6Service
->Signature
= UDP6_SERVICE_DATA_SIGNATURE
;
296 Udp6Service
->ServiceBinding
= mUdp6ServiceBinding
;
297 Udp6Service
->ImageHandle
= ImageHandle
;
298 Udp6Service
->ControllerHandle
= ControllerHandle
;
299 Udp6Service
->ChildrenNumber
= 0;
301 InitializeListHead (&Udp6Service
->ChildrenList
);
304 // Create the IpIo for this service context.
306 Udp6Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
, IP_VERSION_6
);
307 if (Udp6Service
->IpIo
== NULL
) {
308 return EFI_OUT_OF_RESOURCES
;
312 // Set the OpenData used to open the IpIo.
315 &OpenData
.IpConfigData
.Ip6CfgData
,
316 &mIp6IoDefaultIpConfigData
,
317 sizeof (EFI_IP6_CONFIG_DATA
)
319 OpenData
.RcvdContext
= (VOID
*) Udp6Service
;
320 OpenData
.SndContext
= NULL
;
321 OpenData
.PktRcvdNotify
= Udp6DgramRcvd
;
322 OpenData
.PktSentNotify
= Udp6DgramSent
;
325 // Configure and start the IpIo.
327 Status
= IpIoOpen (Udp6Service
->IpIo
, &OpenData
);
328 if (EFI_ERROR (Status
)) {
333 // Create the event for Udp timeout checking.
335 Status
= gBS
->CreateEvent (
336 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
340 &Udp6Service
->TimeoutEvent
342 if (EFI_ERROR (Status
)) {
347 // Start the timeout timer event.
349 Status
= gBS
->SetTimer (
350 Udp6Service
->TimeoutEvent
,
352 UDP6_TIMEOUT_INTERVAL
354 if (EFI_ERROR (Status
)) {
362 if (Udp6Service
->TimeoutEvent
!= NULL
) {
363 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
366 IpIoDestroy (Udp6Service
->IpIo
);
367 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
));
400 This function checks and times out the I/O datagrams listed in the
401 UDP6_SERVICE_DATA which is specified by the input parameter Context.
404 @param[in] Event The event this function registered to.
405 @param[in] Context The context data registered during the creation of
416 UDP6_SERVICE_DATA
*Udp6Service
;
418 UDP6_INSTANCE_DATA
*Instance
;
419 LIST_ENTRY
*WrapEntry
;
420 LIST_ENTRY
*NextEntry
;
421 UDP6_RXDATA_WRAP
*Wrap
;
423 Udp6Service
= (UDP6_SERVICE_DATA
*) Context
;
424 NET_CHECK_SIGNATURE (Udp6Service
, UDP6_SERVICE_DATA_SIGNATURE
);
426 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
428 // Iterate all the instances belonging to this service context.
430 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
431 NET_CHECK_SIGNATURE (Instance
, UDP6_INSTANCE_DATA_SIGNATURE
);
433 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
435 // Skip this instance if it's not configured or no receive timeout.
440 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
442 // Iterate all the rxdatas belonging to this udp instance.
444 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP6_RXDATA_WRAP
, Link
);
446 if (Wrap
->TimeoutTick
< UDP6_TIMEOUT_INTERVAL
/ 10) {
448 // Remove this RxData if it timeouts.
450 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
452 Wrap
->TimeoutTick
-= UDP6_TIMEOUT_INTERVAL
/ 10;
460 This function intializes the new created udp instance.
462 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
463 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
468 IN UDP6_SERVICE_DATA
*Udp6Service
,
469 IN OUT UDP6_INSTANCE_DATA
*Instance
473 // Set the signature.
475 Instance
->Signature
= UDP6_INSTANCE_DATA_SIGNATURE
;
480 InitializeListHead (&Instance
->Link
);
481 InitializeListHead (&Instance
->RcvdDgramQue
);
482 InitializeListHead (&Instance
->DeliveredDgramQue
);
485 // Init the NET_MAPs.
487 NetMapInit (&Instance
->TxTokens
);
488 NetMapInit (&Instance
->RxTokens
);
489 NetMapInit (&Instance
->McastIps
);
492 // Save the pointer to the UDP6_SERVICE_DATA, and initialize other members.
494 Instance
->Udp6Service
= Udp6Service
;
495 CopyMem (&Instance
->Udp6Proto
, &mUdp6Protocol
, sizeof (EFI_UDP6_PROTOCOL
));
496 Instance
->IcmpError
= EFI_SUCCESS
;
497 Instance
->Configured
= FALSE
;
498 Instance
->IsNoMapping
= FALSE
;
499 Instance
->InDestroy
= FALSE
;
504 This function cleans the udp instance.
506 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
511 IN OUT UDP6_INSTANCE_DATA
*Instance
514 NetMapClean (&Instance
->McastIps
);
515 NetMapClean (&Instance
->RxTokens
);
516 NetMapClean (&Instance
->TxTokens
);
521 This function finds the udp instance by the specified <Address, Port> pair.
523 @param[in] InstanceList Pointer to the head of the list linking the udp
525 @param[in] Address Pointer to the specified IPv6 address.
526 @param[in] Port The udp port number.
528 @retval TRUE The specified <Address, Port> pair is found.
529 @retval FALSE Otherwise.
533 Udp6FindInstanceByPort (
534 IN LIST_ENTRY
*InstanceList
,
535 IN EFI_IPv6_ADDRESS
*Address
,
540 UDP6_INSTANCE_DATA
*Instance
;
541 EFI_UDP6_CONFIG_DATA
*ConfigData
;
543 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
545 // Iterate all the udp instances.
547 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
548 ConfigData
= &Instance
->ConfigData
;
550 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
552 // If the instance is not configured, or the configdata of the instance indicates
553 // this instance accepts any port, skip it.
558 if (EFI_IP6_EQUAL (&ConfigData
->StationAddress
, Address
) &&
559 (ConfigData
->StationPort
== Port
)
562 // If both the address and the port are the same, return TRUE.
569 // Return FALSE when matching fails.
576 This function tries to bind the udp instance according to the configured port
579 @param[in] InstanceList Pointer to the head of the list linking the udp
581 @param[in] ConfigData Pointer to the ConfigData of the instance to be
584 @retval EFI_SUCCESS The bound operation completed successfully.
585 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
586 already used by other instance.
587 @retval EFI_OUT_OF_RESOURCES No available port resources.
592 IN LIST_ENTRY
*InstanceList
,
593 IN EFI_UDP6_CONFIG_DATA
*ConfigData
596 EFI_IPv6_ADDRESS
*StationAddress
;
599 if (ConfigData
->AcceptAnyPort
) {
603 StationAddress
= &ConfigData
->StationAddress
;
605 if (ConfigData
->StationPort
!= 0) {
607 if (!ConfigData
->AllowDuplicatePort
&&
608 Udp6FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)
611 // Do not allow duplicate ports and the port is already used by other instance.
613 return EFI_ACCESS_DENIED
;
617 // Select a random port for this instance.
619 if (ConfigData
->AllowDuplicatePort
) {
621 // Just pick up the random port if the instance allows duplicate port.
623 ConfigData
->StationPort
= mUdp6RandomPort
;
626 StartPort
= mUdp6RandomPort
;
628 while (Udp6FindInstanceByPort (InstanceList
, StationAddress
, mUdp6RandomPort
)) {
631 if (mUdp6RandomPort
== 0) {
632 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
635 if (mUdp6RandomPort
== StartPort
) {
637 // No available port.
639 return EFI_OUT_OF_RESOURCES
;
643 ConfigData
->StationPort
= mUdp6RandomPort
;
647 if (mUdp6RandomPort
== 0) {
648 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
656 This function is used to check whether the NewConfigData has any un-reconfigurable
657 parameters changed compared to the OldConfigData.
659 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
661 @param[in] NewConfigData Pointer to the new ConfigData.
663 @retval TRUE The instance is reconfigurable according to the NewConfigData.
664 @retval FALSE Otherwise.
668 Udp6IsReconfigurable (
669 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
670 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
673 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
674 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
675 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)
678 // The receiving filter parameters cannot be changed.
683 if ((!NewConfigData
->AcceptAnyPort
) &&
684 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)
687 // The port is not changeable.
692 if (!EFI_IP6_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
)) {
694 // The StationAddress is not the same.
700 if (!EFI_IP6_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
702 // The remoteaddress is not the same.
707 if (!NetIp6IsUnspecifiedAddr (&NewConfigData
->RemoteAddress
) &&
708 (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)
711 // The RemotePort differs if it's designated in the configdata.
717 // All checks pass, return TRUE.
724 This function builds the Ip6 configdata from the Udp6ConfigData.
726 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
727 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
731 Udp6BuildIp6ConfigData (
732 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
733 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
738 &mIp6IoDefaultIpConfigData
,
739 sizeof (EFI_IP6_CONFIG_DATA
)
741 Ip6ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
742 Ip6ConfigData
->AcceptPromiscuous
= Udp6ConfigData
->AcceptPromiscuous
;
743 IP6_COPY_ADDRESS (&Ip6ConfigData
->StationAddress
, &Udp6ConfigData
->StationAddress
);
744 IP6_COPY_ADDRESS (&Ip6ConfigData
->DestinationAddress
, &Udp6ConfigData
->RemoteAddress
);
746 // Use the -1 magic number to disable the receiving process of the ip instance.
748 Ip6ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
753 This function validates the TxToken. It returns the error code according to the spec.
755 @param[in] Instance Pointer to the udp instance context data.
756 @param[in] TxToken Pointer to the token to be checked.
758 @retval EFI_SUCCESS The TxToken is valid.
759 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
761 Token.Packet.TxData is NULL;
762 Token.Packet.TxData.FragmentCount is zero;
763 Token.Packet.TxData.DataLength is not equal to the
764 sum of fragment lengths;
766 Token.Packet.TxData.FragmentTable[].FragmentLength
769 Token.Packet.TxData.FragmentTable[].FragmentBuffer
771 UdpSessionData.DestinationAddress are not valid
772 unicast IPv6 addresses if the UdpSessionData is
774 UdpSessionData.DestinationPort and
775 ConfigData.RemotePort are all zero if the
776 UdpSessionData is not NULL.
777 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
782 Udp6ValidateTxToken (
783 IN UDP6_INSTANCE_DATA
*Instance
,
784 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
787 EFI_UDP6_TRANSMIT_DATA
*TxData
;
790 EFI_UDP6_CONFIG_DATA
*ConfigData
;
791 EFI_UDP6_SESSION_DATA
*UdpSessionData
;
794 if (TxToken
->Event
== NULL
) {
795 return EFI_INVALID_PARAMETER
;
798 TxData
= TxToken
->Packet
.TxData
;
800 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
801 return EFI_INVALID_PARAMETER
;
805 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
807 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
808 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)
811 // If the FragmentBuffer is NULL, or the FragmentLeng is zero.
813 return EFI_INVALID_PARAMETER
;
816 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
819 if (TotalLen
!= TxData
->DataLength
) {
821 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
824 return EFI_INVALID_PARAMETER
;
827 ConfigData
= &Instance
->ConfigData
;
828 UdpSessionData
= TxData
->UdpSessionData
;
830 if (UdpSessionData
!= NULL
) {
832 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
834 // Ambiguous; no avalaible DestinationPort for this token.
836 return EFI_INVALID_PARAMETER
;
839 if (NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
840 NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
843 // The DestinationAddress is not specificed.
845 return EFI_INVALID_PARAMETER
;
848 if (!NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
849 !NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
852 // The ConfigData.RemoteAddress is not zero and the UdpSessionData.DestinationAddress
855 return EFI_INVALID_PARAMETER
;
857 } else if (NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)) {
859 // The configured RemoteAddress is all zero, and the user doesn't override the
860 // destination address.
862 return EFI_INVALID_PARAMETER
;
865 if (TxData
->DataLength
> UDP6_MAX_DATA_SIZE
) {
866 return EFI_BAD_BUFFER_SIZE
;
874 This function checks whether the specified Token duplicates the one in the Map.
876 @param[in] Map Pointer to the NET_MAP.
877 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
879 @param[in] Context Pointer to the Token to be checked.
881 @retval EFI_SUCCESS The Token specified by Context differs from the
883 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
890 IN NET_MAP_ITEM
*Item
,
894 EFI_UDP6_COMPLETION_TOKEN
*Token
;
895 EFI_UDP6_COMPLETION_TOKEN
*TokenInItem
;
897 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) Context
;
898 TokenInItem
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
900 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
902 // The Token duplicates with the TokenInItem in case either the two pointers are the
903 // same, or the Events of these two tokens are the same.
905 return EFI_ACCESS_DENIED
;
913 This function calculates the checksum for the Packet, utilizing the pre-calculated
914 pseudo HeadSum to reduce some overhead.
916 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
917 @param[in] HeadSum Checksum of the pseudo header, execpt the length
920 @return The 16-bit checksum of this udp datagram.
931 Checksum
= NetbufChecksum (Packet
);
932 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
934 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
935 Checksum
= (UINT16
) (~Checksum
);
941 This function removes the specified Token from the TokenMap.
943 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
944 @param[in] Token Pointer to the Token to be removed.
946 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
947 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
952 IN NET_MAP
*TokenMap
,
953 IN EFI_UDP6_COMPLETION_TOKEN
*Token
959 // Find the Token first.
961 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
965 // Remove the token if it's found in the map.
967 NetMapRemoveItem (TokenMap
, Item
, NULL
);
971 return EFI_NOT_FOUND
;
976 This function is the packet transmitting notify function registered to the IpIo
977 interface. It's called to signal the udp TxToken when IpIo layer completes the
978 transmitting of the udp datagram.
980 @param[in] Status The completion status of the output udp datagram.
981 @param[in] Context Pointer to the context data.
982 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
983 @param[in] NotifyData Pointer to the notify data.
989 IN EFI_STATUS Status
,
991 IN IP_IO_IP_PROTOCOL Sender
,
995 UDP6_INSTANCE_DATA
*Instance
;
996 EFI_UDP6_COMPLETION_TOKEN
*Token
;
998 Instance
= (UDP6_INSTANCE_DATA
*) Context
;
999 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NotifyData
;
1001 if (Udp6RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
1003 // The token may be cancelled. Only signal it if the remove operation succeeds.
1005 Token
->Status
= Status
;
1006 gBS
->SignalEvent (Token
->Event
);
1013 This function processes the received datagram passed up by the IpIo layer.
1015 @param[in] Status The status of this udp datagram.
1016 @param[in] IcmpError The IcmpError code, only available when Status is
1018 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
1019 @param[in] Packet Pointer to the NET_BUF containing the received udp
1021 @param[in] Context Pointer to the context data.
1027 IN EFI_STATUS Status
,
1029 IN EFI_NET_SESSION_DATA
*NetSession
,
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
) {
1042 // Demultiplex the received datagram.
1044 Udp6Demultiplex ((UDP6_SERVICE_DATA
*) Context
, NetSession
, Packet
);
1047 // Handle the ICMP6 Error packet.
1049 Udp6IcmpHandler ((UDP6_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
1053 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
1054 // that are signaled with received data.
1061 This function removes the multicast group specified by Arg from the Map.
1063 @param[in] Map Pointer to the NET_MAP.
1064 @param[in] Item Pointer to the NET_MAP_ITEM.
1065 @param[in] Arg Pointer to the Arg, it's the pointer to a
1066 multicast IPv6 Address. This parameter is
1067 optional and may be NULL.
1069 @retval EFI_SUCCESS The multicast address is removed.
1070 @retval EFI_ABORTED The specified multicast address is removed, and the
1078 IN NET_MAP_ITEM
*Item
,
1079 IN VOID
*Arg OPTIONAL
1082 EFI_IPv6_ADDRESS
*McastIp
;
1086 if ((McastIp
!= NULL
) &&
1087 !EFI_IP6_EQUAL (McastIp
, ((EFI_IPv6_ADDRESS
*)Item
->Key
))
1090 // McastIp is not NULL and the multicast address contained in the Item
1091 // is not the same as McastIp.
1096 FreePool (Item
->Key
);
1099 // Remove this Item.
1101 NetMapRemoveItem (Map
, Item
, NULL
);
1103 if (McastIp
!= NULL
) {
1105 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
1115 This function cancle the token specified by Arg in the Map.
1117 @param[in] Map Pointer to the NET_MAP.
1118 @param[in] Item Pointer to the NET_MAP_ITEM.
1119 @param[in] Arg Pointer to the token to be cancelled. If NULL, all
1120 the tokens in this Map will be cancelled.
1121 This parameter is optional and may be NULL.
1123 @retval EFI_SUCCESS The token is cancelled if Arg is NULL, or the token
1124 is not the same as that in the Item, if Arg is not
1126 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1134 IN NET_MAP_ITEM
*Item
,
1135 IN VOID
*Arg OPTIONAL
1138 EFI_UDP6_COMPLETION_TOKEN
*TokenToCancel
;
1142 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1146 if (Item
->Value
!= NULL
) {
1148 // If the token is a transmit token, the corresponding Packet is recorded in
1149 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1150 // will invoke Udp6DgramSent, the token will be signaled and this Item will
1151 // be removed from the Map there.
1153 Packet
= (NET_BUF
*) (Item
->Value
);
1154 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1156 IpIoCancelTxToken (IpIo
, Packet
);
1159 // The token is a receive token. Abort it and remove it from the Map.
1161 TokenToCancel
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
1162 NetMapRemoveItem (Map
, Item
, NULL
);
1164 TokenToCancel
->Status
= EFI_ABORTED
;
1165 gBS
->SignalEvent (TokenToCancel
->Event
);
1177 This function removes all the Wrap datas in the RcvdDgramQue.
1179 @param[in] Instance Pointer to the Udp6 Instance.
1183 Udp6FlushRcvdDgram (
1184 IN UDP6_INSTANCE_DATA
*Instance
1187 UDP6_RXDATA_WRAP
*Wrap
;
1189 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1191 // Iterate all the Wraps in the RcvdDgramQue.
1193 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1196 // The Wrap will be removed from the RcvdDgramQue by this function call.
1198 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1205 Cancel Udp6 tokens from the Udp6 instance.
1207 @param[in] Instance Pointer to the udp instance context data.
1208 @param[in] Token Pointer to the token to be canceled. If NULL, all
1209 tokens in this instance will be cancelled.
1210 This parameter is optional and may be NULL.
1212 @retval EFI_SUCCESS The Token is cancelled.
1213 @retval EFI_NOT_FOUND The Token is not found.
1217 Udp6InstanceCancelToken (
1218 IN UDP6_INSTANCE_DATA
*Instance
,
1219 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
1225 // Cancel this token from the TxTokens map.
1227 Status
= NetMapIterate (&Instance
->TxTokens
, Udp6CancelTokens
, Token
);
1229 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1231 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1232 // the TxTokens and returns success.
1238 // Try to cancel this token from the RxTokens map in condition either the Token
1239 // is NULL or the specified Token is not in TxTokens.
1241 Status
= NetMapIterate (&Instance
->RxTokens
, Udp6CancelTokens
, Token
);
1243 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1245 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1246 // TxTokens nor the RxTokens, or say, it's not found.
1248 return EFI_NOT_FOUND
;
1251 ASSERT ((Token
!= NULL
) ||
1252 ((0 == NetMapGetCount (&Instance
->TxTokens
)) &&
1253 (0 == NetMapGetCount (&Instance
->RxTokens
)))
1261 This function checks if the received udp datagram matches with the Instance.
1263 @param[in] Instance Pointer to the udp instance context data.
1264 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
1265 from the received udp datagram.
1267 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
1268 @retval FALSE The udp datagram does not matche the receiving requirements of the Instance.
1273 IN UDP6_INSTANCE_DATA
*Instance
,
1274 IN EFI_UDP6_SESSION_DATA
*Udp6Session
1277 EFI_UDP6_CONFIG_DATA
*ConfigData
;
1278 EFI_IPv6_ADDRESS Destination
;
1280 ConfigData
= &Instance
->ConfigData
;
1282 if (ConfigData
->AcceptPromiscuous
) {
1284 // Always matches if this instance is in the promiscuous state.
1289 if ((!ConfigData
->AcceptAnyPort
&& (Udp6Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1290 ((ConfigData
->RemotePort
!= 0) && (Udp6Session
->SourcePort
!= ConfigData
->RemotePort
))
1293 // The local port or the remote port doesn't match.
1298 if (!NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
) &&
1299 !EFI_IP6_EQUAL (&ConfigData
->RemoteAddress
, &Udp6Session
->SourceAddress
)
1302 // This datagram doesn't come from the instance's specified sender.
1307 if (NetIp6IsUnspecifiedAddr (&ConfigData
->StationAddress
) ||
1308 EFI_IP6_EQUAL (&Udp6Session
->DestinationAddress
, &ConfigData
->StationAddress
)
1311 // The instance is configured to receive datagrams destinated to any station IP or
1312 // the destination address of this datagram matches the configured station IP.
1317 IP6_COPY_ADDRESS (&Destination
, &Udp6Session
->DestinationAddress
);
1319 if (IP6_IS_MULTICAST (&Destination
) &&
1320 (NULL
!= Udp6MapMultiCastAddr (&Instance
->McastIps
, &Destination
))
1323 // It's a multicast packet and the multicast address is accepted by this instance.
1333 This function removes the Wrap specified by Context and release relevant resources.
1335 @param[in] Event The Event this notify function registered to.
1336 @param[in] Context Pointer to the context data.
1341 Udp6RecycleRxDataWrap (
1346 UDP6_RXDATA_WRAP
*Wrap
;
1348 Wrap
= (UDP6_RXDATA_WRAP
*) Context
;
1351 // Remove the Wrap from the list it belongs to.
1353 RemoveEntryList (&Wrap
->Link
);
1356 // Free the Packet associated with this Wrap.
1358 NetbufFree (Wrap
->Packet
);
1363 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1370 This function wraps the Packet into RxData.
1372 @param[in] Instance Pointer to the instance context data.
1373 @param[in] Packet Pointer to the buffer containing the received
1375 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1378 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
1379 be returned if any error occurs.
1384 IN UDP6_INSTANCE_DATA
*Instance
,
1386 IN EFI_UDP6_RECEIVE_DATA
*RxData
1390 UDP6_RXDATA_WRAP
*Wrap
;
1393 // Allocate buffer for the Wrap.
1395 Wrap
= AllocateZeroPool (sizeof (UDP6_RXDATA_WRAP
) +
1396 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP6_FRAGMENT_DATA
));
1401 InitializeListHead (&Wrap
->Link
);
1403 CopyMem (&Wrap
->RxData
, RxData
, sizeof(EFI_UDP6_RECEIVE_DATA
));
1405 // Create the Recycle event.
1407 Status
= gBS
->CreateEvent (
1410 Udp6RecycleRxDataWrap
,
1412 &Wrap
->RxData
.RecycleSignal
1414 if (EFI_ERROR (Status
)) {
1419 Wrap
->Packet
= Packet
;
1420 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1427 This function enqueues the received datagram into the instances' receiving queues.
1429 @param[in] Udp6Service Pointer to the udp service context data.
1430 @param[in] Packet Pointer to the buffer containing the received
1432 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1435 @return The times this datagram is enqueued.
1440 IN UDP6_SERVICE_DATA
*Udp6Service
,
1442 IN EFI_UDP6_RECEIVE_DATA
*RxData
1446 UDP6_INSTANCE_DATA
*Instance
;
1447 UDP6_RXDATA_WRAP
*Wrap
;
1452 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1454 // Iterate the instances.
1456 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1458 if (!Instance
->Configured
) {
1462 if (Udp6MatchDgram (Instance
, &RxData
->UdpSession
)) {
1464 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1466 Wrap
= Udp6WrapRxData (Instance
, Packet
, RxData
);
1471 NET_GET_REF (Packet
);
1473 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1484 This function delivers the received datagrams to the specified instance.
1486 @param[in] Instance Pointer to the instance context data.
1490 Udp6InstanceDeliverDgram (
1491 IN UDP6_INSTANCE_DATA
*Instance
1494 UDP6_RXDATA_WRAP
*Wrap
;
1495 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1497 EFI_UDP6_RECEIVE_DATA
*RxData
;
1500 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1501 !NetMapIsEmpty (&Instance
->RxTokens
)
1504 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1506 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1508 // Duplicate the Packet if it is shared between instances.
1510 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1515 NetbufFree (Wrap
->Packet
);
1520 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1522 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1525 // Build the FragmentTable and set the FragmentCount in RxData.
1527 RxData
= &Wrap
->RxData
;
1528 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1532 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1533 &RxData
->FragmentCount
1536 Token
->Status
= EFI_SUCCESS
;
1537 Token
->Packet
.RxData
= &Wrap
->RxData
;
1539 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1540 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1541 gBS
->RestoreTPL (OldTpl
);
1543 gBS
->SignalEvent (Token
->Event
);
1549 This function delivers the datagrams enqueued in the instances.
1551 @param[in] Udp6Service Pointer to the udp service context data.
1556 IN UDP6_SERVICE_DATA
*Udp6Service
1560 UDP6_INSTANCE_DATA
*Instance
;
1562 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1564 // Iterate the instances.
1566 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1568 if (!Instance
->Configured
) {
1573 // Deliver the datagrams of this instance.
1575 Udp6InstanceDeliverDgram (Instance
);
1581 This function demultiplexes the received udp datagram to the appropriate instances.
1583 @param[in] Udp6Service Pointer to the udp service context data.
1584 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
1585 the received datagram.
1586 @param[in] Packet Pointer to the buffer containing the received udp
1592 IN UDP6_SERVICE_DATA
*Udp6Service
,
1593 IN EFI_NET_SESSION_DATA
*NetSession
,
1597 EFI_UDP_HEADER
*Udp6Header
;
1599 EFI_UDP6_RECEIVE_DATA RxData
;
1600 EFI_UDP6_SESSION_DATA
*Udp6Session
;
1603 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1604 NetbufFree (Packet
);
1609 // Get the datagram header from the packet buffer.
1611 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1612 ASSERT (Udp6Header
!= NULL
);
1613 if (Udp6Header
== NULL
) {
1614 NetbufFree (Packet
);
1618 if (Udp6Header
->Checksum
!= 0) {
1620 // check the checksum.
1622 HeadSum
= NetIp6PseudoHeadChecksum (
1623 &NetSession
->Source
.v6
,
1624 &NetSession
->Dest
.v6
,
1629 if (Udp6Checksum (Packet
, HeadSum
) != 0) {
1633 NetbufFree (Packet
);
1638 Udp6Session
= &RxData
.UdpSession
;
1639 Udp6Session
->SourcePort
= NTOHS (Udp6Header
->SrcPort
);
1640 Udp6Session
->DestinationPort
= NTOHS (Udp6Header
->DstPort
);
1642 IP6_COPY_ADDRESS (&Udp6Session
->SourceAddress
, &NetSession
->Source
);
1643 IP6_COPY_ADDRESS (&Udp6Session
->DestinationAddress
, &NetSession
->Dest
);
1646 // Trim the UDP header.
1648 NetbufTrim (Packet
, UDP6_HEADER_SIZE
, TRUE
);
1650 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1653 // Try to enqueue this datagram into the instances.
1655 Enqueued
= Udp6EnqueueDgram (Udp6Service
, Packet
, &RxData
);
1657 if (Enqueued
== 0) {
1659 // Send the port unreachable ICMP packet before we free this NET_BUF
1661 Udp6SendPortUnreach (Udp6Service
->IpIo
, NetSession
, Udp6Header
);
1665 // Try to free the packet before deliver it.
1667 NetbufFree (Packet
);
1671 // Deliver the datagram.
1673 Udp6DeliverDgram (Udp6Service
);
1679 This function builds and sends out a icmp port unreachable message.
1681 @param[in] IpIo Pointer to the IP_IO instance.
1682 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1683 causes this icmp error message.
1684 @param[in] Udp6Header Pointer to the udp header of the datagram causes
1685 this icmp error message.
1689 Udp6SendPortUnreach (
1691 IN EFI_NET_SESSION_DATA
*NetSession
,
1697 IP6_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1699 IP_IO_OVERRIDE Override
;
1700 IP_IO_IP_INFO
*IpSender
;
1701 EFI_IP6_MODE_DATA
*Ip6ModeData
;
1703 EFI_IP6_PROTOCOL
*Ip6Protocol
;
1708 // An ICMPv6 error message MUST NOT be originated as A packet destined to
1709 // 1) an IPv6 multicast address 2) The IPv6 Unspecified Address
1711 if (NetSession
->IpVersion
== IP_VERSION_6
) {
1712 if (NetIp6IsUnspecifiedAddr (&NetSession
->Dest
.v6
) ||
1713 IP6_IS_MULTICAST (&NetSession
->Dest
.v6
)
1720 IpSender
= IpIoFindSender (&IpIo
, NetSession
->IpVersion
, &NetSession
->Dest
);
1723 // Get the Ipv6 Mode Data.
1725 Ip6ModeData
= AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA
));
1726 ASSERT (Ip6ModeData
!= NULL
);
1727 if (Ip6ModeData
== NULL
) {
1732 // If not finding the related IpSender use the default IpIo to send out
1733 // the port unreachable ICMP message.
1735 if (IpSender
== NULL
) {
1736 Ip6Protocol
= IpIo
->Ip
.Ip6
;
1738 Ip6Protocol
= IpSender
->Ip
.Ip6
;
1741 Status
= Ip6Protocol
->GetModeData (
1748 if (EFI_ERROR (Status
)) {
1752 // The ICMP6 packet length, includes whole invoking packet and ICMP6 error header.
1754 Len
= NetSession
->IpHdrLen
+
1755 NTOHS(((EFI_UDP_HEADER
*) Udp6Header
)->Length
) +
1756 sizeof (IP6_ICMP_ERROR_HEAD
);
1759 // If the ICMP6 packet length larger than IP MTU, adjust its length to MTU.
1761 if (Ip6ModeData
->MaxPacketSize
< Len
) {
1762 Len
= Ip6ModeData
->MaxPacketSize
;
1766 // Allocate buffer for the icmp error message.
1768 Packet
= NetbufAlloc (Len
);
1769 if (Packet
== NULL
) {
1774 // Allocate space for the IP6_ICMP_ERROR_HEAD.
1776 IcmpErrHdr
= (IP6_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1777 ASSERT (IcmpErrHdr
!= NULL
);
1778 if (IcmpErrHdr
== NULL
) {
1783 // Set the required fields for the icmp port unreachable message.
1785 IcmpErrHdr
->Head
.Type
= ICMP_V6_DEST_UNREACHABLE
;
1786 IcmpErrHdr
->Head
.Code
= ICMP_V6_PORT_UNREACHABLE
;
1787 IcmpErrHdr
->Head
.Checksum
= 0;
1788 IcmpErrHdr
->Fourth
= 0;
1791 // Copy as much of invoking Packet as possible without the ICMPv6 packet
1792 // exceeding the minimum Ipv6 MTU. The length of IP6_ICMP_ERROR_HEAD contains
1793 // the length of EFI_IP6_HEADER, so when using the length of IP6_ICMP_ERROR_HEAD
1794 // for pointer movement that fact should be considered.
1796 Ptr
= (VOID
*) &IcmpErrHdr
->Head
;
1797 Ptr
= (UINT8
*) (UINTN
) ((UINTN
) Ptr
+ sizeof (IP6_ICMP_ERROR_HEAD
) - sizeof (EFI_IP6_HEADER
));
1798 CopyMem (Ptr
, NetSession
->IpHdr
.Ip6Hdr
, NetSession
->IpHdrLen
);
1800 Ptr
+ NetSession
->IpHdrLen
,
1802 Len
- NetSession
->IpHdrLen
- sizeof (IP6_ICMP_ERROR_HEAD
) + sizeof (EFI_IP6_HEADER
)
1806 // Set the checksum as zero, and IP6 driver will calcuate it with pseudo header.
1808 IcmpErrHdr
->Head
.Checksum
= 0;
1811 // Fill the override data.
1813 Override
.Ip6OverrideData
.FlowLabel
= 0;
1814 Override
.Ip6OverrideData
.HopLimit
= 255;
1815 Override
.Ip6OverrideData
.Protocol
= IP6_ICMP
;
1818 // Send out this icmp packet.
1820 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, &NetSession
->Source
, &Override
);
1822 NetbufFree (Packet
);
1825 if (Ip6ModeData
!= NULL
) {
1826 FreePool (Ip6ModeData
);
1832 This function handles the received Icmp Error message and de-multiplexes it to the
1835 @param[in] Udp6Service Pointer to the udp service context data.
1836 @param[in] IcmpError The icmp error code.
1837 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1838 from the received Icmp Error packet.
1839 @param[in, out] Packet Pointer to the Icmp Error packet.
1844 IN UDP6_SERVICE_DATA
*Udp6Service
,
1846 IN EFI_NET_SESSION_DATA
*NetSession
,
1847 IN OUT NET_BUF
*Packet
1850 EFI_UDP_HEADER
*Udp6Header
;
1851 EFI_UDP6_SESSION_DATA Udp6Session
;
1853 UDP6_INSTANCE_DATA
*Instance
;
1855 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1856 NetbufFree (Packet
);
1860 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1861 ASSERT (Udp6Header
!= NULL
);
1862 if (Udp6Header
== NULL
) {
1863 NetbufFree (Packet
);
1867 IP6_COPY_ADDRESS (&Udp6Session
.SourceAddress
, &NetSession
->Source
);
1868 IP6_COPY_ADDRESS (&Udp6Session
.DestinationAddress
, &NetSession
->Dest
);
1870 Udp6Session
.SourcePort
= NTOHS (Udp6Header
->DstPort
);
1871 Udp6Session
.DestinationPort
= NTOHS (Udp6Header
->SrcPort
);
1873 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1875 // Iterate all the instances.
1877 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1879 if (!Instance
->Configured
) {
1883 if (Udp6MatchDgram (Instance
, &Udp6Session
)) {
1885 // Translate the Icmp Error code according to the udp spec.
1887 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, IP_VERSION_6
, NULL
, NULL
);
1889 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1890 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1894 // Notify the instance with the received Icmp Error.
1896 Udp6ReportIcmpError (Instance
);
1902 NetbufFree (Packet
);
1907 This function reports the received ICMP error.
1909 @param[in] Instance Pointer to the udp instance context data.
1913 Udp6ReportIcmpError (
1914 IN UDP6_INSTANCE_DATA
*Instance
1917 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1919 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1921 // There are no receive tokens to deliver the ICMP error.
1926 if (EFI_ERROR (Instance
->IcmpError
)) {
1928 // Try to get a RxToken from the RxTokens map.
1930 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1932 if (Token
!= NULL
) {
1934 // Report the error through the Token.
1936 Token
->Status
= Instance
->IcmpError
;
1937 gBS
->SignalEvent (Token
->Event
);
1940 // Clear the IcmpError.
1942 Instance
->IcmpError
= EFI_SUCCESS
;
1949 This function is a dummy ext-free function for the NET_BUF created for the output
1952 @param[in] Context Pointer to the context data.
1957 Udp6NetVectorExtFree (
1964 Find the key in the netmap.
1966 @param[in] Map The netmap to search within.
1967 @param[in] Key The key to search.
1969 @return The point to the item contains the Key, or NULL, if Key isn't in the map.
1973 Udp6MapMultiCastAddr (
1980 EFI_IPv6_ADDRESS
*Addr
;
1982 ASSERT (Map
!= NULL
);
1983 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
1984 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1985 Addr
= (EFI_IPv6_ADDRESS
*) Item
->Key
;
1986 if (EFI_IP6_EQUAL (Addr
, Key
)) {