3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The implementation of the Udp4 protocol.
26 UINT16 mUdp4RandomPort
;
38 Udp4FindInstanceByPort (
39 IN NET_LIST_ENTRY
*InstanceList
,
40 IN EFI_IPv4_ADDRESS
*Address
,
57 IN ICMP_ERROR IcmpError
,
58 IN EFI_NET_SESSION_DATA
*NetSession
,
67 IN NET_MAP_ITEM
*Item
,
74 IN UDP4_INSTANCE_DATA
*Instance
,
75 IN EFI_UDP4_SESSION_DATA
*Udp4Session
81 Udp4RecycleRxDataWrap (
89 IN UDP4_INSTANCE_DATA
*Instance
,
91 IN EFI_UDP4_RECEIVE_DATA
*RxData
97 IN UDP4_SERVICE_DATA
*Udp4Service
,
99 IN EFI_UDP4_RECEIVE_DATA
*RxData
105 IN UDP4_SERVICE_DATA
*Udp4Service
111 IN UDP4_SERVICE_DATA
*Udp4Service
,
112 IN EFI_NET_SESSION_DATA
*NetSession
,
119 IN UDP4_SERVICE_DATA
*Udp4Service
,
120 IN ICMP_ERROR IcmpError
,
121 IN EFI_NET_SESSION_DATA
*NetSession
,
127 Udp4SendPortUnreach (
129 IN EFI_NET_SESSION_DATA
*NetSession
,
135 Create the Udp service context data.
137 @param Udp4Service Pointer to the UDP4_SERVICE_DATA.
138 @param ImageHandle The image handle of this udp4 driver.
139 @param ControllerHandle The controller handle this udp4 driver binds on.
141 @retval EFI_SUCCESS The udp4 service context data is created and
143 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
148 IN UDP4_SERVICE_DATA
*Udp4Service
,
149 IN EFI_HANDLE ImageHandle
,
150 IN EFI_HANDLE ControllerHandle
154 IP_IO_OPEN_DATA OpenData
;
156 Udp4Service
->Signature
= UDP4_SERVICE_DATA_SIGNATURE
;
157 Udp4Service
->ServiceBinding
= mUdp4ServiceBinding
;
158 Udp4Service
->ImageHandle
= ImageHandle
;
159 Udp4Service
->ControllerHandle
= ControllerHandle
;
160 Udp4Service
->ChildrenNumber
= 0;
162 NetListInit (&Udp4Service
->ChildrenList
);
165 // Create the IpIo for this service context.
167 Udp4Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
);
168 if (Udp4Service
->IpIo
== NULL
) {
169 return EFI_OUT_OF_RESOURCES
;
173 // Set the OpenData used to open the IpIo.
175 CopyMem (&OpenData
.IpConfigData
, &mIpIoDefaultIpConfigData
, sizeof (OpenData
.IpConfigData
));
176 OpenData
.IpConfigData
.AcceptBroadcast
= TRUE
;
177 OpenData
.RcvdContext
= (VOID
*) Udp4Service
;
178 OpenData
.SndContext
= NULL
;
179 OpenData
.PktRcvdNotify
= Udp4DgramRcvd
;
180 OpenData
.PktSentNotify
= Udp4DgramSent
;
183 // Configure and start the IpIo.
185 Status
= IpIoOpen (Udp4Service
->IpIo
, &OpenData
);
186 if (EFI_ERROR (Status
)) {
191 // Create the event for Udp timeout checking.
193 Status
= gBS
->CreateEvent (
194 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
198 &Udp4Service
->TimeoutEvent
200 if (EFI_ERROR (Status
)) {
205 // Start the timeout timer event.
207 Status
= gBS
->SetTimer (
208 Udp4Service
->TimeoutEvent
,
210 UDP4_TIMEOUT_INTERVAL
212 if (EFI_ERROR (Status
)) {
216 Udp4Service
->MacString
= NULL
;
222 gBS
->CloseEvent (Udp4Service
->TimeoutEvent
);
226 IpIoDestroy (Udp4Service
->IpIo
);
233 Clean the Udp service context data.
235 @param Udp4Service Pointer to the UDP4_SERVICE_DATA.
242 IN UDP4_SERVICE_DATA
*Udp4Service
246 // Cancel the TimeoutEvent timer.
248 gBS
->SetTimer (Udp4Service
->TimeoutEvent
, TimerCancel
, 0);
251 // Close the TimeoutEvent timer.
253 gBS
->CloseEvent (Udp4Service
->TimeoutEvent
);
258 IpIoDestroy (Udp4Service
->IpIo
);
263 This function checks and timeouts the I/O datagrams holding by the corresponding
266 @param Event The event this function registered to.
267 @param Conext The context data registered during the creation of
281 UDP4_SERVICE_DATA
*Udp4Service
;
282 NET_LIST_ENTRY
*Entry
;
283 UDP4_INSTANCE_DATA
*Instance
;
284 NET_LIST_ENTRY
*WrapEntry
;
285 NET_LIST_ENTRY
*NextEntry
;
286 UDP4_RXDATA_WRAP
*Wrap
;
288 Udp4Service
= (UDP4_SERVICE_DATA
*) Context
;
289 NET_CHECK_SIGNATURE (Udp4Service
, UDP4_SERVICE_DATA_SIGNATURE
);
291 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
293 // Iterate all the instances belonging to this service context.
295 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
296 NET_CHECK_SIGNATURE (Instance
, UDP4_INSTANCE_DATA_SIGNATURE
);
298 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
300 // Skip this instance if it's not configured or no receive timeout.
305 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
307 // Iterate all the rxdatas belonging to this udp instance.
309 Wrap
= NET_LIST_USER_STRUCT (Entry
, UDP4_RXDATA_WRAP
, Link
);
311 if (Wrap
->TimeoutTick
<= UDP4_TIMEOUT_INTERVAL
/ 1000) {
313 // Remove this RxData if it timeouts.
315 Udp4RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
317 Wrap
->TimeoutTick
-= UDP4_TIMEOUT_INTERVAL
/ 1000;
325 This function intializes the new created udp instance.
327 @param Udp4Service Pointer to the UDP4_SERVICE_DATA.
328 @param Instance Pointer to the un-initialized UDP4_INSTANCE_DATA.
335 IN UDP4_SERVICE_DATA
*Udp4Service
,
336 IN UDP4_INSTANCE_DATA
*Instance
340 // Set the signature.
342 Instance
->Signature
= UDP4_INSTANCE_DATA_SIGNATURE
;
347 NetListInit (&Instance
->Link
);
348 NetListInit (&Instance
->RcvdDgramQue
);
349 NetListInit (&Instance
->DeliveredDgramQue
);
352 // Init the NET_MAPs.
354 NetMapInit (&Instance
->TxTokens
);
355 NetMapInit (&Instance
->RxTokens
);
356 NetMapInit (&Instance
->McastIps
);
359 // Save the pointer to the UDP4_SERVICE_DATA, and initialize other members.
361 Instance
->Udp4Service
= Udp4Service
;
362 CopyMem (&Instance
->Udp4Proto
, &mUdp4Protocol
, sizeof (Instance
->Udp4Proto
));
363 Instance
->IcmpError
= EFI_SUCCESS
;
364 Instance
->Configured
= FALSE
;
365 Instance
->IsNoMapping
= FALSE
;
366 Instance
->Destroyed
= FALSE
;
371 This function cleans the udp instance.
373 @param Instance Pointer to the UDP4_INSTANCE_DATA to clean.
380 IN UDP4_INSTANCE_DATA
*Instance
383 NetMapClean (&Instance
->McastIps
);
384 NetMapClean (&Instance
->RxTokens
);
385 NetMapClean (&Instance
->TxTokens
);
390 This function finds the udp instance by the specified <Address, Port> pair.
392 @param InstanceList Pointer to the head of the list linking the udp
394 @param Address Pointer to the specified IPv4 address.
395 @param Port The udp port number.
397 @return Is the specified <Address, Port> pair found or not.
402 Udp4FindInstanceByPort (
403 IN NET_LIST_ENTRY
*InstanceList
,
404 IN EFI_IPv4_ADDRESS
*Address
,
408 NET_LIST_ENTRY
*Entry
;
409 UDP4_INSTANCE_DATA
*Instance
;
410 EFI_UDP4_CONFIG_DATA
*ConfigData
;
412 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
414 // Iterate all the udp instances.
416 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
417 ConfigData
= &Instance
->ConfigData
;
419 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
421 // If the instance is not configured or the configdata of the instance indicates
422 // this instance accepts any port, skip it.
427 if (EFI_IP4_EQUAL (&ConfigData
->StationAddress
, Address
) &&
428 (ConfigData
->StationPort
== Port
)) {
430 // if both the address and the port are the same, return TRUE.
437 // return FALSE when matching fails.
444 This function tries to bind the udp instance according to the configured port
447 @param InstanceList Pointer to the head of the list linking the udp
449 @param ConfigData Pointer to the ConfigData of the instance to be
452 @retval EFI_SUCCESS The bound operation is completed successfully.
453 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
454 already used by other instance.
455 @retval EFI_OUT_OF_RESOURCES No available port resources.
460 IN NET_LIST_ENTRY
*InstanceList
,
461 IN EFI_UDP4_CONFIG_DATA
*ConfigData
464 EFI_IPv4_ADDRESS
*StationAddress
;
467 if (ConfigData
->AcceptAnyPort
) {
471 StationAddress
= &ConfigData
->StationAddress
;
473 if (ConfigData
->StationPort
!= 0) {
475 if (!ConfigData
->AllowDuplicatePort
&&
476 Udp4FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)) {
478 // Do not allow duplicate port and the port is already used by other instance.
480 return EFI_ACCESS_DENIED
;
484 // select a random port for this instance;
487 if (ConfigData
->AllowDuplicatePort
) {
489 // Just pick up the random port if the instance allows duplicate port.
491 ConfigData
->StationPort
= mUdp4RandomPort
;
494 StartPort
= mUdp4RandomPort
;
496 while (Udp4FindInstanceByPort(InstanceList
, StationAddress
, mUdp4RandomPort
)) {
499 if (mUdp4RandomPort
== 0) {
500 mUdp4RandomPort
= UDP4_PORT_KNOWN
;
503 if (mUdp4RandomPort
== StartPort
) {
505 // No available port.
507 return EFI_OUT_OF_RESOURCES
;
511 ConfigData
->StationPort
= mUdp4RandomPort
;
515 if (mUdp4RandomPort
== 0) {
516 mUdp4RandomPort
= UDP4_PORT_KNOWN
;
525 This function is used to check whether the NewConfigData has any un-reconfigurable
526 parameters changed compared to the OldConfigData.
528 @param OldConfigData Pointer to the current ConfigData the udp instance
530 @param NewConfigData Pointer to the new ConfigData.
532 @return The instance is reconfigurable or not according to the NewConfigData.
536 Udp4IsReconfigurable (
537 IN EFI_UDP4_CONFIG_DATA
*OldConfigData
,
538 IN EFI_UDP4_CONFIG_DATA
*NewConfigData
541 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
542 (NewConfigData
->AcceptBroadcast
!= OldConfigData
->AcceptBroadcast
) ||
543 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
544 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)) {
546 // The receiving filter parameters cannot be changed.
551 if ((!NewConfigData
->AcceptAnyPort
) &&
552 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)) {
554 // The port is not changeable.
559 if (!NewConfigData
->AcceptPromiscuous
) {
561 if (NewConfigData
->UseDefaultAddress
!= OldConfigData
->UseDefaultAddress
) {
563 // The NewConfigData differs to the old one on the UseDefaultAddress.
568 if (!NewConfigData
->UseDefaultAddress
&&
569 (!EFI_IP4_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
) ||
570 !EFI_IP4_EQUAL (&NewConfigData
->SubnetMask
, &OldConfigData
->SubnetMask
))) {
572 // If the instance doesn't use the default address, and the new address or
573 // new subnet mask is different from the old values.
579 if (!EFI_IP4_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
581 // The remoteaddress is not the same.
586 if (!EFI_IP4_EQUAL (&NewConfigData
->RemoteAddress
, &mZeroIp4Addr
) && (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)) {
588 // The RemotePort differs if it's designated in the configdata.
594 // All checks pass, return TRUE.
601 This function builds the Ip4 configdata from the Udp4ConfigData.
603 @param Udp4ConfigData Pointer to the EFI_UDP4_CONFIG_DATA.
604 @param Ip4ConfigData Pointer to the EFI_IP4_CONFIG_DATA.
610 Udp4BuildIp4ConfigData (
611 IN EFI_UDP4_CONFIG_DATA
*Udp4ConfigData
,
612 IN EFI_IP4_CONFIG_DATA
*Ip4ConfigData
615 CopyMem (Ip4ConfigData
, &mIpIoDefaultIpConfigData
, sizeof (*Ip4ConfigData
));
617 Ip4ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
618 Ip4ConfigData
->AcceptBroadcast
= Udp4ConfigData
->AcceptBroadcast
;
619 Ip4ConfigData
->AcceptPromiscuous
= Udp4ConfigData
->AcceptPromiscuous
;
620 Ip4ConfigData
->UseDefaultAddress
= Udp4ConfigData
->UseDefaultAddress
;
621 Ip4ConfigData
->StationAddress
= Udp4ConfigData
->StationAddress
;
622 Ip4ConfigData
->SubnetMask
= Udp4ConfigData
->SubnetMask
;
625 // use the -1 magic number to disable the receiving process of the ip instance.
627 Ip4ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
632 This function validates the TxToken, it returns the error code according to the spec.
634 @param Instance Pointer to the udp instance context data.
635 @param TxToken Pointer to the token to be checked.
637 @retval EFI_SUCCESS The TxToken is valid.
638 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: This is
639 NULL. Token is NULL. Token.Event is NULL.
640 Token.Packet.TxData is NULL.
641 Token.Packet.TxData.FragmentCount is zero.
642 Token.Packet.TxData.DataLength is not equal to the
643 sum of fragment lengths. One or more of the
644 Token.Packet.TxData.FragmentTable[].
645 FragmentLength fields is zero. One or more of the
646 Token.Packet.TxData.FragmentTable[].
647 FragmentBuffer fields is NULL.
648 Token.Packet.TxData. GatewayAddress is not a
649 unicast IPv4 address if it is not NULL. One or
650 more IPv4 addresses in Token.Packet.TxData.
651 UdpSessionData are not valid unicast IPv4
652 addresses if the UdpSessionData is not NULL.
653 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
658 Udp4ValidateTxToken (
659 IN UDP4_INSTANCE_DATA
*Instance
,
660 IN EFI_UDP4_COMPLETION_TOKEN
*TxToken
663 EFI_UDP4_TRANSMIT_DATA
*TxData
;
666 EFI_UDP4_CONFIG_DATA
*ConfigData
;
667 EFI_UDP4_SESSION_DATA
*UdpSessionData
;
668 IP4_ADDR SourceAddress
;
669 IP4_ADDR GatewayAddress
;
671 if (TxToken
->Event
== NULL
) {
672 return EFI_INVALID_PARAMETER
;
675 TxData
= TxToken
->Packet
.TxData
;
677 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
678 return EFI_INVALID_PARAMETER
;
682 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
684 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
685 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
687 // if the FragmentBuffer is NULL or the FragmentLeng is zero.
689 return EFI_INVALID_PARAMETER
;
692 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
695 if (TotalLen
!= TxData
->DataLength
) {
697 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
700 return EFI_INVALID_PARAMETER
;
703 if (TxData
->GatewayAddress
!= NULL
) {
704 NetCopyMem (&GatewayAddress
, TxData
->GatewayAddress
, sizeof (IP4_ADDR
));
706 if (!Ip4IsUnicast (NTOHL (GatewayAddress
), 0)) {
708 // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.
710 return EFI_INVALID_PARAMETER
;
714 ConfigData
= &Instance
->ConfigData
;
715 UdpSessionData
= TxData
->UdpSessionData
;
717 if (UdpSessionData
!= NULL
) {
719 NetCopyMem (&SourceAddress
, &UdpSessionData
->SourceAddress
, sizeof (IP4_ADDR
));
721 if ((SourceAddress
!= 0) && !Ip4IsUnicast (HTONL (SourceAddress
), 0)) {
723 // Check whether SourceAddress is a valid IPv4 address in case it's not zero.
724 // The configured station address is used if SourceAddress is zero.
726 return EFI_INVALID_PARAMETER
;
729 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
731 // Ambiguous, no avalaible DestinationPort for this token.
733 return EFI_INVALID_PARAMETER
;
736 if (EFI_IP4_EQUAL (&UdpSessionData
->DestinationAddress
, &mZeroIp4Addr
)) {
738 // The DestinationAddress specified in the UdpSessionData is 0.
740 return EFI_INVALID_PARAMETER
;
742 } else if (EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &mZeroIp4Addr
)) {
744 // the configured RemoteAddress is all zero, and the user doens't override the
745 // destination address.
747 return EFI_INVALID_PARAMETER
;
750 if (TxData
->DataLength
> UDP4_MAX_DATA_SIZE
) {
751 return EFI_BAD_BUFFER_SIZE
;
759 This function checks whether the specified Token duplicates with the one in the Map.
761 @param Map Pointer to the NET_MAP.
762 @param Item Pointer to the NET_MAP_ITEM contain the pointer to
764 @param Context Pointer to the Token to be checked.
766 @retval EFI_SUCCESS The Token specified by Context differs from the
768 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
774 IN NET_MAP_ITEM
*Item
,
778 EFI_UDP4_COMPLETION_TOKEN
*Token
;
779 EFI_UDP4_COMPLETION_TOKEN
*TokenInItem
;
781 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) Context
;
782 TokenInItem
= (EFI_UDP4_COMPLETION_TOKEN
*) Item
->Key
;
784 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
786 // The Token duplicates with the TokenInItem in case either the two pointers are the
787 // same or the Events of these two tokens are the same.
789 return EFI_ACCESS_DENIED
;
797 This function calculates the checksum for the Packet, utilizing the pre-calculated
798 pseudo HeadSum to reduce some overhead.
800 @param Packet Pointer to the NET_BUF contains the udp datagram.
801 @param HeadSum Checksum of the pseudo header execpt the length
804 @return The 16-bit checksum of this udp datagram.
815 Checksum
= NetbufChecksum (Packet
);
816 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
818 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
820 return (UINT16
) ~Checksum
;
825 This function removes the specified Token from the TokenMap.
827 @param TokenMap Pointer to the NET_MAP containing the tokens.
828 @param Token Pointer to the Token to be removed.
830 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
831 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
836 IN NET_MAP
*TokenMap
,
837 IN EFI_UDP4_COMPLETION_TOKEN
*Token
843 // Find the Token first.
845 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
849 // Remove the token if it's found in the map.
851 NetMapRemoveItem (TokenMap
, Item
, NULL
);
856 return EFI_NOT_FOUND
;
861 This function is the packet transmitting notify function registered to the IpIo
862 interface. It's called to signal the udp TxToken when IpIo layer completes the
863 transmitting of the udp datagram.
865 @param Status The completion status of the output udp datagram.
866 @param Context Pointer to the context data.
867 @param Sender Pointer to the Ip sender of the udp datagram.
868 @param NotifyData Pointer to the notify data.
876 IN EFI_STATUS Status
,
882 UDP4_INSTANCE_DATA
*Instance
;
883 EFI_UDP4_COMPLETION_TOKEN
*Token
;
885 Instance
= (UDP4_INSTANCE_DATA
*) Context
;
886 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NotifyData
;
888 if (Udp4RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
890 // The token may be cancelled. Only signal it if the remove operation succeeds.
892 Token
->Status
= Status
;
893 gBS
->SignalEvent (Token
->Event
);
899 This function processes the received datagram passed up by the IpIo layer.
901 @param Status The status of this udp datagram.
902 @param IcmpError The IcmpError code, only available when Status is
904 @param NetSession Pointer to the EFI_NET_SESSION_DATA.
905 @param Packet Pointer to the NET_BUF containing the received udp
907 @param Context Pointer to the context data.
915 IN EFI_STATUS Status
,
916 IN ICMP_ERROR IcmpError
,
917 IN EFI_NET_SESSION_DATA
*NetSession
,
922 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
925 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
927 if (Status
== EFI_SUCCESS
) {
929 // Demultiplex the received datagram.
931 Udp4Demultiplex ((UDP4_SERVICE_DATA
*) Context
, NetSession
, Packet
);
934 // Handle the ICMP_ERROR packet.
936 Udp4IcmpHandler ((UDP4_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
942 This function removes the multicast group specified by Arg from the Map.
944 @param Map Pointer to the NET_MAP.
945 @param Item Pointer to the NET_MAP_ITEM.
946 @param Arg Pointer to the Arg, it's the pointer to a
947 multicast IPv4 Address.
949 @retval EFI_SUCCESS The multicast address is removed.
950 @retval EFI_ABORTED The specified multicast address is removed and the
957 IN NET_MAP_ITEM
*Item
,
958 IN VOID
*Arg OPTIONAL
961 EFI_IPv4_ADDRESS
*McastIp
;
965 if ((McastIp
!= NULL
) && (!EFI_IP4_EQUAL (McastIp
, &(Item
->Key
)))) {
967 // McastIp is not NULL and the multicast address contained in the Item
968 // is not the same as McastIp.
976 NetMapRemoveItem (Map
, Item
, NULL
);
978 if (McastIp
!= NULL
) {
980 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
990 This function cancle the token specified by Arg in the Map.
992 @param Map Pointer to the NET_MAP.
993 @param Item Pointer to the NET_MAP_ITEM.
994 @param Arg Pointer to the token to be cancelled, if NULL, all
995 the tokens in this Map will be cancelled.
997 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
998 is not the same as that in the Item if Arg is not
1000 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1008 IN NET_MAP_ITEM
*Item
,
1009 IN VOID
*Arg OPTIONAL
1012 EFI_UDP4_COMPLETION_TOKEN
*TokenToCancel
;
1016 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1020 if (Item
->Value
!= NULL
) {
1022 // If the token is a transmit token, the corresponding Packet is recorded in
1023 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1024 // will invoke Udp4DgramSent, the token will be signaled and this Item will
1025 // be removed from the Map there.
1027 Packet
= (NET_BUF
*) (Item
->Value
);
1028 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1030 IpIoCancelTxToken (IpIo
, Packet
);
1033 // The token is a receive token. Abort it and remove it from the Map.
1035 TokenToCancel
= (EFI_UDP4_COMPLETION_TOKEN
*) Item
->Key
;
1037 TokenToCancel
->Status
= EFI_ABORTED
;
1038 gBS
->SignalEvent (TokenToCancel
->Event
);
1040 NetMapRemoveItem (Map
, Item
, NULL
);
1052 This function removes all the Wrap datas in the RcvdDgramQue.
1054 @param RcvdDgramQue Pointer to the list containing all the Wrap datas.
1061 IN NET_LIST_ENTRY
*RcvdDgramQue
1064 UDP4_RXDATA_WRAP
*Wrap
;
1067 OldTpl
= NET_RAISE_TPL (NET_TPL_RECYCLE
);
1069 while (!NetListIsEmpty (RcvdDgramQue
)) {
1071 // Iterate all the Wraps in the RcvdDgramQue.
1073 Wrap
= NET_LIST_HEAD (RcvdDgramQue
, UDP4_RXDATA_WRAP
, Link
);
1076 // The Wrap will be removed from the RcvdDgramQue by this function call.
1078 Udp4RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1081 NET_RESTORE_TPL (OldTpl
);
1088 @param Instance Pointer to the udp instance context data.
1089 @param Token Pointer to the token to be canceled, if NULL, all
1090 tokens in this instance will be cancelled.
1092 @retval EFI_SUCCESS The Token is cancelled.
1093 @retval EFI_NOT_FOUND The Token is not found.
1097 Udp4InstanceCancelToken (
1098 IN UDP4_INSTANCE_DATA
*Instance
,
1099 IN EFI_UDP4_COMPLETION_TOKEN
*Token OPTIONAL
1105 // Cancle this token from the TxTokens map.
1107 Status
= NetMapIterate (&Instance
->TxTokens
, Udp4CancelTokens
, Token
);
1109 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1111 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1112 // the TxTokens, just return success.
1118 // Try to cancel this token from the RxTokens map in condition either the Token
1119 // is NULL or the specified Token is not in TxTokens.
1121 Status
= NetMapIterate (&Instance
->RxTokens
, Udp4CancelTokens
, Token
);
1123 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1125 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1126 // TxTokens nor the RxTokens, or say, it's not found.
1128 return EFI_NOT_FOUND
;
1131 ASSERT ((Token
!= NULL
) || ((0 == NetMapGetCount (&Instance
->TxTokens
))
1132 && (0 == NetMapGetCount (&Instance
->RxTokens
))));
1139 This function matches the received udp datagram with the Instance.
1141 @param Instance Pointer to the udp instance context data.
1142 @param Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted
1143 from the received udp datagram.
1145 @return The udp datagram matches the receiving requirments of the Instance or not.
1151 IN UDP4_INSTANCE_DATA
*Instance
,
1152 IN EFI_UDP4_SESSION_DATA
*Udp4Session
1155 EFI_UDP4_CONFIG_DATA
*ConfigData
;
1156 IP4_ADDR Destination
;
1158 ConfigData
= &Instance
->ConfigData
;
1160 if (ConfigData
->AcceptPromiscuous
) {
1162 // Always matches if this instance is in the promiscuous state.
1167 if ((!ConfigData
->AcceptAnyPort
&& (Udp4Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1168 ((ConfigData
->RemotePort
!= 0) && (Udp4Session
->SourcePort
!= ConfigData
->RemotePort
))) {
1170 // The local port or the remote port doesn't match.
1175 if (!EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &mZeroIp4Addr
) &&
1176 !EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &Udp4Session
->SourceAddress
)) {
1178 // This datagram doesn't come from the instance's specified sender.
1183 if (EFI_IP4_EQUAL (&ConfigData
->StationAddress
, &mZeroIp4Addr
) ||
1184 EFI_IP4_EQUAL (&Udp4Session
->DestinationAddress
, &ConfigData
->StationAddress
)) {
1186 // The instance is configured to receive datagrams destinated to any station IP or
1187 // the destination address of this datagram matches the configured station IP.
1192 NetCopyMem (&Destination
, &Udp4Session
->DestinationAddress
, sizeof (IP4_ADDR
));
1194 if (IP4_IS_LOCAL_BROADCAST (Destination
) && ConfigData
->AcceptBroadcast
) {
1196 // The instance is configured to receive broadcast and this is a broadcast packet.
1201 if (IP4_IS_MULTICAST (NTOHL (Destination
)) &&
1202 (NULL
!= NetMapFindKey (&Instance
->McastIps
, (VOID
*) (UINTN
) Destination
))) {
1204 // It's a multicast packet and the multicast address is accepted by this instance.
1214 This function removes the Wrap specified by Context and release relevant resources.
1216 @param Event The Event this notify function registered to.
1217 @param Context Pointer to the context data.
1225 Udp4RecycleRxDataWrap (
1230 UDP4_RXDATA_WRAP
*Wrap
;
1232 Wrap
= (UDP4_RXDATA_WRAP
*) Context
;
1235 // Remove the Wrap from the list it belongs to.
1237 NetListRemoveEntry (&Wrap
->Link
);
1240 // Free the Packet associated with this Wrap.
1242 NetbufFree (Wrap
->Packet
);
1247 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1254 This function wraps the Packet and the RxData.
1256 @param Instance Pointer to the instance context data.
1257 @param Packet Pointer to the buffer containing the received
1259 @param RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this
1262 @return Pointer to the structure wrapping the RxData and the Packet.
1268 IN UDP4_INSTANCE_DATA
*Instance
,
1270 IN EFI_UDP4_RECEIVE_DATA
*RxData
1274 UDP4_RXDATA_WRAP
*Wrap
;
1277 // Allocate buffer for the Wrap.
1279 Wrap
= NetAllocatePool (sizeof (UDP4_RXDATA_WRAP
) +
1280 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1285 NetListInit (&Wrap
->Link
);
1287 CopyMem (&Wrap
->RxData
, RxData
, sizeof (Wrap
->RxData
));
1290 // Create the Recycle event.
1292 Status
= gBS
->CreateEvent (
1295 Udp4RecycleRxDataWrap
,
1297 &Wrap
->RxData
.RecycleSignal
1299 if (EFI_ERROR (Status
)) {
1304 Wrap
->Packet
= Packet
;
1305 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1312 This function enqueues the received datagram into the instances' receiving queues.
1314 @param Udp4Service Pointer to the udp service context data.
1315 @param Packet Pointer to the buffer containing the received
1317 @param RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this
1320 @return The times this datagram is enqueued.
1326 IN UDP4_SERVICE_DATA
*Udp4Service
,
1328 IN EFI_UDP4_RECEIVE_DATA
*RxData
1331 NET_LIST_ENTRY
*Entry
;
1332 UDP4_INSTANCE_DATA
*Instance
;
1333 UDP4_RXDATA_WRAP
*Wrap
;
1338 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1340 // Iterate the instances.
1342 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1344 if (!Instance
->Configured
) {
1348 if (Udp4MatchDgram (Instance
, &RxData
->UdpSession
)) {
1350 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1352 Wrap
= Udp4WrapRxData (Instance
, Packet
, RxData
);
1357 NET_GET_REF (Packet
);
1359 NetListInsertTail (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1370 This function delivers the received datagrams for the specified instance.
1372 @param Instance Pointer to the instance context data.
1378 Udp4InstanceDeliverDgram (
1379 IN UDP4_INSTANCE_DATA
*Instance
1382 UDP4_RXDATA_WRAP
*Wrap
;
1383 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1385 EFI_UDP4_RECEIVE_DATA
*RxData
;
1387 if (!NetListIsEmpty (&Instance
->RcvdDgramQue
) &&
1388 !NetMapIsEmpty (&Instance
->RxTokens
)) {
1390 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP4_RXDATA_WRAP
, Link
);
1392 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1394 // Duplicate the Packet if it is shared between instances.
1396 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1401 NetbufFree (Wrap
->Packet
);
1406 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1408 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1411 // Build the FragmentTable and set the FragmentCount in RxData.
1413 RxData
= &Wrap
->RxData
;
1414 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1418 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1419 &RxData
->FragmentCount
1422 Token
->Status
= EFI_SUCCESS
;
1423 Token
->Packet
.RxData
= &Wrap
->RxData
;
1425 gBS
->SignalEvent (Token
->Event
);
1427 NetListInsertTail (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1433 This function delivers the datagrams enqueued in the instances.
1435 @param Udp4Service Pointer to the udp service context data.
1443 IN UDP4_SERVICE_DATA
*Udp4Service
1446 NET_LIST_ENTRY
*Entry
;
1447 UDP4_INSTANCE_DATA
*Instance
;
1449 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1451 // Iterate the instances.
1453 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1455 if (!Instance
->Configured
) {
1460 // Deliver the datagrams of this instance.
1462 Udp4InstanceDeliverDgram (Instance
);
1468 This function demultiplexes the received udp datagram to the apropriate instances.
1470 @param Udp4Service Pointer to the udp service context data.
1471 @param NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from
1472 the received datagram.
1473 @param Packet Pointer to the buffer containing the received udp
1482 IN UDP4_SERVICE_DATA
*Udp4Service
,
1483 IN EFI_NET_SESSION_DATA
*NetSession
,
1487 EFI_UDP4_HEADER
*Udp4Header
;
1489 EFI_UDP4_RECEIVE_DATA RxData
;
1490 EFI_UDP4_SESSION_DATA
*Udp4Session
;
1494 // Get the datagram header from the packet buffer.
1496 Udp4Header
= (EFI_UDP4_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1498 if (Udp4Header
->Checksum
!= 0) {
1500 // check the checksum.
1502 HeadSum
= NetPseudoHeadChecksum (
1509 if (Udp4Checksum (Packet
, HeadSum
) != 0) {
1517 gRT
->GetTime (&RxData
.TimeStamp
, NULL
);
1519 Udp4Session
= &RxData
.UdpSession
;
1520 Udp4Session
->SourcePort
= NTOHS (Udp4Header
->SrcPort
);
1521 Udp4Session
->DestinationPort
= NTOHS (Udp4Header
->DstPort
);
1523 NetCopyMem (&Udp4Session
->SourceAddress
, &NetSession
->Source
, sizeof (EFI_IPv4_ADDRESS
));
1524 NetCopyMem (&Udp4Session
->DestinationAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1527 // Trim the UDP header.
1529 NetbufTrim (Packet
, UDP4_HEADER_SIZE
, TRUE
);
1531 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1534 // Try to enqueue this datagram into the instances.
1536 Enqueued
= Udp4EnqueueDgram (Udp4Service
, Packet
, &RxData
);
1538 if (Enqueued
== 0) {
1540 // Send the port unreachable ICMP packet before we free this NET_BUF
1542 Udp4SendPortUnreach (Udp4Service
->IpIo
, NetSession
, Udp4Header
);
1546 // Try to free the packet before deliver it.
1548 NetbufFree (Packet
);
1552 // Deliver the datagram.
1554 Udp4DeliverDgram (Udp4Service
);
1560 This function builds and sends out a icmp port unreachable message.
1562 @param IpIo Pointer to the IP_IO instance.
1563 @param NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1564 causes this icmp error message.
1565 @param Udp4Header Pointer to the udp header of the datagram causes
1566 this icmp error message.
1573 Udp4SendPortUnreach (
1575 IN EFI_NET_SESSION_DATA
*NetSession
,
1581 IP4_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1582 EFI_IP4_HEADER
*IpHdr
;
1584 IP_IO_OVERRIDE Override
;
1585 IP_IO_IP_INFO
*IpSender
;
1587 IpSender
= IpIoFindSender (&IpIo
, NetSession
->Dest
);
1588 if (IpSender
== NULL
) {
1590 // No apropriate sender, since we cannot send out the ICMP message through
1591 // the default zero station address IP instance, abort.
1596 IpHdr
= NetSession
->IpHdr
;
1599 // Calculate the requried length of the icmp error message.
1601 Len
= sizeof (IP4_ICMP_ERROR_HEAD
) + (EFI_IP4_HEADER_LEN (IpHdr
) -
1602 sizeof (IP4_HEAD
)) + ICMP_ERROR_PACKET_LENGTH
;
1605 // Allocate buffer for the icmp error message.
1607 Packet
= NetbufAlloc (Len
);
1608 if (Packet
== NULL
) {
1613 // Allocate space for the IP4_ICMP_ERROR_HEAD.
1615 IcmpErrHdr
= (IP4_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1618 // Set the required fields for the icmp port unreachable message.
1620 IcmpErrHdr
->Head
.Type
= ICMP_TYPE_UNREACH
;
1621 IcmpErrHdr
->Head
.Code
= ICMP_CODE_UNREACH_PORT
;
1622 IcmpErrHdr
->Head
.Checksum
= 0;
1623 IcmpErrHdr
->Fourth
= 0;
1626 // Copy the IP header of the datagram tragged the error.
1628 NetCopyMem (&IcmpErrHdr
->IpHead
, IpHdr
, EFI_IP4_HEADER_LEN (IpHdr
));
1631 // Copy the UDP header.
1633 Ptr
= (UINT8
*) &IcmpErrHdr
->IpHead
+ EFI_IP4_HEADER_LEN (IpHdr
);
1634 NetCopyMem (Ptr
, Udp4Header
, ICMP_ERROR_PACKET_LENGTH
);
1637 // Calculate the checksum.
1639 IcmpErrHdr
->Head
.Checksum
= (UINT16
) ~(NetbufChecksum (Packet
));
1642 // Fill the override data.
1644 Override
.DoNotFragment
= FALSE
;
1645 Override
.TypeOfService
= 0;
1646 Override
.TimeToLive
= 255;
1647 Override
.Protocol
= EFI_IP_PROTO_ICMP
;
1649 NetCopyMem (&Override
.SourceAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1650 NetZeroMem (&Override
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
1653 // Send out this icmp packet.
1655 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, NetSession
->Source
, &Override
);
1657 NetbufFree (Packet
);
1662 This function handles the received Icmp Error message and demultiplexes it to the
1665 @param Udp4Service Pointer to the udp service context data.
1666 @param IcmpError The icmp error code.
1667 @param NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1668 from the received Icmp Error packet.
1669 @param Packet Pointer to the Icmp Error packet.
1677 IN UDP4_SERVICE_DATA
*Udp4Service
,
1678 IN ICMP_ERROR IcmpError
,
1679 IN EFI_NET_SESSION_DATA
*NetSession
,
1683 EFI_UDP4_HEADER
*Udp4Header
;
1684 EFI_UDP4_SESSION_DATA Udp4Session
;
1685 NET_LIST_ENTRY
*Entry
;
1686 UDP4_INSTANCE_DATA
*Instance
;
1688 Udp4Header
= (EFI_UDP4_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1690 NetCopyMem (&Udp4Session
.SourceAddress
, &NetSession
->Source
, sizeof (EFI_IPv4_ADDRESS
));
1691 NetCopyMem (&Udp4Session
.DestinationAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1693 Udp4Session
.SourcePort
= NTOHS (Udp4Header
->DstPort
);
1694 Udp4Session
.DestinationPort
= NTOHS (Udp4Header
->SrcPort
);
1696 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1698 // Iterate all the instances.
1700 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1702 if (!Instance
->Configured
||
1703 Instance
->ConfigData
.AcceptPromiscuous
||
1704 Instance
->ConfigData
.AcceptAnyPort
||
1705 EFI_IP4_EQUAL (&Instance
->ConfigData
.StationAddress
, &mZeroIp4Addr
)) {
1707 // Don't try to deliver the ICMP error to this instance if it is not configured,
1708 // or it's configured to be promiscuous or accept any port or accept all the
1714 if (Udp4MatchDgram (Instance
, &Udp4Session
)) {
1716 // Translate the Icmp Error code according to the udp spec.
1718 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, NULL
, NULL
);
1720 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1721 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1725 // Notify the instance with the received Icmp Error.
1727 Udp4ReportIcmpError (Instance
);
1733 NetbufFree (Packet
);
1738 This function reports the received ICMP error.
1740 @param Instance Pointer to the udp instance context data.
1746 Udp4ReportIcmpError (
1747 IN UDP4_INSTANCE_DATA
*Instance
1750 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1752 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1754 // There are no receive tokens to deliver the ICMP error.
1759 if (EFI_ERROR (Instance
->IcmpError
)) {
1761 // Try to get a RxToken from the RxTokens map.
1763 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1765 if (Token
!= NULL
) {
1767 // Report the error through the Token.
1769 Token
->Status
= Instance
->IcmpError
;
1770 gBS
->SignalEvent (Token
->Event
);
1773 // Clear the IcmpError.
1775 Instance
->IcmpError
= EFI_SUCCESS
;
1782 This function is a dummy ext-free function for the NET_BUF created for the output
1785 @param Context Pointer to the context data.
1791 Udp4NetVectorExtFree (
1799 Set the Udp4 variable data.
1801 @param Udp4Service Udp4 service data.
1803 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the
1805 @retval other Set variable failed.
1809 Udp4SetVariableData (
1810 IN UDP4_SERVICE_DATA
*Udp4Service
1813 UINT32 NumConfiguredInstance
;
1814 NET_LIST_ENTRY
*Entry
;
1815 UINTN VariableDataSize
;
1816 EFI_UDP4_VARIABLE_DATA
*Udp4VariableData
;
1817 EFI_UDP4_SERVICE_POINT
*Udp4ServicePoint
;
1818 UDP4_INSTANCE_DATA
*Udp4Instance
;
1819 CHAR16
*NewMacString
;
1822 NumConfiguredInstance
= 0;
1825 // Go through the children list to count the configured children.
1827 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1828 Udp4Instance
= NET_LIST_USER_STRUCT_S (
1832 UDP4_INSTANCE_DATA_SIGNATURE
1835 if (Udp4Instance
->Configured
) {
1836 NumConfiguredInstance
++;
1841 // Calculate the size of the Udp4VariableData. As there may be no Udp4 child,
1842 // we should add extra buffer for the service points only if the number of configured
1843 // children is more than 1.
1845 VariableDataSize
= sizeof (EFI_UDP4_VARIABLE_DATA
);
1847 if (NumConfiguredInstance
> 1) {
1848 VariableDataSize
+= sizeof (EFI_UDP4_SERVICE_POINT
) * (NumConfiguredInstance
- 1);
1851 Udp4VariableData
= NetAllocatePool (VariableDataSize
);
1852 if (Udp4VariableData
== NULL
) {
1853 return EFI_OUT_OF_RESOURCES
;
1856 Udp4VariableData
->DriverHandle
= Udp4Service
->ImageHandle
;
1857 Udp4VariableData
->ServiceCount
= NumConfiguredInstance
;
1859 Udp4ServicePoint
= &Udp4VariableData
->Services
[0];
1862 // Go through the children list to fill the configured children's address pairs.
1864 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1865 Udp4Instance
= NET_LIST_USER_STRUCT_S (
1869 UDP4_INSTANCE_DATA_SIGNATURE
1872 if (Udp4Instance
->Configured
) {
1873 Udp4ServicePoint
->InstanceHandle
= Udp4Instance
->ChildHandle
;
1874 Udp4ServicePoint
->LocalAddress
= Udp4Instance
->ConfigData
.StationAddress
;
1875 Udp4ServicePoint
->LocalPort
= Udp4Instance
->ConfigData
.StationPort
;
1876 Udp4ServicePoint
->RemoteAddress
= Udp4Instance
->ConfigData
.RemoteAddress
;
1877 Udp4ServicePoint
->RemotePort
= Udp4Instance
->ConfigData
.RemotePort
;
1884 // Get the mac string.
1886 Status
= NetLibGetMacString (
1887 Udp4Service
->ControllerHandle
,
1888 Udp4Service
->ImageHandle
,
1891 if (EFI_ERROR (Status
)) {
1895 if (Udp4Service
->MacString
!= NULL
) {
1897 // The variable is set already, we're going to update it.
1899 if (StrCmp (Udp4Service
->MacString
, NewMacString
) != 0) {
1901 // The mac address is changed, delete the previous variable first.
1904 Udp4Service
->MacString
,
1905 &gEfiUdp4ServiceBindingProtocolGuid
,
1906 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1912 NetFreePool (Udp4Service
->MacString
);
1915 Udp4Service
->MacString
= NewMacString
;
1917 Status
= gRT
->SetVariable (
1918 Udp4Service
->MacString
,
1919 &gEfiUdp4ServiceBindingProtocolGuid
,
1920 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1922 (VOID
*) Udp4VariableData
1927 NetFreePool (Udp4VariableData
);
1934 Clear the variable and free the resource.
1936 @param Udp4Service Udp4 service data.
1942 Udp4ClearVariableData (
1943 IN UDP4_SERVICE_DATA
*Udp4Service
1946 ASSERT (Udp4Service
->MacString
!= NULL
);
1949 Udp4Service
->MacString
,
1950 &gEfiUdp4ServiceBindingProtocolGuid
,
1951 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1956 NetFreePool (Udp4Service
->MacString
);
1957 Udp4Service
->MacString
= NULL
;