2 The implementation of the Udp4 protocol.
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UINT16 mUdp4RandomPort
;
21 This function checks and timeouts the I/O datagrams holding by the corresponding
24 @param[in] Event The event this function 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 IPv4 address.
42 @param[in] Port The udp port number.
44 @retval TRUE The specified <Address, Port> pair is found.
45 @retval FALSE Otherwise.
49 Udp4FindInstanceByPort (
50 IN LIST_ENTRY
*InstanceList
,
51 IN EFI_IPv4_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 IpIo layer completes the
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 pointer of EFI_IP4_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 cancels the token specified by Arg in the Map. This is a callback
99 used by Udp4InstanceCancelToken().
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,
104 the token specified by Item is cancelled.
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 matches the received udp datagram with the Instance.
124 @param[in] Instance Pointer to the udp instance context data.
125 @param[in] Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted
126 from the received udp datagram.
128 @retval TRUE The udp datagram matches the receiving requirments of the
130 @retval FALSE Otherwise.
135 IN UDP4_INSTANCE_DATA
*Instance
,
136 IN EFI_UDP4_SESSION_DATA
*Udp4Session
140 This function removes the Wrap specified by Context and release relevant resources.
142 @param[in] Event The Event this notify function registered to.
143 @param[in] Context Pointer to the context data.
148 Udp4RecycleRxDataWrap (
154 This function wraps the Packet and the 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_UDP4_RECEIVE_DATA of this
162 @return Pointer to the structure wrapping the RxData and the Packet.
167 IN UDP4_INSTANCE_DATA
*Instance
,
169 IN EFI_UDP4_RECEIVE_DATA
*RxData
173 This function enqueues the received datagram into the instances' receiving queues.
175 @param[in] Udp4Service 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_UDP4_RECEIVE_DATA of this
181 @return The times this datagram is enqueued.
186 IN UDP4_SERVICE_DATA
*Udp4Service
,
188 IN EFI_UDP4_RECEIVE_DATA
*RxData
192 This function delivers the datagrams enqueued in the instances.
194 @param[in] Udp4Service Pointer to the udp service context data.
199 IN UDP4_SERVICE_DATA
*Udp4Service
203 This function demultiplexes the received udp datagram to the appropriate instances.
205 @param[in] Udp4Service 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 UDP4_SERVICE_DATA
*Udp4Service
,
215 IN EFI_NET_SESSION_DATA
*NetSession
,
220 This function handles the received Icmp Error message and demultiplexes it to the
223 @param[in] Udp4Service 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] Packet Pointer to the Icmp Error packet.
232 IN UDP4_SERVICE_DATA
*Udp4Service
,
234 IN EFI_NET_SESSION_DATA
*NetSession
,
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] Udp4Header Pointer to the udp header of the datagram causes
245 this icmp error message.
249 Udp4SendPortUnreach (
251 IN EFI_NET_SESSION_DATA
*NetSession
,
257 Create the Udp service context data.
259 @param[in, out] Udp4Service Pointer to the UDP4_SERVICE_DATA.
260 @param[in] ImageHandle The image handle of this udp4 driver.
261 @param[in] ControllerHandle The controller handle this udp4 driver binds on.
263 @retval EFI_SUCCESS The udp4 service context data is created and
265 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
266 @retval other Other error occurs.
271 IN OUT UDP4_SERVICE_DATA
*Udp4Service
,
272 IN EFI_HANDLE ImageHandle
,
273 IN EFI_HANDLE ControllerHandle
277 IP_IO_OPEN_DATA OpenData
;
278 EFI_IP4_CONFIG_DATA
*Ip4ConfigData
;
280 ZeroMem (Udp4Service
, sizeof (UDP4_SERVICE_DATA
));
282 Udp4Service
->Signature
= UDP4_SERVICE_DATA_SIGNATURE
;
283 Udp4Service
->ServiceBinding
= mUdp4ServiceBinding
;
284 Udp4Service
->ImageHandle
= ImageHandle
;
285 Udp4Service
->ControllerHandle
= ControllerHandle
;
286 Udp4Service
->ChildrenNumber
= 0;
288 InitializeListHead (&Udp4Service
->ChildrenList
);
291 // Create the IpIo for this service context.
293 Udp4Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
, IP_VERSION_4
);
294 if (Udp4Service
->IpIo
== NULL
) {
295 return EFI_OUT_OF_RESOURCES
;
299 // Set the OpenData used to open the IpIo.
301 Ip4ConfigData
= &OpenData
.IpConfigData
.Ip4CfgData
;
302 CopyMem (Ip4ConfigData
, &mIp4IoDefaultIpConfigData
, sizeof (EFI_IP4_CONFIG_DATA
));
303 Ip4ConfigData
->AcceptBroadcast
= TRUE
;
304 OpenData
.RcvdContext
= (VOID
*) Udp4Service
;
305 OpenData
.SndContext
= NULL
;
306 OpenData
.PktRcvdNotify
= Udp4DgramRcvd
;
307 OpenData
.PktSentNotify
= Udp4DgramSent
;
310 // Configure and start the IpIo.
312 Status
= IpIoOpen (Udp4Service
->IpIo
, &OpenData
);
313 if (EFI_ERROR (Status
)) {
318 // Create the event for Udp timeout checking.
320 Status
= gBS
->CreateEvent (
321 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
325 &Udp4Service
->TimeoutEvent
327 if (EFI_ERROR (Status
)) {
332 // Start the timeout timer event.
334 Status
= gBS
->SetTimer (
335 Udp4Service
->TimeoutEvent
,
337 UDP4_TIMEOUT_INTERVAL
339 if (EFI_ERROR (Status
)) {
347 if (Udp4Service
->TimeoutEvent
!= NULL
) {
348 gBS
->CloseEvent (Udp4Service
->TimeoutEvent
);
351 IpIoDestroy (Udp4Service
->IpIo
);
358 Clean the Udp service context data.
360 @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA.
365 IN UDP4_SERVICE_DATA
*Udp4Service
369 // Cancel the TimeoutEvent timer.
371 gBS
->SetTimer (Udp4Service
->TimeoutEvent
, TimerCancel
, 0);
374 // Close the TimeoutEvent timer.
376 gBS
->CloseEvent (Udp4Service
->TimeoutEvent
);
381 IpIoDestroy (Udp4Service
->IpIo
);
386 This function checks and timeouts the I/O datagrams holding by the corresponding
389 @param[in] Event The event this function registered to.
390 @param[in] Context The context data registered during the creation of
401 UDP4_SERVICE_DATA
*Udp4Service
;
403 UDP4_INSTANCE_DATA
*Instance
;
404 LIST_ENTRY
*WrapEntry
;
405 LIST_ENTRY
*NextEntry
;
406 UDP4_RXDATA_WRAP
*Wrap
;
408 Udp4Service
= (UDP4_SERVICE_DATA
*) Context
;
409 NET_CHECK_SIGNATURE (Udp4Service
, UDP4_SERVICE_DATA_SIGNATURE
);
411 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
413 // Iterate all the instances belonging to this service context.
415 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
416 NET_CHECK_SIGNATURE (Instance
, UDP4_INSTANCE_DATA_SIGNATURE
);
418 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
420 // Skip this instance if it's not configured or no receive timeout.
425 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
427 // Iterate all the rxdatas belonging to this udp instance.
429 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP4_RXDATA_WRAP
, Link
);
432 // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.
434 if (Wrap
->TimeoutTick
< (UDP4_TIMEOUT_INTERVAL
/ 10)) {
436 // Remove this RxData if it timeouts.
438 Udp4RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
440 Wrap
->TimeoutTick
-= (UDP4_TIMEOUT_INTERVAL
/ 10);
448 This function intializes the new created udp instance.
450 @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA.
451 @param[in, out] Instance Pointer to the un-initialized UDP4_INSTANCE_DATA.
456 IN UDP4_SERVICE_DATA
*Udp4Service
,
457 IN OUT UDP4_INSTANCE_DATA
*Instance
461 // Set the signature.
463 Instance
->Signature
= UDP4_INSTANCE_DATA_SIGNATURE
;
468 InitializeListHead (&Instance
->Link
);
469 InitializeListHead (&Instance
->RcvdDgramQue
);
470 InitializeListHead (&Instance
->DeliveredDgramQue
);
473 // Init the NET_MAPs.
475 NetMapInit (&Instance
->TxTokens
);
476 NetMapInit (&Instance
->RxTokens
);
477 NetMapInit (&Instance
->McastIps
);
480 // Save the pointer to the UDP4_SERVICE_DATA, and initialize other members.
482 Instance
->Udp4Service
= Udp4Service
;
483 CopyMem (&Instance
->Udp4Proto
, &mUdp4Protocol
, sizeof (Instance
->Udp4Proto
));
484 Instance
->IcmpError
= EFI_SUCCESS
;
485 Instance
->Configured
= FALSE
;
486 Instance
->IsNoMapping
= FALSE
;
487 Instance
->InDestroy
= FALSE
;
492 This function cleans the udp instance.
494 @param[in] Instance Pointer to the UDP4_INSTANCE_DATA to clean.
499 IN UDP4_INSTANCE_DATA
*Instance
502 NetMapClean (&Instance
->McastIps
);
503 NetMapClean (&Instance
->RxTokens
);
504 NetMapClean (&Instance
->TxTokens
);
509 This function finds the udp instance by the specified <Address, Port> pair.
511 @param[in] InstanceList Pointer to the head of the list linking the udp
513 @param[in] Address Pointer to the specified IPv4 address.
514 @param[in] Port The udp port number.
516 @retval TRUE The specified <Address, Port> pair is found.
517 @retval FALSE Otherwise.
521 Udp4FindInstanceByPort (
522 IN LIST_ENTRY
*InstanceList
,
523 IN EFI_IPv4_ADDRESS
*Address
,
528 UDP4_INSTANCE_DATA
*Instance
;
529 EFI_UDP4_CONFIG_DATA
*ConfigData
;
531 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
533 // Iterate all the udp instances.
535 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
536 ConfigData
= &Instance
->ConfigData
;
538 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
540 // If the instance is not configured or the configdata of the instance indicates
541 // this instance accepts any port, skip it.
546 if (EFI_IP4_EQUAL (&ConfigData
->StationAddress
, Address
) &&
547 (ConfigData
->StationPort
== Port
)) {
549 // if both the address and the port are the same, return TRUE.
556 // return FALSE when matching fails.
563 This function tries to bind the udp instance according to the configured port
566 @param[in] InstanceList Pointer to the head of the list linking the udp
568 @param[in, out] ConfigData Pointer to the ConfigData of the instance to be
569 bound. ConfigData->StationPort will be assigned
570 with an available port value on success.
572 @retval EFI_SUCCESS The bound operation is completed successfully.
573 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
574 already used by other instance.
575 @retval EFI_OUT_OF_RESOURCES No available port resources.
580 IN LIST_ENTRY
*InstanceList
,
581 IN OUT EFI_UDP4_CONFIG_DATA
*ConfigData
584 EFI_IPv4_ADDRESS
*StationAddress
;
587 if (ConfigData
->AcceptAnyPort
) {
591 StationAddress
= &ConfigData
->StationAddress
;
593 if (ConfigData
->StationPort
!= 0) {
595 if (!ConfigData
->AllowDuplicatePort
&&
596 Udp4FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)) {
598 // Do not allow duplicate port and the port is already used by other instance.
600 return EFI_ACCESS_DENIED
;
604 // select a random port for this instance;
607 if (ConfigData
->AllowDuplicatePort
) {
609 // Just pick up the random port if the instance allows duplicate port.
611 ConfigData
->StationPort
= mUdp4RandomPort
;
614 StartPort
= mUdp4RandomPort
;
616 while (Udp4FindInstanceByPort(InstanceList
, StationAddress
, mUdp4RandomPort
)) {
619 if (mUdp4RandomPort
== 0) {
620 mUdp4RandomPort
= UDP4_PORT_KNOWN
;
623 if (mUdp4RandomPort
== StartPort
) {
625 // No available port.
627 return EFI_OUT_OF_RESOURCES
;
631 ConfigData
->StationPort
= mUdp4RandomPort
;
635 if (mUdp4RandomPort
== 0) {
636 mUdp4RandomPort
= UDP4_PORT_KNOWN
;
645 This function is used to check whether the NewConfigData has any un-reconfigurable
646 parameters changed compared to the OldConfigData.
648 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
650 @param[in] NewConfigData Pointer to the new ConfigData.
652 @retval TRUE The instance is reconfigurable.
653 @retval FALSE Otherwise.
657 Udp4IsReconfigurable (
658 IN EFI_UDP4_CONFIG_DATA
*OldConfigData
,
659 IN EFI_UDP4_CONFIG_DATA
*NewConfigData
662 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
663 (NewConfigData
->AcceptBroadcast
!= OldConfigData
->AcceptBroadcast
) ||
664 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
665 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)
668 // The receiving filter parameters cannot be changed.
673 if ((!NewConfigData
->AcceptAnyPort
) &&
674 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)
677 // The port is not changeable.
682 if (!NewConfigData
->AcceptPromiscuous
) {
684 if (NewConfigData
->UseDefaultAddress
!= OldConfigData
->UseDefaultAddress
) {
686 // The NewConfigData differs to the old one on the UseDefaultAddress.
691 if (!NewConfigData
->UseDefaultAddress
&&
692 (!EFI_IP4_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
) ||
693 !EFI_IP4_EQUAL (&NewConfigData
->SubnetMask
, &OldConfigData
->SubnetMask
))
696 // If the instance doesn't use the default address, and the new address or
697 // new subnet mask is different from the old values.
703 if (!EFI_IP4_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
705 // The remoteaddress is not the same.
710 if (!EFI_IP4_EQUAL (&NewConfigData
->RemoteAddress
, &mZeroIp4Addr
) &&
711 NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
714 // The RemotePort differs if it's designated in the configdata.
720 // All checks pass, return TRUE.
727 This function builds the Ip4 configdata from the Udp4ConfigData.
729 @param[in] Udp4ConfigData Pointer to the EFI_UDP4_CONFIG_DATA.
730 @param[in, out] Ip4ConfigData Pointer to the EFI_IP4_CONFIG_DATA.
734 Udp4BuildIp4ConfigData (
735 IN EFI_UDP4_CONFIG_DATA
*Udp4ConfigData
,
736 IN OUT EFI_IP4_CONFIG_DATA
*Ip4ConfigData
739 CopyMem (Ip4ConfigData
, &mIp4IoDefaultIpConfigData
, sizeof (*Ip4ConfigData
));
741 Ip4ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
742 Ip4ConfigData
->AcceptBroadcast
= Udp4ConfigData
->AcceptBroadcast
;
743 Ip4ConfigData
->AcceptPromiscuous
= Udp4ConfigData
->AcceptPromiscuous
;
744 Ip4ConfigData
->UseDefaultAddress
= Udp4ConfigData
->UseDefaultAddress
;
745 CopyMem (&Ip4ConfigData
->StationAddress
, &Udp4ConfigData
->StationAddress
, sizeof (EFI_IPv4_ADDRESS
));
746 CopyMem (&Ip4ConfigData
->SubnetMask
, &Udp4ConfigData
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
749 // use the -1 magic number to disable the receiving process of the ip instance.
751 Ip4ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
756 This function validates the TxToken, it returns the error code according to the spec.
758 @param[in] Instance Pointer to the udp instance context data.
759 @param[in] TxToken Pointer to the token to be checked.
761 @retval EFI_SUCCESS The TxToken is valid.
762 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: This is
763 NULL. Token is NULL. Token.Event is NULL.
764 Token.Packet.TxData is NULL.
765 Token.Packet.TxData.FragmentCount is zero.
766 Token.Packet.TxData.DataLength is not equal to the
767 sum of fragment lengths. One or more of the
768 Token.Packet.TxData.FragmentTable[].
769 FragmentLength fields is zero. One or more of the
770 Token.Packet.TxData.FragmentTable[].
771 FragmentBuffer fields is NULL.
772 Token.Packet.TxData. GatewayAddress is not a
773 unicast IPv4 address if it is not NULL. One or
774 more IPv4 addresses in Token.Packet.TxData.
775 UdpSessionData are not valid unicast IPv4
776 addresses if the UdpSessionData is not NULL.
777 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
782 Udp4ValidateTxToken (
783 IN UDP4_INSTANCE_DATA
*Instance
,
784 IN EFI_UDP4_COMPLETION_TOKEN
*TxToken
787 EFI_UDP4_TRANSMIT_DATA
*TxData
;
790 EFI_UDP4_CONFIG_DATA
*ConfigData
;
791 EFI_UDP4_SESSION_DATA
*UdpSessionData
;
792 IP4_ADDR SourceAddress
;
793 IP4_ADDR GatewayAddress
;
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)) {
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 if (TxData
->GatewayAddress
!= NULL
) {
828 CopyMem (&GatewayAddress
, TxData
->GatewayAddress
, sizeof (IP4_ADDR
));
830 if (!Instance
->ConfigData
.UseDefaultAddress
&&
831 (EFI_NTOHL(Instance
->ConfigData
.SubnetMask
) != 0) &&
832 !NetIp4IsUnicast (NTOHL (GatewayAddress
), EFI_NTOHL(Instance
->ConfigData
.SubnetMask
))) {
834 // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.
836 return EFI_INVALID_PARAMETER
;
840 ConfigData
= &Instance
->ConfigData
;
841 UdpSessionData
= TxData
->UdpSessionData
;
843 if (UdpSessionData
!= NULL
) {
845 CopyMem (&SourceAddress
, &UdpSessionData
->SourceAddress
, sizeof (IP4_ADDR
));
847 if ((SourceAddress
!= 0) &&
848 !Instance
->ConfigData
.UseDefaultAddress
&&
849 (EFI_NTOHL(Instance
->ConfigData
.SubnetMask
) != 0) &&
850 !NetIp4IsUnicast (HTONL (SourceAddress
), EFI_NTOHL(Instance
->ConfigData
.SubnetMask
))) {
852 // Check whether SourceAddress is a valid IPv4 address in case it's not zero.
853 // The configured station address is used if SourceAddress is zero.
855 return EFI_INVALID_PARAMETER
;
858 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
860 // Ambiguous, no avalaible DestinationPort for this token.
862 return EFI_INVALID_PARAMETER
;
865 if (EFI_IP4_EQUAL (&UdpSessionData
->DestinationAddress
, &mZeroIp4Addr
)) {
867 // The DestinationAddress specified in the UdpSessionData is 0.
869 return EFI_INVALID_PARAMETER
;
871 } else if (EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &mZeroIp4Addr
)) {
873 // the configured RemoteAddress is all zero, and the user doens't override the
874 // destination address.
876 return EFI_INVALID_PARAMETER
;
879 if (TxData
->DataLength
> UDP4_MAX_DATA_SIZE
) {
880 return EFI_BAD_BUFFER_SIZE
;
888 This function checks whether the specified Token duplicates with the one in the Map.
890 @param[in] Map Pointer to the NET_MAP.
891 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
893 @param[in] Context Pointer to the Token to be checked.
895 @retval EFI_SUCCESS The Token specified by Context differs from the
897 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
904 IN NET_MAP_ITEM
*Item
,
908 EFI_UDP4_COMPLETION_TOKEN
*Token
;
909 EFI_UDP4_COMPLETION_TOKEN
*TokenInItem
;
911 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) Context
;
912 TokenInItem
= (EFI_UDP4_COMPLETION_TOKEN
*) Item
->Key
;
914 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
916 // The Token duplicates with the TokenInItem in case either the two pointers are the
917 // same or the Events of these two tokens are the same.
919 return EFI_ACCESS_DENIED
;
927 This function calculates the checksum for the Packet, utilizing the pre-calculated
928 pseudo HeadSum to reduce some overhead.
930 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
931 @param[in] HeadSum Checksum of the pseudo header execpt the length
934 @retval The 16-bit checksum of this udp datagram.
945 Checksum
= NetbufChecksum (Packet
);
946 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
948 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
950 return (UINT16
) ~Checksum
;
955 This function removes the specified Token from the TokenMap.
957 @param[in, out] TokenMap Pointer to the NET_MAP containing the tokens.
958 @param[in] Token Pointer to the Token to be removed.
960 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
961 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
966 IN OUT NET_MAP
*TokenMap
,
967 IN EFI_UDP4_COMPLETION_TOKEN
*Token
973 // Find the Token first.
975 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
979 // Remove the token if it's found in the map.
981 NetMapRemoveItem (TokenMap
, Item
, NULL
);
986 return EFI_NOT_FOUND
;
991 This function is the packet transmitting notify function registered to the IpIo
992 interface. It's called to signal the udp TxToken when IpIo layer completes the
993 transmitting of the udp datagram.
995 @param[in] Status The completion status of the output udp datagram.
996 @param[in] Context Pointer to the context data.
997 @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending.
998 @param[in] NotifyData Pointer to the notify data.
1004 IN EFI_STATUS Status
,
1006 IN IP_IO_IP_PROTOCOL Sender
,
1010 UDP4_INSTANCE_DATA
*Instance
;
1011 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1013 Instance
= (UDP4_INSTANCE_DATA
*) Context
;
1014 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NotifyData
;
1016 if (Udp4RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
1018 // The token may be cancelled. Only signal it if the remove operation succeeds.
1020 Token
->Status
= Status
;
1021 gBS
->SignalEvent (Token
->Event
);
1028 This function processes the received datagram passed up by the IpIo layer.
1030 @param[in] Status The status of this udp datagram.
1031 @param[in] IcmpError The IcmpError code, only available when Status is
1033 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
1034 @param[in] Packet Pointer to the NET_BUF containing the received udp
1036 @param[in] Context Pointer to the context data.
1042 IN EFI_STATUS Status
,
1044 IN EFI_NET_SESSION_DATA
*NetSession
,
1049 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
1052 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
1054 if (Status
== EFI_SUCCESS
) {
1056 // Demultiplex the received datagram.
1058 Udp4Demultiplex ((UDP4_SERVICE_DATA
*) Context
, NetSession
, Packet
);
1061 // Handle the ICMP_ERROR packet.
1063 Udp4IcmpHandler ((UDP4_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
1067 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
1068 // which are signaled with received data.
1075 This function removes the multicast group specified by Arg from the Map.
1077 @param[in, out] Map Pointer to the NET_MAP.
1078 @param[in] Item Pointer to the NET_MAP_ITEM.
1079 @param[in] Arg Pointer to the Arg, it's the pointer to a
1080 multicast IPv4 Address.
1082 @retval EFI_SUCCESS The multicast address is removed.
1083 @retval EFI_ABORTED The specified multicast address is removed and the
1090 IN OUT NET_MAP
*Map
,
1091 IN NET_MAP_ITEM
*Item
,
1092 IN VOID
*Arg OPTIONAL
1095 EFI_IPv4_ADDRESS
*McastIp
;
1099 if ((McastIp
!= NULL
) && (!EFI_IP4_EQUAL (McastIp
, &(Item
->Key
)))) {
1101 // McastIp is not NULL and the multicast address contained in the Item
1102 // is not the same as McastIp.
1108 // Remove this Item.
1110 NetMapRemoveItem (Map
, Item
, NULL
);
1112 if (McastIp
!= NULL
) {
1114 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
1124 This function cancels the token specified by Arg in the Map. This is a callback
1125 used by Udp4InstanceCancelToken().
1127 @param[in] Map Pointer to the NET_MAP.
1128 @param[in] Item Pointer to the NET_MAP_ITEM.
1129 @param[in] Arg Pointer to the token to be cancelled, if NULL,
1130 the token specified by Item is cancelled.
1132 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
1133 is not the same as that in the Item if Arg is not
1135 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1143 IN NET_MAP_ITEM
*Item
,
1144 IN VOID
*Arg OPTIONAL
1147 EFI_UDP4_COMPLETION_TOKEN
*TokenToCancel
;
1151 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1155 if (Item
->Value
!= NULL
) {
1157 // If the token is a transmit token, the corresponding Packet is recorded in
1158 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1159 // will invoke Udp4DgramSent, the token will be signaled and this Item will
1160 // be removed from the Map there.
1162 Packet
= (NET_BUF
*) (Item
->Value
);
1163 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1165 IpIoCancelTxToken (IpIo
, Packet
);
1168 // The token is a receive token. Abort it and remove it from the Map.
1170 TokenToCancel
= (EFI_UDP4_COMPLETION_TOKEN
*) Item
->Key
;
1171 NetMapRemoveItem (Map
, Item
, NULL
);
1173 TokenToCancel
->Status
= EFI_ABORTED
;
1174 gBS
->SignalEvent (TokenToCancel
->Event
);
1186 This function removes all the Wrap datas in the RcvdDgramQue.
1188 @param[in] Instance Pointer to the udp instance context data.
1192 Udp4FlushRcvdDgram (
1193 IN UDP4_INSTANCE_DATA
*Instance
1196 UDP4_RXDATA_WRAP
*Wrap
;
1198 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1200 // Iterate all the Wraps in the RcvdDgramQue.
1202 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP4_RXDATA_WRAP
, Link
);
1205 // The Wrap will be removed from the RcvdDgramQue by this function call.
1207 Udp4RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1214 Cancel Udp4 tokens from the Udp4 instance.
1216 @param[in] Instance Pointer to the udp instance context data.
1217 @param[in] Token Pointer to the token to be canceled, if NULL, all
1218 tokens in this instance will be cancelled.
1220 @retval EFI_SUCCESS The Token is cancelled.
1221 @retval EFI_NOT_FOUND The Token is not found.
1225 Udp4InstanceCancelToken (
1226 IN UDP4_INSTANCE_DATA
*Instance
,
1227 IN EFI_UDP4_COMPLETION_TOKEN
*Token OPTIONAL
1233 // Cancel this token from the TxTokens map.
1235 Status
= NetMapIterate (&Instance
->TxTokens
, Udp4CancelTokens
, Token
);
1237 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1239 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1240 // the TxTokens, just return success.
1246 // Try to cancel this token from the RxTokens map in condition either the Token
1247 // is NULL or the specified Token is not in TxTokens.
1249 Status
= NetMapIterate (&Instance
->RxTokens
, Udp4CancelTokens
, Token
);
1251 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1253 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1254 // TxTokens nor the RxTokens, or say, it's not found.
1256 return EFI_NOT_FOUND
;
1259 ASSERT ((Token
!= NULL
) || ((0 == NetMapGetCount (&Instance
->TxTokens
))
1260 && (0 == NetMapGetCount (&Instance
->RxTokens
))));
1267 This function matches the received udp datagram with the Instance.
1269 @param[in] Instance Pointer to the udp instance context data.
1270 @param[in] Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted
1271 from the received udp datagram.
1273 @retval TRUE The udp datagram matches the receiving requirments of the
1275 @retval FALSE Otherwise.
1280 IN UDP4_INSTANCE_DATA
*Instance
,
1281 IN EFI_UDP4_SESSION_DATA
*Udp4Session
1284 EFI_UDP4_CONFIG_DATA
*ConfigData
;
1285 IP4_ADDR Destination
;
1287 ConfigData
= &Instance
->ConfigData
;
1289 if (ConfigData
->AcceptPromiscuous
) {
1291 // Always matches if this instance is in the promiscuous state.
1296 if ((!ConfigData
->AcceptAnyPort
&& (Udp4Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1297 ((ConfigData
->RemotePort
!= 0) && (Udp4Session
->SourcePort
!= ConfigData
->RemotePort
))
1300 // The local port or the remote port doesn't match.
1305 if (!EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &mZeroIp4Addr
) &&
1306 !EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &Udp4Session
->SourceAddress
)
1309 // This datagram doesn't come from the instance's specified sender.
1314 if (EFI_IP4_EQUAL (&ConfigData
->StationAddress
, &mZeroIp4Addr
) ||
1315 EFI_IP4_EQUAL (&Udp4Session
->DestinationAddress
, &ConfigData
->StationAddress
)
1318 // The instance is configured to receive datagrams destined to any station IP or
1319 // the destination address of this datagram matches the configured station IP.
1324 CopyMem (&Destination
, &Udp4Session
->DestinationAddress
, sizeof (IP4_ADDR
));
1326 if (IP4_IS_LOCAL_BROADCAST (Destination
) && ConfigData
->AcceptBroadcast
) {
1328 // The instance is configured to receive broadcast and this is a broadcast packet.
1333 if (IP4_IS_MULTICAST (NTOHL (Destination
)) &&
1334 NetMapFindKey (&Instance
->McastIps
, (VOID
*) (UINTN
) Destination
) != NULL
1337 // It's a multicast packet and the multicast address is accepted by this instance.
1347 This function removes the Wrap specified by Context and release relevant resources.
1349 @param[in] Event The Event this notify function registered to.
1350 @param[in] Context Pointer to the context data.
1355 Udp4RecycleRxDataWrap (
1360 UDP4_RXDATA_WRAP
*Wrap
;
1362 Wrap
= (UDP4_RXDATA_WRAP
*) Context
;
1365 // Remove the Wrap from the list it belongs to.
1367 RemoveEntryList (&Wrap
->Link
);
1370 // Free the Packet associated with this Wrap.
1372 NetbufFree (Wrap
->Packet
);
1377 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1384 This function wraps the Packet and the RxData.
1386 @param[in] Instance Pointer to the instance context data.
1387 @param[in] Packet Pointer to the buffer containing the received
1389 @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this
1392 @return Pointer to the structure wrapping the RxData and the Packet.
1397 IN UDP4_INSTANCE_DATA
*Instance
,
1399 IN EFI_UDP4_RECEIVE_DATA
*RxData
1403 UDP4_RXDATA_WRAP
*Wrap
;
1406 // Allocate buffer for the Wrap.
1408 Wrap
= AllocatePool (sizeof (UDP4_RXDATA_WRAP
) +
1409 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1414 InitializeListHead (&Wrap
->Link
);
1416 CopyMem (&Wrap
->RxData
, RxData
, sizeof (Wrap
->RxData
));
1419 // Create the Recycle event.
1421 Status
= gBS
->CreateEvent (
1424 Udp4RecycleRxDataWrap
,
1426 &Wrap
->RxData
.RecycleSignal
1428 if (EFI_ERROR (Status
)) {
1433 Wrap
->Packet
= Packet
;
1434 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1441 This function enqueues the received datagram into the instances' receiving queues.
1443 @param[in] Udp4Service Pointer to the udp service context data.
1444 @param[in] Packet Pointer to the buffer containing the received
1446 @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this
1449 @return The times this datagram is enqueued.
1454 IN UDP4_SERVICE_DATA
*Udp4Service
,
1456 IN EFI_UDP4_RECEIVE_DATA
*RxData
1460 UDP4_INSTANCE_DATA
*Instance
;
1461 UDP4_RXDATA_WRAP
*Wrap
;
1466 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1468 // Iterate the instances.
1470 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1472 if (!Instance
->Configured
) {
1476 if (Udp4MatchDgram (Instance
, &RxData
->UdpSession
)) {
1478 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1480 Wrap
= Udp4WrapRxData (Instance
, Packet
, RxData
);
1485 NET_GET_REF (Packet
);
1487 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1498 This function delivers the received datagrams for the specified instance.
1500 @param[in] Instance Pointer to the instance context data.
1504 Udp4InstanceDeliverDgram (
1505 IN UDP4_INSTANCE_DATA
*Instance
1508 UDP4_RXDATA_WRAP
*Wrap
;
1509 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1511 EFI_UDP4_RECEIVE_DATA
*RxData
;
1514 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1515 !NetMapIsEmpty (&Instance
->RxTokens
)) {
1517 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP4_RXDATA_WRAP
, Link
);
1519 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1521 // Duplicate the Packet if it is shared between instances.
1523 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1528 NetbufFree (Wrap
->Packet
);
1533 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1535 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1538 // Build the FragmentTable and set the FragmentCount in RxData.
1540 RxData
= &Wrap
->RxData
;
1541 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1545 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1546 &RxData
->FragmentCount
1549 Token
->Status
= EFI_SUCCESS
;
1550 Token
->Packet
.RxData
= &Wrap
->RxData
;
1552 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1553 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1554 gBS
->RestoreTPL (OldTpl
);
1556 gBS
->SignalEvent (Token
->Event
);
1562 This function delivers the datagrams enqueued in the instances.
1564 @param[in] Udp4Service Pointer to the udp service context data.
1569 IN UDP4_SERVICE_DATA
*Udp4Service
1573 UDP4_INSTANCE_DATA
*Instance
;
1575 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1577 // Iterate the instances.
1579 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1581 if (!Instance
->Configured
) {
1586 // Deliver the datagrams of this instance.
1588 Udp4InstanceDeliverDgram (Instance
);
1594 This function demultiplexes the received udp datagram to the appropriate instances.
1596 @param[in] Udp4Service Pointer to the udp service context data.
1597 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
1598 the received datagram.
1599 @param[in] Packet Pointer to the buffer containing the received udp
1605 IN UDP4_SERVICE_DATA
*Udp4Service
,
1606 IN EFI_NET_SESSION_DATA
*NetSession
,
1610 EFI_UDP_HEADER
*Udp4Header
;
1612 EFI_UDP4_RECEIVE_DATA RxData
;
1613 EFI_UDP4_SESSION_DATA
*Udp4Session
;
1616 if (Packet
->TotalSize
< sizeof (EFI_UDP_HEADER
)) {
1617 NetbufFree (Packet
);
1622 // Get the datagram header from the packet buffer.
1624 Udp4Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1625 ASSERT (Udp4Header
!= NULL
);
1627 if (Udp4Header
->Checksum
!= 0) {
1629 // check the checksum.
1631 HeadSum
= NetPseudoHeadChecksum (
1632 NetSession
->Source
.Addr
[0],
1633 NetSession
->Dest
.Addr
[0],
1638 if (Udp4Checksum (Packet
, HeadSum
) != 0) {
1642 NetbufFree (Packet
);
1647 Udp4Session
= &RxData
.UdpSession
;
1648 Udp4Session
->SourcePort
= NTOHS (Udp4Header
->SrcPort
);
1649 Udp4Session
->DestinationPort
= NTOHS (Udp4Header
->DstPort
);
1651 CopyMem (&Udp4Session
->SourceAddress
, &NetSession
->Source
, sizeof (EFI_IPv4_ADDRESS
));
1652 CopyMem (&Udp4Session
->DestinationAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1655 // Trim the UDP header.
1657 NetbufTrim (Packet
, UDP4_HEADER_SIZE
, TRUE
);
1659 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1662 // Try to enqueue this datagram into the instances.
1664 Enqueued
= Udp4EnqueueDgram (Udp4Service
, Packet
, &RxData
);
1666 if (Enqueued
== 0) {
1668 // Send the port unreachable ICMP packet before we free this NET_BUF
1670 Udp4SendPortUnreach (Udp4Service
->IpIo
, NetSession
, Udp4Header
);
1674 // Try to free the packet before deliver it.
1676 NetbufFree (Packet
);
1680 // Deliver the datagram.
1682 Udp4DeliverDgram (Udp4Service
);
1688 This function builds and sends out a icmp port unreachable message.
1690 @param[in] IpIo Pointer to the IP_IO instance.
1691 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1692 causes this icmp error message.
1693 @param[in] Udp4Header Pointer to the udp header of the datagram causes
1694 this icmp error message.
1698 Udp4SendPortUnreach (
1700 IN EFI_NET_SESSION_DATA
*NetSession
,
1706 IP4_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1707 EFI_IP4_HEADER
*IpHdr
;
1709 IP_IO_OVERRIDE Override
;
1710 IP_IO_IP_INFO
*IpSender
;
1712 IpSender
= IpIoFindSender (&IpIo
, NetSession
->IpVersion
, &NetSession
->Dest
);
1713 if (IpSender
== NULL
) {
1715 // No appropriate sender, since we cannot send out the ICMP message through
1716 // the default zero station address IP instance, abort.
1721 IpHdr
= NetSession
->IpHdr
.Ip4Hdr
;
1724 // Calculate the required length of the icmp error message.
1726 Len
= sizeof (IP4_ICMP_ERROR_HEAD
) + (EFI_IP4_HEADER_LEN (IpHdr
) -
1727 sizeof (IP4_HEAD
)) + ICMP_ERROR_PACKET_LENGTH
;
1730 // Allocate buffer for the icmp error message.
1732 Packet
= NetbufAlloc (Len
);
1733 if (Packet
== NULL
) {
1738 // Allocate space for the IP4_ICMP_ERROR_HEAD.
1740 IcmpErrHdr
= (IP4_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1741 ASSERT (IcmpErrHdr
!= NULL
);
1744 // Set the required fields for the icmp port unreachable message.
1746 IcmpErrHdr
->Head
.Type
= ICMP_TYPE_UNREACH
;
1747 IcmpErrHdr
->Head
.Code
= ICMP_CODE_UNREACH_PORT
;
1748 IcmpErrHdr
->Head
.Checksum
= 0;
1749 IcmpErrHdr
->Fourth
= 0;
1752 // Copy the IP header of the datagram tragged the error.
1754 CopyMem (&IcmpErrHdr
->IpHead
, IpHdr
, EFI_IP4_HEADER_LEN (IpHdr
));
1757 // Copy the UDP header.
1759 Ptr
= (UINT8
*) &IcmpErrHdr
->IpHead
+ EFI_IP4_HEADER_LEN (IpHdr
);
1760 CopyMem (Ptr
, Udp4Header
, ICMP_ERROR_PACKET_LENGTH
);
1763 // Calculate the checksum.
1765 IcmpErrHdr
->Head
.Checksum
= (UINT16
) ~(NetbufChecksum (Packet
));
1768 // Fill the override data.
1770 Override
.Ip4OverrideData
.DoNotFragment
= FALSE
;
1771 Override
.Ip4OverrideData
.TypeOfService
= 0;
1772 Override
.Ip4OverrideData
.TimeToLive
= 255;
1773 Override
.Ip4OverrideData
.Protocol
= EFI_IP_PROTO_ICMP
;
1775 CopyMem (&Override
.Ip4OverrideData
.SourceAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1776 ZeroMem (&Override
.Ip4OverrideData
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
1779 // Send out this icmp packet.
1781 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, &NetSession
->Source
, &Override
);
1783 NetbufFree (Packet
);
1788 This function handles the received Icmp Error message and demultiplexes it to the
1791 @param[in] Udp4Service Pointer to the udp service context data.
1792 @param[in] IcmpError The icmp error code.
1793 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1794 from the received Icmp Error packet.
1795 @param[in] Packet Pointer to the Icmp Error packet.
1800 IN UDP4_SERVICE_DATA
*Udp4Service
,
1802 IN EFI_NET_SESSION_DATA
*NetSession
,
1806 EFI_UDP_HEADER
*Udp4Header
;
1807 EFI_UDP4_SESSION_DATA Udp4Session
;
1809 UDP4_INSTANCE_DATA
*Instance
;
1811 if (Packet
->TotalSize
< sizeof (EFI_UDP_HEADER
)) {
1812 NetbufFree (Packet
);
1816 Udp4Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1817 ASSERT (Udp4Header
!= NULL
);
1819 CopyMem (&Udp4Session
.SourceAddress
, &NetSession
->Source
, sizeof (EFI_IPv4_ADDRESS
));
1820 CopyMem (&Udp4Session
.DestinationAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1822 Udp4Session
.SourcePort
= NTOHS (Udp4Header
->DstPort
);
1823 Udp4Session
.DestinationPort
= NTOHS (Udp4Header
->SrcPort
);
1825 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1827 // Iterate all the instances.
1829 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1831 if (!Instance
->Configured
) {
1835 if (Udp4MatchDgram (Instance
, &Udp4Session
)) {
1837 // Translate the Icmp Error code according to the udp spec.
1839 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, IP_VERSION_4
, NULL
, NULL
);
1841 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1842 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1846 // Notify the instance with the received Icmp Error.
1848 Udp4ReportIcmpError (Instance
);
1854 NetbufFree (Packet
);
1859 This function reports the received ICMP error.
1861 @param[in] Instance Pointer to the udp instance context data.
1865 Udp4ReportIcmpError (
1866 IN UDP4_INSTANCE_DATA
*Instance
1869 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1871 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1873 // There are no receive tokens to deliver the ICMP error.
1878 if (EFI_ERROR (Instance
->IcmpError
)) {
1880 // Try to get a RxToken from the RxTokens map.
1882 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1884 if (Token
!= NULL
) {
1886 // Report the error through the Token.
1888 Token
->Status
= Instance
->IcmpError
;
1889 gBS
->SignalEvent (Token
->Event
);
1892 // Clear the IcmpError.
1894 Instance
->IcmpError
= EFI_SUCCESS
;
1901 This function is a dummy ext-free function for the NET_BUF created for the output
1904 @param[in] Context Pointer to the context data.
1909 Udp4NetVectorExtFree (