3 Copyright (c) 2006 - 2008, 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
;
36 Udp4FindInstanceByPort (
37 IN LIST_ENTRY
*InstanceList
,
38 IN EFI_IPv4_ADDRESS
*Address
,
53 IN ICMP_ERROR IcmpError
,
54 IN EFI_NET_SESSION_DATA
*NetSession
,
62 IN NET_MAP_ITEM
*Item
,
68 IN UDP4_INSTANCE_DATA
*Instance
,
69 IN EFI_UDP4_SESSION_DATA
*Udp4Session
74 Udp4RecycleRxDataWrap (
81 IN UDP4_INSTANCE_DATA
*Instance
,
83 IN EFI_UDP4_RECEIVE_DATA
*RxData
88 IN UDP4_SERVICE_DATA
*Udp4Service
,
90 IN EFI_UDP4_RECEIVE_DATA
*RxData
95 IN UDP4_SERVICE_DATA
*Udp4Service
100 IN UDP4_SERVICE_DATA
*Udp4Service
,
101 IN EFI_NET_SESSION_DATA
*NetSession
,
107 IN UDP4_SERVICE_DATA
*Udp4Service
,
108 IN ICMP_ERROR IcmpError
,
109 IN EFI_NET_SESSION_DATA
*NetSession
,
114 Udp4SendPortUnreach (
116 IN EFI_NET_SESSION_DATA
*NetSession
,
122 Create the Udp service context data.
124 @param Udp4Service Pointer to the UDP4_SERVICE_DATA.
125 @param ImageHandle The image handle of this udp4 driver.
126 @param ControllerHandle The controller handle this udp4 driver binds on.
128 @retval EFI_SUCCESS The udp4 service context data is created and
130 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
135 IN UDP4_SERVICE_DATA
*Udp4Service
,
136 IN EFI_HANDLE ImageHandle
,
137 IN EFI_HANDLE ControllerHandle
141 IP_IO_OPEN_DATA OpenData
;
143 ZeroMem (Udp4Service
, sizeof (UDP4_SERVICE_DATA
));
145 Udp4Service
->Signature
= UDP4_SERVICE_DATA_SIGNATURE
;
146 Udp4Service
->ServiceBinding
= mUdp4ServiceBinding
;
147 Udp4Service
->ImageHandle
= ImageHandle
;
148 Udp4Service
->ControllerHandle
= ControllerHandle
;
149 Udp4Service
->ChildrenNumber
= 0;
151 InitializeListHead (&Udp4Service
->ChildrenList
);
154 // Create the IpIo for this service context.
156 Udp4Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
);
157 if (Udp4Service
->IpIo
== NULL
) {
158 return EFI_OUT_OF_RESOURCES
;
162 // Set the OpenData used to open the IpIo.
164 CopyMem (&OpenData
.IpConfigData
, &mIpIoDefaultIpConfigData
, sizeof (OpenData
.IpConfigData
));
165 OpenData
.IpConfigData
.AcceptBroadcast
= TRUE
;
166 OpenData
.RcvdContext
= (VOID
*) Udp4Service
;
167 OpenData
.SndContext
= NULL
;
168 OpenData
.PktRcvdNotify
= Udp4DgramRcvd
;
169 OpenData
.PktSentNotify
= Udp4DgramSent
;
172 // Configure and start the IpIo.
174 Status
= IpIoOpen (Udp4Service
->IpIo
, &OpenData
);
175 if (EFI_ERROR (Status
)) {
180 // Create the event for Udp timeout checking.
182 Status
= gBS
->CreateEvent (
183 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
187 &Udp4Service
->TimeoutEvent
189 if (EFI_ERROR (Status
)) {
194 // Start the timeout timer event.
196 Status
= gBS
->SetTimer (
197 Udp4Service
->TimeoutEvent
,
199 UDP4_TIMEOUT_INTERVAL
201 if (EFI_ERROR (Status
)) {
209 if (Udp4Service
->TimeoutEvent
!= NULL
) {
210 gBS
->CloseEvent (Udp4Service
->TimeoutEvent
);
213 IpIoDestroy (Udp4Service
->IpIo
);
220 Clean the Udp service context data.
222 @param Udp4Service Pointer to the UDP4_SERVICE_DATA.
229 IN UDP4_SERVICE_DATA
*Udp4Service
233 // Cancel the TimeoutEvent timer.
235 gBS
->SetTimer (Udp4Service
->TimeoutEvent
, TimerCancel
, 0);
238 // Close the TimeoutEvent timer.
240 gBS
->CloseEvent (Udp4Service
->TimeoutEvent
);
245 IpIoDestroy (Udp4Service
->IpIo
);
250 This function checks and timeouts the I/O datagrams holding by the corresponding
253 @param Event The event this function registered to.
254 @param Conext The context data registered during the creation of
267 UDP4_SERVICE_DATA
*Udp4Service
;
269 UDP4_INSTANCE_DATA
*Instance
;
270 LIST_ENTRY
*WrapEntry
;
271 LIST_ENTRY
*NextEntry
;
272 UDP4_RXDATA_WRAP
*Wrap
;
274 Udp4Service
= (UDP4_SERVICE_DATA
*) Context
;
275 NET_CHECK_SIGNATURE (Udp4Service
, UDP4_SERVICE_DATA_SIGNATURE
);
277 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
279 // Iterate all the instances belonging to this service context.
281 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
282 NET_CHECK_SIGNATURE (Instance
, UDP4_INSTANCE_DATA_SIGNATURE
);
284 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
286 // Skip this instance if it's not configured or no receive timeout.
291 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
293 // Iterate all the rxdatas belonging to this udp instance.
295 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP4_RXDATA_WRAP
, Link
);
297 if (Wrap
->TimeoutTick
<= UDP4_TIMEOUT_INTERVAL
/ 1000) {
299 // Remove this RxData if it timeouts.
301 Udp4RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
303 Wrap
->TimeoutTick
-= UDP4_TIMEOUT_INTERVAL
/ 1000;
311 This function intializes the new created udp instance.
313 @param Udp4Service Pointer to the UDP4_SERVICE_DATA.
314 @param Instance Pointer to the un-initialized UDP4_INSTANCE_DATA.
321 IN UDP4_SERVICE_DATA
*Udp4Service
,
322 IN UDP4_INSTANCE_DATA
*Instance
326 // Set the signature.
328 Instance
->Signature
= UDP4_INSTANCE_DATA_SIGNATURE
;
333 InitializeListHead (&Instance
->Link
);
334 InitializeListHead (&Instance
->RcvdDgramQue
);
335 InitializeListHead (&Instance
->DeliveredDgramQue
);
338 // Init the NET_MAPs.
340 NetMapInit (&Instance
->TxTokens
);
341 NetMapInit (&Instance
->RxTokens
);
342 NetMapInit (&Instance
->McastIps
);
345 // Save the pointer to the UDP4_SERVICE_DATA, and initialize other members.
347 Instance
->Udp4Service
= Udp4Service
;
348 CopyMem (&Instance
->Udp4Proto
, &mUdp4Protocol
, sizeof (Instance
->Udp4Proto
));
349 Instance
->IcmpError
= EFI_SUCCESS
;
350 Instance
->Configured
= FALSE
;
351 Instance
->IsNoMapping
= FALSE
;
352 Instance
->Destroyed
= FALSE
;
357 This function cleans the udp instance.
359 @param Instance Pointer to the UDP4_INSTANCE_DATA to clean.
366 IN UDP4_INSTANCE_DATA
*Instance
369 NetMapClean (&Instance
->McastIps
);
370 NetMapClean (&Instance
->RxTokens
);
371 NetMapClean (&Instance
->TxTokens
);
376 This function finds the udp instance by the specified <Address, Port> pair.
378 @param InstanceList Pointer to the head of the list linking the udp
380 @param Address Pointer to the specified IPv4 address.
381 @param Port The udp port number.
383 @return Is the specified <Address, Port> pair found or not.
387 Udp4FindInstanceByPort (
388 IN LIST_ENTRY
*InstanceList
,
389 IN EFI_IPv4_ADDRESS
*Address
,
394 UDP4_INSTANCE_DATA
*Instance
;
395 EFI_UDP4_CONFIG_DATA
*ConfigData
;
397 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
399 // Iterate all the udp instances.
401 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
402 ConfigData
= &Instance
->ConfigData
;
404 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
406 // If the instance is not configured or the configdata of the instance indicates
407 // this instance accepts any port, skip it.
412 if (EFI_IP4_EQUAL (&ConfigData
->StationAddress
, Address
) &&
413 (ConfigData
->StationPort
== Port
)) {
415 // if both the address and the port are the same, return TRUE.
422 // return FALSE when matching fails.
429 This function tries to bind the udp instance according to the configured port
432 @param InstanceList Pointer to the head of the list linking the udp
434 @param ConfigData Pointer to the ConfigData of the instance to be
437 @retval EFI_SUCCESS The bound operation is completed successfully.
438 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
439 already used by other instance.
440 @retval EFI_OUT_OF_RESOURCES No available port resources.
445 IN LIST_ENTRY
*InstanceList
,
446 IN EFI_UDP4_CONFIG_DATA
*ConfigData
449 EFI_IPv4_ADDRESS
*StationAddress
;
452 if (ConfigData
->AcceptAnyPort
) {
456 StationAddress
= &ConfigData
->StationAddress
;
458 if (ConfigData
->StationPort
!= 0) {
460 if (!ConfigData
->AllowDuplicatePort
&&
461 Udp4FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)) {
463 // Do not allow duplicate port and the port is already used by other instance.
465 return EFI_ACCESS_DENIED
;
469 // select a random port for this instance;
472 if (ConfigData
->AllowDuplicatePort
) {
474 // Just pick up the random port if the instance allows duplicate port.
476 ConfigData
->StationPort
= mUdp4RandomPort
;
479 StartPort
= mUdp4RandomPort
;
481 while (Udp4FindInstanceByPort(InstanceList
, StationAddress
, mUdp4RandomPort
)) {
484 if (mUdp4RandomPort
== 0) {
485 mUdp4RandomPort
= UDP4_PORT_KNOWN
;
488 if (mUdp4RandomPort
== StartPort
) {
490 // No available port.
492 return EFI_OUT_OF_RESOURCES
;
496 ConfigData
->StationPort
= mUdp4RandomPort
;
500 if (mUdp4RandomPort
== 0) {
501 mUdp4RandomPort
= UDP4_PORT_KNOWN
;
510 This function is used to check whether the NewConfigData has any un-reconfigurable
511 parameters changed compared to the OldConfigData.
513 @param OldConfigData Pointer to the current ConfigData the udp instance
515 @param NewConfigData Pointer to the new ConfigData.
517 @return The instance is reconfigurable or not according to the NewConfigData.
521 Udp4IsReconfigurable (
522 IN EFI_UDP4_CONFIG_DATA
*OldConfigData
,
523 IN EFI_UDP4_CONFIG_DATA
*NewConfigData
526 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
527 (NewConfigData
->AcceptBroadcast
!= OldConfigData
->AcceptBroadcast
) ||
528 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
529 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)) {
531 // The receiving filter parameters cannot be changed.
536 if ((!NewConfigData
->AcceptAnyPort
) &&
537 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)) {
539 // The port is not changeable.
544 if (!NewConfigData
->AcceptPromiscuous
) {
546 if (NewConfigData
->UseDefaultAddress
!= OldConfigData
->UseDefaultAddress
) {
548 // The NewConfigData differs to the old one on the UseDefaultAddress.
553 if (!NewConfigData
->UseDefaultAddress
&&
554 (!EFI_IP4_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
) ||
555 !EFI_IP4_EQUAL (&NewConfigData
->SubnetMask
, &OldConfigData
->SubnetMask
))) {
557 // If the instance doesn't use the default address, and the new address or
558 // new subnet mask is different from the old values.
564 if (!EFI_IP4_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
566 // The remoteaddress is not the same.
571 if (!EFI_IP4_EQUAL (&NewConfigData
->RemoteAddress
, &mZeroIp4Addr
) && (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)) {
573 // The RemotePort differs if it's designated in the configdata.
579 // All checks pass, return TRUE.
586 This function builds the Ip4 configdata from the Udp4ConfigData.
588 @param Udp4ConfigData Pointer to the EFI_UDP4_CONFIG_DATA.
589 @param Ip4ConfigData Pointer to the EFI_IP4_CONFIG_DATA.
595 Udp4BuildIp4ConfigData (
596 IN EFI_UDP4_CONFIG_DATA
*Udp4ConfigData
,
597 IN EFI_IP4_CONFIG_DATA
*Ip4ConfigData
600 CopyMem (Ip4ConfigData
, &mIpIoDefaultIpConfigData
, sizeof (*Ip4ConfigData
));
602 Ip4ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
603 Ip4ConfigData
->AcceptBroadcast
= Udp4ConfigData
->AcceptBroadcast
;
604 Ip4ConfigData
->AcceptPromiscuous
= Udp4ConfigData
->AcceptPromiscuous
;
605 Ip4ConfigData
->UseDefaultAddress
= Udp4ConfigData
->UseDefaultAddress
;
606 CopyMem (&Ip4ConfigData
->StationAddress
, &Udp4ConfigData
->StationAddress
, sizeof (EFI_IPv4_ADDRESS
));
607 CopyMem (&Ip4ConfigData
->SubnetMask
, &Udp4ConfigData
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
610 // use the -1 magic number to disable the receiving process of the ip instance.
612 Ip4ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
617 This function validates the TxToken, it returns the error code according to the spec.
619 @param Instance Pointer to the udp instance context data.
620 @param TxToken Pointer to the token to be checked.
622 @retval EFI_SUCCESS The TxToken is valid.
623 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: This is
624 NULL. Token is NULL. Token.Event is NULL.
625 Token.Packet.TxData is NULL.
626 Token.Packet.TxData.FragmentCount is zero.
627 Token.Packet.TxData.DataLength is not equal to the
628 sum of fragment lengths. One or more of the
629 Token.Packet.TxData.FragmentTable[].
630 FragmentLength fields is zero. One or more of the
631 Token.Packet.TxData.FragmentTable[].
632 FragmentBuffer fields is NULL.
633 Token.Packet.TxData. GatewayAddress is not a
634 unicast IPv4 address if it is not NULL. One or
635 more IPv4 addresses in Token.Packet.TxData.
636 UdpSessionData are not valid unicast IPv4
637 addresses if the UdpSessionData is not NULL.
638 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
643 Udp4ValidateTxToken (
644 IN UDP4_INSTANCE_DATA
*Instance
,
645 IN EFI_UDP4_COMPLETION_TOKEN
*TxToken
648 EFI_UDP4_TRANSMIT_DATA
*TxData
;
651 EFI_UDP4_CONFIG_DATA
*ConfigData
;
652 EFI_UDP4_SESSION_DATA
*UdpSessionData
;
653 IP4_ADDR SourceAddress
;
654 IP4_ADDR GatewayAddress
;
656 if (TxToken
->Event
== NULL
) {
657 return EFI_INVALID_PARAMETER
;
660 TxData
= TxToken
->Packet
.TxData
;
662 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
663 return EFI_INVALID_PARAMETER
;
667 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
669 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
670 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
672 // if the FragmentBuffer is NULL or the FragmentLeng is zero.
674 return EFI_INVALID_PARAMETER
;
677 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
680 if (TotalLen
!= TxData
->DataLength
) {
682 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
685 return EFI_INVALID_PARAMETER
;
688 if (TxData
->GatewayAddress
!= NULL
) {
689 CopyMem (&GatewayAddress
, TxData
->GatewayAddress
, sizeof (IP4_ADDR
));
691 if (!Ip4IsUnicast (NTOHL (GatewayAddress
), 0)) {
693 // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.
695 return EFI_INVALID_PARAMETER
;
699 ConfigData
= &Instance
->ConfigData
;
700 UdpSessionData
= TxData
->UdpSessionData
;
702 if (UdpSessionData
!= NULL
) {
704 CopyMem (&SourceAddress
, &UdpSessionData
->SourceAddress
, sizeof (IP4_ADDR
));
706 if ((SourceAddress
!= 0) && !Ip4IsUnicast (HTONL (SourceAddress
), 0)) {
708 // Check whether SourceAddress is a valid IPv4 address in case it's not zero.
709 // The configured station address is used if SourceAddress is zero.
711 return EFI_INVALID_PARAMETER
;
714 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
716 // Ambiguous, no avalaible DestinationPort for this token.
718 return EFI_INVALID_PARAMETER
;
721 if (EFI_IP4_EQUAL (&UdpSessionData
->DestinationAddress
, &mZeroIp4Addr
)) {
723 // The DestinationAddress specified in the UdpSessionData is 0.
725 return EFI_INVALID_PARAMETER
;
727 } else if (EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &mZeroIp4Addr
)) {
729 // the configured RemoteAddress is all zero, and the user doens't override the
730 // destination address.
732 return EFI_INVALID_PARAMETER
;
735 if (TxData
->DataLength
> UDP4_MAX_DATA_SIZE
) {
736 return EFI_BAD_BUFFER_SIZE
;
744 This function checks whether the specified Token duplicates with the one in the Map.
746 @param Map Pointer to the NET_MAP.
747 @param Item Pointer to the NET_MAP_ITEM contain the pointer to
749 @param Context Pointer to the Token to be checked.
751 @retval EFI_SUCCESS The Token specified by Context differs from the
753 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
759 IN NET_MAP_ITEM
*Item
,
763 EFI_UDP4_COMPLETION_TOKEN
*Token
;
764 EFI_UDP4_COMPLETION_TOKEN
*TokenInItem
;
766 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) Context
;
767 TokenInItem
= (EFI_UDP4_COMPLETION_TOKEN
*) Item
->Key
;
769 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
771 // The Token duplicates with the TokenInItem in case either the two pointers are the
772 // same or the Events of these two tokens are the same.
774 return EFI_ACCESS_DENIED
;
782 This function calculates the checksum for the Packet, utilizing the pre-calculated
783 pseudo HeadSum to reduce some overhead.
785 @param Packet Pointer to the NET_BUF contains the udp datagram.
786 @param HeadSum Checksum of the pseudo header execpt the length
789 @return The 16-bit checksum of this udp datagram.
800 Checksum
= NetbufChecksum (Packet
);
801 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
803 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
805 return (UINT16
) ~Checksum
;
810 This function removes the specified Token from the TokenMap.
812 @param TokenMap Pointer to the NET_MAP containing the tokens.
813 @param Token Pointer to the Token to be removed.
815 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
816 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
821 IN NET_MAP
*TokenMap
,
822 IN EFI_UDP4_COMPLETION_TOKEN
*Token
828 // Find the Token first.
830 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
834 // Remove the token if it's found in the map.
836 NetMapRemoveItem (TokenMap
, Item
, NULL
);
841 return EFI_NOT_FOUND
;
846 This function is the packet transmitting notify function registered to the IpIo
847 interface. It's called to signal the udp TxToken when IpIo layer completes the
848 transmitting of the udp datagram.
850 @param Status The completion status of the output udp datagram.
851 @param Context Pointer to the context data.
852 @param Sender Pointer to the Ip sender of the udp datagram.
853 @param NotifyData Pointer to the notify data.
860 IN EFI_STATUS Status
,
866 UDP4_INSTANCE_DATA
*Instance
;
867 EFI_UDP4_COMPLETION_TOKEN
*Token
;
869 Instance
= (UDP4_INSTANCE_DATA
*) Context
;
870 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NotifyData
;
872 if (Udp4RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
874 // The token may be cancelled. Only signal it if the remove operation succeeds.
876 Token
->Status
= Status
;
877 gBS
->SignalEvent (Token
->Event
);
878 NetLibDispatchDpc ();
884 This function processes the received datagram passed up by the IpIo layer.
886 @param Status The status of this udp datagram.
887 @param IcmpError The IcmpError code, only available when Status is
889 @param NetSession Pointer to the EFI_NET_SESSION_DATA.
890 @param Packet Pointer to the NET_BUF containing the received udp
892 @param Context Pointer to the context data.
899 IN EFI_STATUS Status
,
900 IN ICMP_ERROR IcmpError
,
901 IN EFI_NET_SESSION_DATA
*NetSession
,
906 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
909 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
911 if (Status
== EFI_SUCCESS
) {
913 // Demultiplex the received datagram.
915 Udp4Demultiplex ((UDP4_SERVICE_DATA
*) Context
, NetSession
, Packet
);
918 // Handle the ICMP_ERROR packet.
920 Udp4IcmpHandler ((UDP4_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
924 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
925 // which are signaled with received data.
927 NetLibDispatchDpc ();
932 This function removes the multicast group specified by Arg from the Map.
934 @param Map Pointer to the NET_MAP.
935 @param Item Pointer to the NET_MAP_ITEM.
936 @param Arg Pointer to the Arg, it's the pointer to a
937 multicast IPv4 Address.
939 @retval EFI_SUCCESS The multicast address is removed.
940 @retval EFI_ABORTED The specified multicast address is removed and the
947 IN NET_MAP_ITEM
*Item
,
948 IN VOID
*Arg OPTIONAL
951 EFI_IPv4_ADDRESS
*McastIp
;
955 if ((McastIp
!= NULL
) && (!EFI_IP4_EQUAL (McastIp
, &(Item
->Key
)))) {
957 // McastIp is not NULL and the multicast address contained in the Item
958 // is not the same as McastIp.
966 NetMapRemoveItem (Map
, Item
, NULL
);
968 if (McastIp
!= NULL
) {
970 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
980 This function cancle the token specified by Arg in the Map.
982 @param Map Pointer to the NET_MAP.
983 @param Item Pointer to the NET_MAP_ITEM.
984 @param Arg Pointer to the token to be cancelled, if NULL, all
985 the tokens in this Map will be cancelled.
987 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
988 is not the same as that in the Item if Arg is not
990 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
997 IN NET_MAP_ITEM
*Item
,
998 IN VOID
*Arg OPTIONAL
1001 EFI_UDP4_COMPLETION_TOKEN
*TokenToCancel
;
1005 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1009 if (Item
->Value
!= NULL
) {
1011 // If the token is a transmit token, the corresponding Packet is recorded in
1012 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1013 // will invoke Udp4DgramSent, the token will be signaled and this Item will
1014 // be removed from the Map there.
1016 Packet
= (NET_BUF
*) (Item
->Value
);
1017 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1019 IpIoCancelTxToken (IpIo
, Packet
);
1022 // The token is a receive token. Abort it and remove it from the Map.
1024 TokenToCancel
= (EFI_UDP4_COMPLETION_TOKEN
*) Item
->Key
;
1025 NetMapRemoveItem (Map
, Item
, NULL
);
1027 TokenToCancel
->Status
= EFI_ABORTED
;
1028 gBS
->SignalEvent (TokenToCancel
->Event
);
1040 This function removes all the Wrap datas in the RcvdDgramQue.
1042 @param RcvdDgramQue Pointer to the list containing all the Wrap datas.
1048 Udp4FlushRcvdDgram (
1049 IN UDP4_INSTANCE_DATA
*Instance
1052 UDP4_RXDATA_WRAP
*Wrap
;
1054 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1056 // Iterate all the Wraps in the RcvdDgramQue.
1058 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP4_RXDATA_WRAP
, Link
);
1061 // The Wrap will be removed from the RcvdDgramQue by this function call.
1063 Udp4RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1071 @param Instance Pointer to the udp instance context data.
1072 @param Token Pointer to the token to be canceled, if NULL, all
1073 tokens in this instance will be cancelled.
1075 @retval EFI_SUCCESS The Token is cancelled.
1076 @retval EFI_NOT_FOUND The Token is not found.
1080 Udp4InstanceCancelToken (
1081 IN UDP4_INSTANCE_DATA
*Instance
,
1082 IN EFI_UDP4_COMPLETION_TOKEN
*Token OPTIONAL
1088 // Cancle this token from the TxTokens map.
1090 Status
= NetMapIterate (&Instance
->TxTokens
, Udp4CancelTokens
, Token
);
1092 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1094 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1095 // the TxTokens, just return success.
1101 // Try to cancel this token from the RxTokens map in condition either the Token
1102 // is NULL or the specified Token is not in TxTokens.
1104 Status
= NetMapIterate (&Instance
->RxTokens
, Udp4CancelTokens
, Token
);
1106 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1108 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1109 // TxTokens nor the RxTokens, or say, it's not found.
1111 return EFI_NOT_FOUND
;
1114 ASSERT ((Token
!= NULL
) || ((0 == NetMapGetCount (&Instance
->TxTokens
))
1115 && (0 == NetMapGetCount (&Instance
->RxTokens
))));
1122 This function matches the received udp datagram with the Instance.
1124 @param Instance Pointer to the udp instance context data.
1125 @param Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted
1126 from the received udp datagram.
1128 @return The udp datagram matches the receiving requirments of the Instance or not.
1133 IN UDP4_INSTANCE_DATA
*Instance
,
1134 IN EFI_UDP4_SESSION_DATA
*Udp4Session
1137 EFI_UDP4_CONFIG_DATA
*ConfigData
;
1138 IP4_ADDR Destination
;
1140 ConfigData
= &Instance
->ConfigData
;
1142 if (ConfigData
->AcceptPromiscuous
) {
1144 // Always matches if this instance is in the promiscuous state.
1149 if ((!ConfigData
->AcceptAnyPort
&& (Udp4Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1150 ((ConfigData
->RemotePort
!= 0) && (Udp4Session
->SourcePort
!= ConfigData
->RemotePort
))) {
1152 // The local port or the remote port doesn't match.
1157 if (!EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &mZeroIp4Addr
) &&
1158 !EFI_IP4_EQUAL (&ConfigData
->RemoteAddress
, &Udp4Session
->SourceAddress
)) {
1160 // This datagram doesn't come from the instance's specified sender.
1165 if (EFI_IP4_EQUAL (&ConfigData
->StationAddress
, &mZeroIp4Addr
) ||
1166 EFI_IP4_EQUAL (&Udp4Session
->DestinationAddress
, &ConfigData
->StationAddress
)) {
1168 // The instance is configured to receive datagrams destinated to any station IP or
1169 // the destination address of this datagram matches the configured station IP.
1174 CopyMem (&Destination
, &Udp4Session
->DestinationAddress
, sizeof (IP4_ADDR
));
1176 if (IP4_IS_LOCAL_BROADCAST (Destination
) && ConfigData
->AcceptBroadcast
) {
1178 // The instance is configured to receive broadcast and this is a broadcast packet.
1183 if (IP4_IS_MULTICAST (NTOHL (Destination
)) &&
1184 (NULL
!= NetMapFindKey (&Instance
->McastIps
, (VOID
*) (UINTN
) Destination
))) {
1186 // It's a multicast packet and the multicast address is accepted by this instance.
1196 This function removes the Wrap specified by Context and release relevant resources.
1198 @param Event The Event this notify function registered to.
1199 @param Context Pointer to the context data.
1206 Udp4RecycleRxDataWrap (
1211 UDP4_RXDATA_WRAP
*Wrap
;
1213 Wrap
= (UDP4_RXDATA_WRAP
*) Context
;
1216 // Remove the Wrap from the list it belongs to.
1218 RemoveEntryList (&Wrap
->Link
);
1221 // Free the Packet associated with this Wrap.
1223 NetbufFree (Wrap
->Packet
);
1228 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1230 gBS
->FreePool (Wrap
);
1235 This function wraps the Packet and the RxData.
1237 @param Instance Pointer to the instance context data.
1238 @param Packet Pointer to the buffer containing the received
1240 @param RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this
1243 @return Pointer to the structure wrapping the RxData and the Packet.
1248 IN UDP4_INSTANCE_DATA
*Instance
,
1250 IN EFI_UDP4_RECEIVE_DATA
*RxData
1254 UDP4_RXDATA_WRAP
*Wrap
;
1257 // Allocate buffer for the Wrap.
1259 Wrap
= AllocatePool (sizeof (UDP4_RXDATA_WRAP
) +
1260 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1265 InitializeListHead (&Wrap
->Link
);
1267 CopyMem (&Wrap
->RxData
, RxData
, sizeof (Wrap
->RxData
));
1270 // Create the Recycle event.
1272 Status
= gBS
->CreateEvent (
1275 Udp4RecycleRxDataWrap
,
1277 &Wrap
->RxData
.RecycleSignal
1279 if (EFI_ERROR (Status
)) {
1280 gBS
->FreePool (Wrap
);
1284 Wrap
->Packet
= Packet
;
1285 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1292 This function enqueues the received datagram into the instances' receiving queues.
1294 @param Udp4Service Pointer to the udp service context data.
1295 @param Packet Pointer to the buffer containing the received
1297 @param RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this
1300 @return The times this datagram is enqueued.
1305 IN UDP4_SERVICE_DATA
*Udp4Service
,
1307 IN EFI_UDP4_RECEIVE_DATA
*RxData
1311 UDP4_INSTANCE_DATA
*Instance
;
1312 UDP4_RXDATA_WRAP
*Wrap
;
1317 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1319 // Iterate the instances.
1321 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1323 if (!Instance
->Configured
) {
1327 if (Udp4MatchDgram (Instance
, &RxData
->UdpSession
)) {
1329 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1331 Wrap
= Udp4WrapRxData (Instance
, Packet
, RxData
);
1336 NET_GET_REF (Packet
);
1338 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1349 This function delivers the received datagrams for the specified instance.
1351 @param Instance Pointer to the instance context data.
1357 Udp4InstanceDeliverDgram (
1358 IN UDP4_INSTANCE_DATA
*Instance
1361 UDP4_RXDATA_WRAP
*Wrap
;
1362 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1364 EFI_UDP4_RECEIVE_DATA
*RxData
;
1367 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1368 !NetMapIsEmpty (&Instance
->RxTokens
)) {
1370 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP4_RXDATA_WRAP
, Link
);
1372 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1374 // Duplicate the Packet if it is shared between instances.
1376 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1381 NetbufFree (Wrap
->Packet
);
1386 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1388 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1391 // Build the FragmentTable and set the FragmentCount in RxData.
1393 RxData
= &Wrap
->RxData
;
1394 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1398 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1399 &RxData
->FragmentCount
1402 Token
->Status
= EFI_SUCCESS
;
1403 Token
->Packet
.RxData
= &Wrap
->RxData
;
1405 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1406 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1407 gBS
->RestoreTPL (OldTpl
);
1409 gBS
->SignalEvent (Token
->Event
);
1415 This function delivers the datagrams enqueued in the instances.
1417 @param Udp4Service Pointer to the udp service context data.
1424 IN UDP4_SERVICE_DATA
*Udp4Service
1428 UDP4_INSTANCE_DATA
*Instance
;
1430 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1432 // Iterate the instances.
1434 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1436 if (!Instance
->Configured
) {
1441 // Deliver the datagrams of this instance.
1443 Udp4InstanceDeliverDgram (Instance
);
1449 This function demultiplexes the received udp datagram to the apropriate instances.
1451 @param Udp4Service Pointer to the udp service context data.
1452 @param NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from
1453 the received datagram.
1454 @param Packet Pointer to the buffer containing the received udp
1462 IN UDP4_SERVICE_DATA
*Udp4Service
,
1463 IN EFI_NET_SESSION_DATA
*NetSession
,
1467 EFI_UDP4_HEADER
*Udp4Header
;
1469 EFI_UDP4_RECEIVE_DATA RxData
;
1470 EFI_UDP4_SESSION_DATA
*Udp4Session
;
1474 // Get the datagram header from the packet buffer.
1476 Udp4Header
= (EFI_UDP4_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1478 if (Udp4Header
->Checksum
!= 0) {
1480 // check the checksum.
1482 HeadSum
= NetPseudoHeadChecksum (
1489 if (Udp4Checksum (Packet
, HeadSum
) != 0) {
1497 gRT
->GetTime (&RxData
.TimeStamp
, NULL
);
1499 Udp4Session
= &RxData
.UdpSession
;
1500 Udp4Session
->SourcePort
= NTOHS (Udp4Header
->SrcPort
);
1501 Udp4Session
->DestinationPort
= NTOHS (Udp4Header
->DstPort
);
1503 CopyMem (&Udp4Session
->SourceAddress
, &NetSession
->Source
, sizeof (EFI_IPv4_ADDRESS
));
1504 CopyMem (&Udp4Session
->DestinationAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1507 // Trim the UDP header.
1509 NetbufTrim (Packet
, UDP4_HEADER_SIZE
, TRUE
);
1511 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1514 // Try to enqueue this datagram into the instances.
1516 Enqueued
= Udp4EnqueueDgram (Udp4Service
, Packet
, &RxData
);
1518 if (Enqueued
== 0) {
1520 // Send the port unreachable ICMP packet before we free this NET_BUF
1522 Udp4SendPortUnreach (Udp4Service
->IpIo
, NetSession
, Udp4Header
);
1526 // Try to free the packet before deliver it.
1528 NetbufFree (Packet
);
1532 // Deliver the datagram.
1534 Udp4DeliverDgram (Udp4Service
);
1540 This function builds and sends out a icmp port unreachable message.
1542 @param IpIo Pointer to the IP_IO instance.
1543 @param NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1544 causes this icmp error message.
1545 @param Udp4Header Pointer to the udp header of the datagram causes
1546 this icmp error message.
1552 Udp4SendPortUnreach (
1554 IN EFI_NET_SESSION_DATA
*NetSession
,
1560 IP4_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1561 EFI_IP4_HEADER
*IpHdr
;
1563 IP_IO_OVERRIDE Override
;
1564 IP_IO_IP_INFO
*IpSender
;
1566 IpSender
= IpIoFindSender (&IpIo
, NetSession
->Dest
);
1567 if (IpSender
== NULL
) {
1569 // No apropriate sender, since we cannot send out the ICMP message through
1570 // the default zero station address IP instance, abort.
1575 IpHdr
= NetSession
->IpHdr
;
1578 // Calculate the requried length of the icmp error message.
1580 Len
= sizeof (IP4_ICMP_ERROR_HEAD
) + (EFI_IP4_HEADER_LEN (IpHdr
) -
1581 sizeof (IP4_HEAD
)) + ICMP_ERROR_PACKET_LENGTH
;
1584 // Allocate buffer for the icmp error message.
1586 Packet
= NetbufAlloc (Len
);
1587 if (Packet
== NULL
) {
1592 // Allocate space for the IP4_ICMP_ERROR_HEAD.
1594 IcmpErrHdr
= (IP4_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1597 // Set the required fields for the icmp port unreachable message.
1599 IcmpErrHdr
->Head
.Type
= ICMP_TYPE_UNREACH
;
1600 IcmpErrHdr
->Head
.Code
= ICMP_CODE_UNREACH_PORT
;
1601 IcmpErrHdr
->Head
.Checksum
= 0;
1602 IcmpErrHdr
->Fourth
= 0;
1605 // Copy the IP header of the datagram tragged the error.
1607 CopyMem (&IcmpErrHdr
->IpHead
, IpHdr
, EFI_IP4_HEADER_LEN (IpHdr
));
1610 // Copy the UDP header.
1612 Ptr
= (UINT8
*) &IcmpErrHdr
->IpHead
+ EFI_IP4_HEADER_LEN (IpHdr
);
1613 CopyMem (Ptr
, Udp4Header
, ICMP_ERROR_PACKET_LENGTH
);
1616 // Calculate the checksum.
1618 IcmpErrHdr
->Head
.Checksum
= (UINT16
) ~(NetbufChecksum (Packet
));
1621 // Fill the override data.
1623 Override
.DoNotFragment
= FALSE
;
1624 Override
.TypeOfService
= 0;
1625 Override
.TimeToLive
= 255;
1626 Override
.Protocol
= EFI_IP_PROTO_ICMP
;
1628 CopyMem (&Override
.SourceAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1629 ZeroMem (&Override
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
1632 // Send out this icmp packet.
1634 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, NetSession
->Source
, &Override
);
1636 NetbufFree (Packet
);
1641 This function handles the received Icmp Error message and demultiplexes it to the
1644 @param Udp4Service Pointer to the udp service context data.
1645 @param IcmpError The icmp error code.
1646 @param NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1647 from the received Icmp Error packet.
1648 @param Packet Pointer to the Icmp Error packet.
1655 IN UDP4_SERVICE_DATA
*Udp4Service
,
1656 IN ICMP_ERROR IcmpError
,
1657 IN EFI_NET_SESSION_DATA
*NetSession
,
1661 EFI_UDP4_HEADER
*Udp4Header
;
1662 EFI_UDP4_SESSION_DATA Udp4Session
;
1664 UDP4_INSTANCE_DATA
*Instance
;
1666 Udp4Header
= (EFI_UDP4_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1668 CopyMem (&Udp4Session
.SourceAddress
, &NetSession
->Source
, sizeof (EFI_IPv4_ADDRESS
));
1669 CopyMem (&Udp4Session
.DestinationAddress
, &NetSession
->Dest
, sizeof (EFI_IPv4_ADDRESS
));
1671 Udp4Session
.SourcePort
= NTOHS (Udp4Header
->DstPort
);
1672 Udp4Session
.DestinationPort
= NTOHS (Udp4Header
->SrcPort
);
1674 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1676 // Iterate all the instances.
1678 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP4_INSTANCE_DATA
, Link
);
1680 if (!Instance
->Configured
||
1681 Instance
->ConfigData
.AcceptPromiscuous
||
1682 Instance
->ConfigData
.AcceptAnyPort
||
1683 EFI_IP4_EQUAL (&Instance
->ConfigData
.StationAddress
, &mZeroIp4Addr
)) {
1685 // Don't try to deliver the ICMP error to this instance if it is not configured,
1686 // or it's configured to be promiscuous or accept any port or accept all the
1692 if (Udp4MatchDgram (Instance
, &Udp4Session
)) {
1694 // Translate the Icmp Error code according to the udp spec.
1696 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, NULL
, NULL
);
1698 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1699 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1703 // Notify the instance with the received Icmp Error.
1705 Udp4ReportIcmpError (Instance
);
1711 NetbufFree (Packet
);
1716 This function reports the received ICMP error.
1718 @param Instance Pointer to the udp instance context data.
1724 Udp4ReportIcmpError (
1725 IN UDP4_INSTANCE_DATA
*Instance
1728 EFI_UDP4_COMPLETION_TOKEN
*Token
;
1730 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1732 // There are no receive tokens to deliver the ICMP error.
1737 if (EFI_ERROR (Instance
->IcmpError
)) {
1739 // Try to get a RxToken from the RxTokens map.
1741 Token
= (EFI_UDP4_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1743 if (Token
!= NULL
) {
1745 // Report the error through the Token.
1747 Token
->Status
= Instance
->IcmpError
;
1748 gBS
->SignalEvent (Token
->Event
);
1751 // Clear the IcmpError.
1753 Instance
->IcmpError
= EFI_SUCCESS
;
1760 This function is a dummy ext-free function for the NET_BUF created for the output
1763 @param Context Pointer to the context data.
1769 Udp4NetVectorExtFree (
1777 Set the Udp4 variable data.
1779 @param Udp4Service Udp4 service data.
1781 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the
1783 @retval other Set variable failed.
1787 Udp4SetVariableData (
1788 IN UDP4_SERVICE_DATA
*Udp4Service
1791 UINT32 NumConfiguredInstance
;
1793 UINTN VariableDataSize
;
1794 EFI_UDP4_VARIABLE_DATA
*Udp4VariableData
;
1795 EFI_UDP4_SERVICE_POINT
*Udp4ServicePoint
;
1796 UDP4_INSTANCE_DATA
*Udp4Instance
;
1797 CHAR16
*NewMacString
;
1800 NumConfiguredInstance
= 0;
1803 // Go through the children list to count the configured children.
1805 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1806 Udp4Instance
= NET_LIST_USER_STRUCT_S (
1810 UDP4_INSTANCE_DATA_SIGNATURE
1813 if (Udp4Instance
->Configured
) {
1814 NumConfiguredInstance
++;
1819 // Calculate the size of the Udp4VariableData. As there may be no Udp4 child,
1820 // we should add extra buffer for the service points only if the number of configured
1821 // children is more than 1.
1823 VariableDataSize
= sizeof (EFI_UDP4_VARIABLE_DATA
);
1825 if (NumConfiguredInstance
> 1) {
1826 VariableDataSize
+= sizeof (EFI_UDP4_SERVICE_POINT
) * (NumConfiguredInstance
- 1);
1829 Udp4VariableData
= AllocatePool (VariableDataSize
);
1830 if (Udp4VariableData
== NULL
) {
1831 return EFI_OUT_OF_RESOURCES
;
1834 Udp4VariableData
->DriverHandle
= Udp4Service
->ImageHandle
;
1835 Udp4VariableData
->ServiceCount
= NumConfiguredInstance
;
1837 Udp4ServicePoint
= &Udp4VariableData
->Services
[0];
1840 // Go through the children list to fill the configured children's address pairs.
1842 NET_LIST_FOR_EACH (Entry
, &Udp4Service
->ChildrenList
) {
1843 Udp4Instance
= NET_LIST_USER_STRUCT_S (
1847 UDP4_INSTANCE_DATA_SIGNATURE
1850 if (Udp4Instance
->Configured
) {
1851 Udp4ServicePoint
->InstanceHandle
= Udp4Instance
->ChildHandle
;
1852 Udp4ServicePoint
->LocalAddress
= Udp4Instance
->ConfigData
.StationAddress
;
1853 Udp4ServicePoint
->LocalPort
= Udp4Instance
->ConfigData
.StationPort
;
1854 Udp4ServicePoint
->RemoteAddress
= Udp4Instance
->ConfigData
.RemoteAddress
;
1855 Udp4ServicePoint
->RemotePort
= Udp4Instance
->ConfigData
.RemotePort
;
1862 // Get the mac string.
1864 Status
= NetLibGetMacString (
1865 Udp4Service
->ControllerHandle
,
1866 Udp4Service
->ImageHandle
,
1869 if (EFI_ERROR (Status
)) {
1873 if (Udp4Service
->MacString
!= NULL
) {
1875 // The variable is set already, we're going to update it.
1877 if (StrCmp (Udp4Service
->MacString
, NewMacString
) != 0) {
1879 // The mac address is changed, delete the previous variable first.
1882 Udp4Service
->MacString
,
1883 &gEfiUdp4ServiceBindingProtocolGuid
,
1884 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1890 gBS
->FreePool (Udp4Service
->MacString
);
1893 Udp4Service
->MacString
= NewMacString
;
1895 Status
= gRT
->SetVariable (
1896 Udp4Service
->MacString
,
1897 &gEfiUdp4ServiceBindingProtocolGuid
,
1898 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1900 (VOID
*) Udp4VariableData
1905 gBS
->FreePool (Udp4VariableData
);
1912 Clear the variable and free the resource.
1914 @param Udp4Service Udp4 service data.
1920 Udp4ClearVariableData (
1921 IN UDP4_SERVICE_DATA
*Udp4Service
1924 ASSERT (Udp4Service
->MacString
!= NULL
);
1927 Udp4Service
->MacString
,
1928 &gEfiUdp4ServiceBindingProtocolGuid
,
1929 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1934 gBS
->FreePool (Udp4Service
->MacString
);
1935 Udp4Service
->MacString
= NULL
;