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 cancle 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
;
375 Clean the Udp service context data.
377 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
382 IN OUT UDP6_SERVICE_DATA
*Udp6Service
386 // Close the TimeoutEvent timer.
388 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
393 IpIoDestroy (Udp6Service
->IpIo
);
394 Udp6Service
->IpIo
= NULL
;
396 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
401 This function checks and times out the I/O datagrams listed in the
402 UDP6_SERVICE_DATA which is specified by the input parameter Context.
405 @param[in] Event The event this function registered to.
406 @param[in] Context The context data registered during the creation of
417 UDP6_SERVICE_DATA
*Udp6Service
;
419 UDP6_INSTANCE_DATA
*Instance
;
420 LIST_ENTRY
*WrapEntry
;
421 LIST_ENTRY
*NextEntry
;
422 UDP6_RXDATA_WRAP
*Wrap
;
424 Udp6Service
= (UDP6_SERVICE_DATA
*) Context
;
425 NET_CHECK_SIGNATURE (Udp6Service
, UDP6_SERVICE_DATA_SIGNATURE
);
427 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
429 // Iterate all the instances belonging to this service context.
431 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
432 NET_CHECK_SIGNATURE (Instance
, UDP6_INSTANCE_DATA_SIGNATURE
);
434 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
436 // Skip this instance if it's not configured or no receive timeout.
441 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
443 // Iterate all the rxdatas belonging to this udp instance.
445 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP6_RXDATA_WRAP
, Link
);
447 if (Wrap
->TimeoutTick
< UDP6_TIMEOUT_INTERVAL
/ 10) {
449 // Remove this RxData if it timeouts.
451 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
453 Wrap
->TimeoutTick
-= UDP6_TIMEOUT_INTERVAL
/ 10;
461 This function intializes the new created udp instance.
463 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
464 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
469 IN UDP6_SERVICE_DATA
*Udp6Service
,
470 IN OUT UDP6_INSTANCE_DATA
*Instance
474 // Set the signature.
476 Instance
->Signature
= UDP6_INSTANCE_DATA_SIGNATURE
;
481 InitializeListHead (&Instance
->Link
);
482 InitializeListHead (&Instance
->RcvdDgramQue
);
483 InitializeListHead (&Instance
->DeliveredDgramQue
);
486 // Init the NET_MAPs.
488 NetMapInit (&Instance
->TxTokens
);
489 NetMapInit (&Instance
->RxTokens
);
490 NetMapInit (&Instance
->McastIps
);
493 // Save the pointer to the UDP6_SERVICE_DATA, and initialize other members.
495 Instance
->Udp6Service
= Udp6Service
;
496 CopyMem (&Instance
->Udp6Proto
, &mUdp6Protocol
, sizeof (EFI_UDP6_PROTOCOL
));
497 Instance
->IcmpError
= EFI_SUCCESS
;
498 Instance
->Configured
= FALSE
;
499 Instance
->IsNoMapping
= FALSE
;
500 Instance
->InDestroy
= FALSE
;
505 This function cleans the udp instance.
507 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
512 IN OUT UDP6_INSTANCE_DATA
*Instance
515 NetMapClean (&Instance
->McastIps
);
516 NetMapClean (&Instance
->RxTokens
);
517 NetMapClean (&Instance
->TxTokens
);
522 This function finds the udp instance by the specified <Address, Port> pair.
524 @param[in] InstanceList Pointer to the head of the list linking the udp
526 @param[in] Address Pointer to the specified IPv6 address.
527 @param[in] Port The udp port number.
529 @retval TRUE The specified <Address, Port> pair is found.
530 @retval FALSE Otherwise.
534 Udp6FindInstanceByPort (
535 IN LIST_ENTRY
*InstanceList
,
536 IN EFI_IPv6_ADDRESS
*Address
,
541 UDP6_INSTANCE_DATA
*Instance
;
542 EFI_UDP6_CONFIG_DATA
*ConfigData
;
544 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
546 // Iterate all the udp instances.
548 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
549 ConfigData
= &Instance
->ConfigData
;
551 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
553 // If the instance is not configured, or the configdata of the instance indicates
554 // this instance accepts any port, skip it.
559 if (EFI_IP6_EQUAL (&ConfigData
->StationAddress
, Address
) &&
560 (ConfigData
->StationPort
== Port
)
563 // If both the address and the port are the same, return TRUE.
570 // Return FALSE when matching fails.
577 This function tries to bind the udp instance according to the configured port
580 @param[in] InstanceList Pointer to the head of the list linking the udp
582 @param[in] ConfigData Pointer to the ConfigData of the instance to be
585 @retval EFI_SUCCESS The bound operation completed successfully.
586 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
587 already used by other instance.
588 @retval EFI_OUT_OF_RESOURCES No available port resources.
593 IN LIST_ENTRY
*InstanceList
,
594 IN EFI_UDP6_CONFIG_DATA
*ConfigData
597 EFI_IPv6_ADDRESS
*StationAddress
;
600 if (ConfigData
->AcceptAnyPort
) {
604 StationAddress
= &ConfigData
->StationAddress
;
606 if (ConfigData
->StationPort
!= 0) {
608 if (!ConfigData
->AllowDuplicatePort
&&
609 Udp6FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)
612 // Do not allow duplicate ports and the port is already used by other instance.
614 return EFI_ACCESS_DENIED
;
618 // Select a random port for this instance.
620 if (ConfigData
->AllowDuplicatePort
) {
622 // Just pick up the random port if the instance allows duplicate port.
624 ConfigData
->StationPort
= mUdp6RandomPort
;
627 StartPort
= mUdp6RandomPort
;
629 while (Udp6FindInstanceByPort (InstanceList
, StationAddress
, mUdp6RandomPort
)) {
632 if (mUdp6RandomPort
== 0) {
633 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
636 if (mUdp6RandomPort
== StartPort
) {
638 // No available port.
640 return EFI_OUT_OF_RESOURCES
;
644 ConfigData
->StationPort
= mUdp6RandomPort
;
648 if (mUdp6RandomPort
== 0) {
649 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
657 This function is used to check whether the NewConfigData has any un-reconfigurable
658 parameters changed compared to the OldConfigData.
660 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
662 @param[in] NewConfigData Pointer to the new ConfigData.
664 @retval TRUE The instance is reconfigurable according to the NewConfigData.
665 @retval FALSE Otherwise.
669 Udp6IsReconfigurable (
670 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
671 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
674 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
675 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
676 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)
679 // The receiving filter parameters cannot be changed.
684 if ((!NewConfigData
->AcceptAnyPort
) &&
685 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)
688 // The port is not changeable.
693 if (!EFI_IP6_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
)) {
695 // The StationAddress is not the same.
701 if (!EFI_IP6_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
703 // The remoteaddress is not the same.
708 if (!NetIp6IsUnspecifiedAddr (&NewConfigData
->RemoteAddress
) &&
709 (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)
712 // The RemotePort differs if it's designated in the configdata.
718 // All checks pass, return TRUE.
725 This function builds the Ip6 configdata from the Udp6ConfigData.
727 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
728 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
732 Udp6BuildIp6ConfigData (
733 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
734 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
739 &mIp6IoDefaultIpConfigData
,
740 sizeof (EFI_IP6_CONFIG_DATA
)
742 Ip6ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
743 Ip6ConfigData
->AcceptPromiscuous
= Udp6ConfigData
->AcceptPromiscuous
;
744 IP6_COPY_ADDRESS (&Ip6ConfigData
->StationAddress
, &Udp6ConfigData
->StationAddress
);
745 IP6_COPY_ADDRESS (&Ip6ConfigData
->DestinationAddress
, &Udp6ConfigData
->RemoteAddress
);
747 // Use the -1 magic number to disable the receiving process of the ip instance.
749 Ip6ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
754 This function validates the TxToken. It returns the error code according to the spec.
756 @param[in] Instance Pointer to the udp instance context data.
757 @param[in] TxToken Pointer to the token to be checked.
759 @retval EFI_SUCCESS The TxToken is valid.
760 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
762 Token.Packet.TxData is NULL;
763 Token.Packet.TxData.FragmentCount is zero;
764 Token.Packet.TxData.DataLength is not equal to the
765 sum of fragment lengths;
767 Token.Packet.TxData.FragmentTable[].FragmentLength
770 Token.Packet.TxData.FragmentTable[].FragmentBuffer
772 UdpSessionData.DestinationAddress are not valid
773 unicast IPv6 addresses if the UdpSessionData is
775 UdpSessionData.DestinationPort and
776 ConfigData.RemotePort are all zero if the
777 UdpSessionData is not NULL.
778 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
783 Udp6ValidateTxToken (
784 IN UDP6_INSTANCE_DATA
*Instance
,
785 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
788 EFI_UDP6_TRANSMIT_DATA
*TxData
;
791 EFI_UDP6_CONFIG_DATA
*ConfigData
;
792 EFI_UDP6_SESSION_DATA
*UdpSessionData
;
795 if (TxToken
->Event
== NULL
) {
796 return EFI_INVALID_PARAMETER
;
799 TxData
= TxToken
->Packet
.TxData
;
801 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
802 return EFI_INVALID_PARAMETER
;
806 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
808 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
809 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)
812 // If the FragmentBuffer is NULL, or the FragmentLeng is zero.
814 return EFI_INVALID_PARAMETER
;
817 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
820 if (TotalLen
!= TxData
->DataLength
) {
822 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
825 return EFI_INVALID_PARAMETER
;
828 ConfigData
= &Instance
->ConfigData
;
829 UdpSessionData
= TxData
->UdpSessionData
;
831 if (UdpSessionData
!= NULL
) {
833 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
835 // Ambiguous; no avalaible DestinationPort for this token.
837 return EFI_INVALID_PARAMETER
;
840 if (NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
841 NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
844 // The DestinationAddress is not specificed.
846 return EFI_INVALID_PARAMETER
;
849 if (!NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
850 !NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
853 // The ConfigData.RemoteAddress is not zero and the UdpSessionData.DestinationAddress
856 return EFI_INVALID_PARAMETER
;
858 } else if (NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)) {
860 // The configured RemoteAddress is all zero, and the user doesn't override the
861 // destination address.
863 return EFI_INVALID_PARAMETER
;
866 if (TxData
->DataLength
> UDP6_MAX_DATA_SIZE
) {
867 return EFI_BAD_BUFFER_SIZE
;
875 This function checks whether the specified Token duplicates the one in the Map.
877 @param[in] Map Pointer to the NET_MAP.
878 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
880 @param[in] Context Pointer to the Token to be checked.
882 @retval EFI_SUCCESS The Token specified by Context differs from the
884 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
891 IN NET_MAP_ITEM
*Item
,
895 EFI_UDP6_COMPLETION_TOKEN
*Token
;
896 EFI_UDP6_COMPLETION_TOKEN
*TokenInItem
;
898 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) Context
;
899 TokenInItem
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
901 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
903 // The Token duplicates with the TokenInItem in case either the two pointers are the
904 // same, or the Events of these two tokens are the same.
906 return EFI_ACCESS_DENIED
;
914 This function calculates the checksum for the Packet, utilizing the pre-calculated
915 pseudo HeadSum to reduce some overhead.
917 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
918 @param[in] HeadSum Checksum of the pseudo header, execpt the length
921 @return The 16-bit checksum of this udp datagram.
932 Checksum
= NetbufChecksum (Packet
);
933 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
935 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
936 Checksum
= (UINT16
) (~Checksum
);
942 This function removes the specified Token from the TokenMap.
944 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
945 @param[in] Token Pointer to the Token to be removed.
947 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
948 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
953 IN NET_MAP
*TokenMap
,
954 IN EFI_UDP6_COMPLETION_TOKEN
*Token
960 // Find the Token first.
962 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
966 // Remove the token if it's found in the map.
968 NetMapRemoveItem (TokenMap
, Item
, NULL
);
972 return EFI_NOT_FOUND
;
977 This function is the packet transmitting notify function registered to the IpIo
978 interface. It's called to signal the udp TxToken when IpIo layer completes the
979 transmitting of the udp datagram.
981 If Context is NULL, then ASSERT().
982 If NotifyData is NULL, then ASSERT().
984 @param[in] Status The completion status of the output udp datagram.
985 @param[in] Context Pointer to the context data.
986 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
987 @param[in] NotifyData Pointer to the notify data.
993 IN EFI_STATUS Status
,
995 IN IP_IO_IP_PROTOCOL Sender
,
999 UDP6_INSTANCE_DATA
*Instance
;
1000 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1002 ASSERT (Context
!= NULL
&& NotifyData
!= NULL
);
1004 Instance
= (UDP6_INSTANCE_DATA
*) Context
;
1005 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NotifyData
;
1007 if (Udp6RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
1009 // The token may be cancelled. Only signal it if the remove operation succeeds.
1011 Token
->Status
= Status
;
1012 gBS
->SignalEvent (Token
->Event
);
1019 This function processes the received datagram passed up by the IpIo layer.
1021 If NetSession is NULL, then ASSERT().
1022 If Packet is NULL, then ASSERT().
1023 If Context is NULL, then ASSERT().
1025 @param[in] Status The status of this udp datagram.
1026 @param[in] IcmpError The IcmpError code, only available when Status is
1028 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
1029 @param[in] Packet Pointer to the NET_BUF containing the received udp
1031 @param[in] Context Pointer to the context data.
1037 IN EFI_STATUS Status
,
1039 IN EFI_NET_SESSION_DATA
*NetSession
,
1044 ASSERT (NetSession
!= NULL
&& Packet
!= NULL
&& Context
!= NULL
);
1045 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
1048 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
1050 if (Status
== EFI_SUCCESS
) {
1053 // Demultiplex the received datagram.
1055 Udp6Demultiplex ((UDP6_SERVICE_DATA
*) Context
, NetSession
, Packet
);
1058 // Handle the ICMP6 Error packet.
1060 Udp6IcmpHandler ((UDP6_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
1064 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
1065 // that are signaled with received data.
1072 This function removes the multicast group specified by Arg from the Map.
1074 @param[in] Map Pointer to the NET_MAP.
1075 @param[in] Item Pointer to the NET_MAP_ITEM.
1076 @param[in] Arg Pointer to the Arg, it's the pointer to a
1077 multicast IPv6 Address. This parameter is
1078 optional and may be NULL.
1080 @retval EFI_SUCCESS The multicast address is removed.
1081 @retval EFI_ABORTED The specified multicast address is removed, and the
1089 IN NET_MAP_ITEM
*Item
,
1090 IN VOID
*Arg OPTIONAL
1093 EFI_IPv6_ADDRESS
*McastIp
;
1097 if ((McastIp
!= NULL
) &&
1098 !EFI_IP6_EQUAL (McastIp
, ((EFI_IPv6_ADDRESS
*)Item
->Key
))
1101 // McastIp is not NULL and the multicast address contained in the Item
1102 // is not the same as McastIp.
1107 FreePool (Item
->Key
);
1110 // Remove this Item.
1112 NetMapRemoveItem (Map
, Item
, NULL
);
1114 if (McastIp
!= NULL
) {
1116 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
1126 This function cancle the token specified by Arg in the Map.
1128 @param[in] Map Pointer to the NET_MAP.
1129 @param[in] Item Pointer to the NET_MAP_ITEM.
1130 @param[in] Arg Pointer to the token to be cancelled. If NULL, all
1131 the tokens in this Map will be cancelled.
1132 This parameter is optional and may be NULL.
1134 @retval EFI_SUCCESS The token is cancelled if Arg is NULL, or the token
1135 is not the same as that in the Item, if Arg is not
1137 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1145 IN NET_MAP_ITEM
*Item
,
1146 IN VOID
*Arg OPTIONAL
1149 EFI_UDP6_COMPLETION_TOKEN
*TokenToCancel
;
1153 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1157 if (Item
->Value
!= NULL
) {
1159 // If the token is a transmit token, the corresponding Packet is recorded in
1160 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1161 // will invoke Udp6DgramSent, the token will be signaled and this Item will
1162 // be removed from the Map there.
1164 Packet
= (NET_BUF
*) (Item
->Value
);
1165 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1167 IpIoCancelTxToken (IpIo
, Packet
);
1170 // The token is a receive token. Abort it and remove it from the Map.
1172 TokenToCancel
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
1173 NetMapRemoveItem (Map
, Item
, NULL
);
1175 TokenToCancel
->Status
= EFI_ABORTED
;
1176 gBS
->SignalEvent (TokenToCancel
->Event
);
1188 This function removes all the Wrap datas in the RcvdDgramQue.
1190 @param[in] Instance Pointer to the Udp6 Instance.
1194 Udp6FlushRcvdDgram (
1195 IN UDP6_INSTANCE_DATA
*Instance
1198 UDP6_RXDATA_WRAP
*Wrap
;
1200 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1202 // Iterate all the Wraps in the RcvdDgramQue.
1204 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1207 // The Wrap will be removed from the RcvdDgramQue by this function call.
1209 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1216 Cancel Udp6 tokens from the Udp6 instance.
1218 @param[in] Instance Pointer to the udp instance context data.
1219 @param[in] Token Pointer to the token to be canceled. If NULL, all
1220 tokens in this instance will be cancelled.
1221 This parameter is optional and may be NULL.
1223 @retval EFI_SUCCESS The Token is cancelled.
1224 @retval EFI_NOT_FOUND The Token is not found.
1228 Udp6InstanceCancelToken (
1229 IN UDP6_INSTANCE_DATA
*Instance
,
1230 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
1236 // Cancel this token from the TxTokens map.
1238 Status
= NetMapIterate (&Instance
->TxTokens
, Udp6CancelTokens
, Token
);
1240 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1242 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1243 // the TxTokens and returns success.
1249 // Try to cancel this token from the RxTokens map in condition either the Token
1250 // is NULL or the specified Token is not in TxTokens.
1252 Status
= NetMapIterate (&Instance
->RxTokens
, Udp6CancelTokens
, Token
);
1254 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1256 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1257 // TxTokens nor the RxTokens, or say, it's not found.
1259 return EFI_NOT_FOUND
;
1262 ASSERT ((Token
!= NULL
) ||
1263 ((0 == NetMapGetCount (&Instance
->TxTokens
)) &&
1264 (0 == NetMapGetCount (&Instance
->RxTokens
)))
1272 This function checks if the received udp datagram matches with the Instance.
1274 @param[in] Instance Pointer to the udp instance context data.
1275 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
1276 from the received udp datagram.
1278 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
1279 @retval FALSE The udp datagram does not matche the receiving requirements of the Instance.
1284 IN UDP6_INSTANCE_DATA
*Instance
,
1285 IN EFI_UDP6_SESSION_DATA
*Udp6Session
1288 EFI_UDP6_CONFIG_DATA
*ConfigData
;
1289 EFI_IPv6_ADDRESS Destination
;
1291 ConfigData
= &Instance
->ConfigData
;
1293 if (ConfigData
->AcceptPromiscuous
) {
1295 // Always matches if this instance is in the promiscuous state.
1300 if ((!ConfigData
->AcceptAnyPort
&& (Udp6Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1301 ((ConfigData
->RemotePort
!= 0) && (Udp6Session
->SourcePort
!= ConfigData
->RemotePort
))
1304 // The local port or the remote port doesn't match.
1309 if (!NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
) &&
1310 !EFI_IP6_EQUAL (&ConfigData
->RemoteAddress
, &Udp6Session
->SourceAddress
)
1313 // This datagram doesn't come from the instance's specified sender.
1318 if (NetIp6IsUnspecifiedAddr (&ConfigData
->StationAddress
) ||
1319 EFI_IP6_EQUAL (&Udp6Session
->DestinationAddress
, &ConfigData
->StationAddress
)
1322 // The instance is configured to receive datagrams destinated to any station IP or
1323 // the destination address of this datagram matches the configured station IP.
1328 IP6_COPY_ADDRESS (&Destination
, &Udp6Session
->DestinationAddress
);
1330 if (IP6_IS_MULTICAST (&Destination
) &&
1331 (NULL
!= Udp6MapMultiCastAddr (&Instance
->McastIps
, &Destination
))
1334 // It's a multicast packet and the multicast address is accepted by this instance.
1344 This function removes the Wrap specified by Context and release relevant resources.
1346 @param[in] Event The Event this notify function registered to.
1347 @param[in] Context Pointer to the context data.
1352 Udp6RecycleRxDataWrap (
1357 UDP6_RXDATA_WRAP
*Wrap
;
1359 Wrap
= (UDP6_RXDATA_WRAP
*) Context
;
1362 // Remove the Wrap from the list it belongs to.
1364 RemoveEntryList (&Wrap
->Link
);
1367 // Free the Packet associated with this Wrap.
1369 NetbufFree (Wrap
->Packet
);
1374 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1381 This function wraps the Packet into RxData.
1383 @param[in] Instance Pointer to the instance context data.
1384 @param[in] Packet Pointer to the buffer containing the received
1386 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1389 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
1390 be returned if any error occurs.
1395 IN UDP6_INSTANCE_DATA
*Instance
,
1397 IN EFI_UDP6_RECEIVE_DATA
*RxData
1401 UDP6_RXDATA_WRAP
*Wrap
;
1404 // Allocate buffer for the Wrap.
1406 Wrap
= AllocateZeroPool (sizeof (UDP6_RXDATA_WRAP
) +
1407 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP6_FRAGMENT_DATA
));
1412 InitializeListHead (&Wrap
->Link
);
1414 CopyMem (&Wrap
->RxData
, RxData
, sizeof(EFI_UDP6_RECEIVE_DATA
));
1416 // Create the Recycle event.
1418 Status
= gBS
->CreateEvent (
1421 Udp6RecycleRxDataWrap
,
1423 &Wrap
->RxData
.RecycleSignal
1425 if (EFI_ERROR (Status
)) {
1430 Wrap
->Packet
= Packet
;
1431 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1438 This function enqueues the received datagram into the instances' receiving queues.
1440 @param[in] Udp6Service Pointer to the udp service context data.
1441 @param[in] Packet Pointer to the buffer containing the received
1443 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1446 @return The times this datagram is enqueued.
1451 IN UDP6_SERVICE_DATA
*Udp6Service
,
1453 IN EFI_UDP6_RECEIVE_DATA
*RxData
1457 UDP6_INSTANCE_DATA
*Instance
;
1458 UDP6_RXDATA_WRAP
*Wrap
;
1463 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1465 // Iterate the instances.
1467 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1469 if (!Instance
->Configured
) {
1473 if (Udp6MatchDgram (Instance
, &RxData
->UdpSession
)) {
1475 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1477 Wrap
= Udp6WrapRxData (Instance
, Packet
, RxData
);
1482 NET_GET_REF (Packet
);
1484 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1495 This function delivers the received datagrams to the specified instance.
1497 @param[in] Instance Pointer to the instance context data.
1501 Udp6InstanceDeliverDgram (
1502 IN UDP6_INSTANCE_DATA
*Instance
1505 UDP6_RXDATA_WRAP
*Wrap
;
1506 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1508 EFI_UDP6_RECEIVE_DATA
*RxData
;
1511 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1512 !NetMapIsEmpty (&Instance
->RxTokens
)
1515 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1517 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1519 // Duplicate the Packet if it is shared between instances.
1521 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1526 NetbufFree (Wrap
->Packet
);
1531 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1533 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1536 // Build the FragmentTable and set the FragmentCount in RxData.
1538 RxData
= &Wrap
->RxData
;
1539 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1543 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1544 &RxData
->FragmentCount
1547 Token
->Status
= EFI_SUCCESS
;
1548 Token
->Packet
.RxData
= &Wrap
->RxData
;
1550 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1551 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1552 gBS
->RestoreTPL (OldTpl
);
1554 gBS
->SignalEvent (Token
->Event
);
1560 This function delivers the datagrams enqueued in the instances.
1562 @param[in] Udp6Service Pointer to the udp service context data.
1567 IN UDP6_SERVICE_DATA
*Udp6Service
1571 UDP6_INSTANCE_DATA
*Instance
;
1573 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1575 // Iterate the instances.
1577 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1579 if (!Instance
->Configured
) {
1584 // Deliver the datagrams of this instance.
1586 Udp6InstanceDeliverDgram (Instance
);
1592 This function demultiplexes the received udp datagram to the appropriate instances.
1594 @param[in] Udp6Service Pointer to the udp service context data.
1595 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
1596 the received datagram.
1597 @param[in] Packet Pointer to the buffer containing the received udp
1603 IN UDP6_SERVICE_DATA
*Udp6Service
,
1604 IN EFI_NET_SESSION_DATA
*NetSession
,
1608 EFI_UDP_HEADER
*Udp6Header
;
1610 EFI_UDP6_RECEIVE_DATA RxData
;
1611 EFI_UDP6_SESSION_DATA
*Udp6Session
;
1614 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1615 NetbufFree (Packet
);
1620 // Get the datagram header from the packet buffer.
1622 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1623 ASSERT (Udp6Header
!= NULL
);
1624 if (Udp6Header
== NULL
) {
1625 NetbufFree (Packet
);
1629 if (Udp6Header
->Checksum
!= 0) {
1631 // check the checksum.
1633 HeadSum
= NetIp6PseudoHeadChecksum (
1634 &NetSession
->Source
.v6
,
1635 &NetSession
->Dest
.v6
,
1640 if (Udp6Checksum (Packet
, HeadSum
) != 0) {
1644 NetbufFree (Packet
);
1649 Udp6Session
= &RxData
.UdpSession
;
1650 Udp6Session
->SourcePort
= NTOHS (Udp6Header
->SrcPort
);
1651 Udp6Session
->DestinationPort
= NTOHS (Udp6Header
->DstPort
);
1653 IP6_COPY_ADDRESS (&Udp6Session
->SourceAddress
, &NetSession
->Source
);
1654 IP6_COPY_ADDRESS (&Udp6Session
->DestinationAddress
, &NetSession
->Dest
);
1657 // Trim the UDP header.
1659 NetbufTrim (Packet
, UDP6_HEADER_SIZE
, TRUE
);
1661 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1664 // Try to enqueue this datagram into the instances.
1666 Enqueued
= Udp6EnqueueDgram (Udp6Service
, Packet
, &RxData
);
1668 if (Enqueued
== 0) {
1670 // Send the port unreachable ICMP packet before we free this NET_BUF
1672 Udp6SendPortUnreach (Udp6Service
->IpIo
, NetSession
, Udp6Header
);
1676 // Try to free the packet before deliver it.
1678 NetbufFree (Packet
);
1682 // Deliver the datagram.
1684 Udp6DeliverDgram (Udp6Service
);
1690 This function builds and sends out a icmp port unreachable message.
1692 @param[in] IpIo Pointer to the IP_IO instance.
1693 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1694 causes this icmp error message.
1695 @param[in] Udp6Header Pointer to the udp header of the datagram causes
1696 this icmp error message.
1700 Udp6SendPortUnreach (
1702 IN EFI_NET_SESSION_DATA
*NetSession
,
1708 IP6_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1710 IP_IO_OVERRIDE Override
;
1711 IP_IO_IP_INFO
*IpSender
;
1712 EFI_IP6_MODE_DATA
*Ip6ModeData
;
1714 EFI_IP6_PROTOCOL
*Ip6Protocol
;
1719 // An ICMPv6 error message MUST NOT be originated as A packet destined to
1720 // 1) an IPv6 multicast address 2) The IPv6 Unspecified Address
1722 if (NetSession
->IpVersion
== IP_VERSION_6
) {
1723 if (NetIp6IsUnspecifiedAddr (&NetSession
->Dest
.v6
) ||
1724 IP6_IS_MULTICAST (&NetSession
->Dest
.v6
)
1731 IpSender
= IpIoFindSender (&IpIo
, NetSession
->IpVersion
, &NetSession
->Dest
);
1734 // Get the Ipv6 Mode Data.
1736 Ip6ModeData
= AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA
));
1737 ASSERT (Ip6ModeData
!= NULL
);
1738 if (Ip6ModeData
== NULL
) {
1743 // If not finding the related IpSender use the default IpIo to send out
1744 // the port unreachable ICMP message.
1746 if (IpSender
== NULL
) {
1747 Ip6Protocol
= IpIo
->Ip
.Ip6
;
1749 Ip6Protocol
= IpSender
->Ip
.Ip6
;
1752 Status
= Ip6Protocol
->GetModeData (
1759 if (EFI_ERROR (Status
)) {
1763 // The ICMP6 packet length, includes whole invoking packet and ICMP6 error header.
1765 Len
= NetSession
->IpHdrLen
+
1766 NTOHS(((EFI_UDP_HEADER
*) Udp6Header
)->Length
) +
1767 sizeof (IP6_ICMP_ERROR_HEAD
);
1770 // If the ICMP6 packet length larger than IP MTU, adjust its length to MTU.
1772 if (Ip6ModeData
->MaxPacketSize
< Len
) {
1773 Len
= Ip6ModeData
->MaxPacketSize
;
1777 // Allocate buffer for the icmp error message.
1779 Packet
= NetbufAlloc (Len
);
1780 if (Packet
== NULL
) {
1785 // Allocate space for the IP6_ICMP_ERROR_HEAD.
1787 IcmpErrHdr
= (IP6_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1788 ASSERT (IcmpErrHdr
!= NULL
);
1789 if (IcmpErrHdr
== NULL
) {
1794 // Set the required fields for the icmp port unreachable message.
1796 IcmpErrHdr
->Head
.Type
= ICMP_V6_DEST_UNREACHABLE
;
1797 IcmpErrHdr
->Head
.Code
= ICMP_V6_PORT_UNREACHABLE
;
1798 IcmpErrHdr
->Head
.Checksum
= 0;
1799 IcmpErrHdr
->Fourth
= 0;
1802 // Copy as much of invoking Packet as possible without the ICMPv6 packet
1803 // exceeding the minimum Ipv6 MTU. The length of IP6_ICMP_ERROR_HEAD contains
1804 // the length of EFI_IP6_HEADER, so when using the length of IP6_ICMP_ERROR_HEAD
1805 // for pointer movement that fact should be considered.
1807 Ptr
= (VOID
*) &IcmpErrHdr
->Head
;
1808 Ptr
= (UINT8
*) (UINTN
) ((UINTN
) Ptr
+ sizeof (IP6_ICMP_ERROR_HEAD
) - sizeof (EFI_IP6_HEADER
));
1809 CopyMem (Ptr
, NetSession
->IpHdr
.Ip6Hdr
, NetSession
->IpHdrLen
);
1811 Ptr
+ NetSession
->IpHdrLen
,
1813 Len
- NetSession
->IpHdrLen
- sizeof (IP6_ICMP_ERROR_HEAD
) + sizeof (EFI_IP6_HEADER
)
1817 // Set the checksum as zero, and IP6 driver will calcuate it with pseudo header.
1819 IcmpErrHdr
->Head
.Checksum
= 0;
1822 // Fill the override data.
1824 Override
.Ip6OverrideData
.FlowLabel
= 0;
1825 Override
.Ip6OverrideData
.HopLimit
= 255;
1826 Override
.Ip6OverrideData
.Protocol
= IP6_ICMP
;
1829 // Send out this icmp packet.
1831 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, &NetSession
->Source
, &Override
);
1833 NetbufFree (Packet
);
1836 if (Ip6ModeData
!= NULL
) {
1837 FreePool (Ip6ModeData
);
1843 This function handles the received Icmp Error message and de-multiplexes it to the
1846 @param[in] Udp6Service Pointer to the udp service context data.
1847 @param[in] IcmpError The icmp error code.
1848 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1849 from the received Icmp Error packet.
1850 @param[in, out] Packet Pointer to the Icmp Error packet.
1855 IN UDP6_SERVICE_DATA
*Udp6Service
,
1857 IN EFI_NET_SESSION_DATA
*NetSession
,
1858 IN OUT NET_BUF
*Packet
1861 EFI_UDP_HEADER
*Udp6Header
;
1862 EFI_UDP6_SESSION_DATA Udp6Session
;
1864 UDP6_INSTANCE_DATA
*Instance
;
1866 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1867 NetbufFree (Packet
);
1871 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1872 ASSERT (Udp6Header
!= NULL
);
1873 if (Udp6Header
== NULL
) {
1874 NetbufFree (Packet
);
1878 IP6_COPY_ADDRESS (&Udp6Session
.SourceAddress
, &NetSession
->Source
);
1879 IP6_COPY_ADDRESS (&Udp6Session
.DestinationAddress
, &NetSession
->Dest
);
1881 Udp6Session
.SourcePort
= NTOHS (Udp6Header
->DstPort
);
1882 Udp6Session
.DestinationPort
= NTOHS (Udp6Header
->SrcPort
);
1884 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1886 // Iterate all the instances.
1888 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1890 if (!Instance
->Configured
) {
1894 if (Udp6MatchDgram (Instance
, &Udp6Session
)) {
1896 // Translate the Icmp Error code according to the udp spec.
1898 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, IP_VERSION_6
, NULL
, NULL
);
1900 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1901 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1905 // Notify the instance with the received Icmp Error.
1907 Udp6ReportIcmpError (Instance
);
1913 NetbufFree (Packet
);
1918 This function reports the received ICMP error.
1920 @param[in] Instance Pointer to the udp instance context data.
1924 Udp6ReportIcmpError (
1925 IN UDP6_INSTANCE_DATA
*Instance
1928 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1930 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1932 // There are no receive tokens to deliver the ICMP error.
1937 if (EFI_ERROR (Instance
->IcmpError
)) {
1939 // Try to get a RxToken from the RxTokens map.
1941 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1943 if (Token
!= NULL
) {
1945 // Report the error through the Token.
1947 Token
->Status
= Instance
->IcmpError
;
1948 gBS
->SignalEvent (Token
->Event
);
1951 // Clear the IcmpError.
1953 Instance
->IcmpError
= EFI_SUCCESS
;
1960 This function is a dummy ext-free function for the NET_BUF created for the output
1963 @param[in] Context Pointer to the context data.
1968 Udp6NetVectorExtFree (
1975 Find the key in the netmap.
1977 @param[in] Map The netmap to search within.
1978 @param[in] Key The key to search.
1980 @return The point to the item contains the Key, or NULL, if Key isn't in the map.
1984 Udp6MapMultiCastAddr (
1991 EFI_IPv6_ADDRESS
*Addr
;
1993 ASSERT (Map
!= NULL
);
1994 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
1995 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
1996 Addr
= (EFI_IPv6_ADDRESS
*) Item
->Key
;
1997 if (EFI_IP6_EQUAL (Addr
, Key
)) {