2 Udp6 driver's whole implementation.
4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UINT16 mUdp6RandomPort
;
21 This function checks and timeouts the I/O datagrams holding by the corresponding
24 @param[in] Event The event this function is registered to.
25 @param[in] Context The context data registered during the creation of
37 This function finds the udp instance by the specified <Address, Port> pair.
39 @param[in] InstanceList Pointer to the head of the list linking the udp
41 @param[in] Address Pointer to the specified IPv6 address.
42 @param[in] Port The udp port number.
44 @retval TRUE The specified <Address, Port> pair is found.
45 @retval FALSE Otherwise.
49 Udp6FindInstanceByPort (
50 IN LIST_ENTRY
*InstanceList
,
51 IN EFI_IPv6_ADDRESS
*Address
,
56 This function is the packet transmitting notify function registered to the IpIo
57 interface. It's called to signal the udp TxToken when the IpIo layer completes
58 transmitting of the udp datagram.
60 @param[in] Status The completion status of the output udp datagram.
61 @param[in] Context Pointer to the context data.
62 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
63 @param[in] NotifyData Pointer to the notify data.
71 IN IP_IO_IP_PROTOCOL Sender
,
76 This function processes the received datagram passed up by the IpIo layer.
78 @param[in] Status The status of this udp datagram.
79 @param[in] IcmpError The IcmpError code, only available when Status is
81 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
82 @param[in] Packet Pointer to the NET_BUF containing the received udp
84 @param[in] Context Pointer to the context data.
92 IN EFI_NET_SESSION_DATA
*NetSession
,
98 This function cancle the token specified by Arg in the Map.
100 @param[in] Map Pointer to the NET_MAP.
101 @param[in] Item Pointer to the NET_MAP_ITEM.
102 @param[in] Arg Pointer to the token to be cancelled, if NULL, all
103 the tokens in this Map will be cancelled.
104 This parameter is optional and may be NULL.
106 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
107 is not the same as that in the Item if Arg is not
109 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
117 IN NET_MAP_ITEM
*Item
,
118 IN VOID
*Arg OPTIONAL
122 This function check if the received udp datagram matches with the Instance.
124 @param[in] Instance Pointer to the udp instance context data.
125 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
126 from the received udp datagram.
128 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
129 @retval FALSE The udp datagram doe not match the receiving requirements of the Instance.
134 IN UDP6_INSTANCE_DATA
*Instance
,
135 IN EFI_UDP6_SESSION_DATA
*Udp6Session
139 This function removes the Wrap specified by Context and releases relevant resources.
141 @param[in] Event The Event this notify function is registered to.
142 @param[in] Context Pointer to the context data.
147 Udp6RecycleRxDataWrap (
153 This function wraps the Packet into RxData.
155 @param[in] Instance Pointer to the instance context data.
156 @param[in] Packet Pointer to the buffer containing the received
158 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
161 @return Pointer to the structure wrapping the RxData and the Packet.
166 IN UDP6_INSTANCE_DATA
*Instance
,
168 IN EFI_UDP6_RECEIVE_DATA
*RxData
172 This function enqueues the received datagram into the instances' receiving queues.
174 @param[in] Udp6Service Pointer to the udp service context data.
175 @param[in] Packet Pointer to the buffer containing the received
177 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
180 @return The times this datagram is enqueued.
185 IN UDP6_SERVICE_DATA
*Udp6Service
,
187 IN EFI_UDP6_RECEIVE_DATA
*RxData
191 This function delivers the datagrams enqueued in the instances.
193 @param[in] Udp6Service Pointer to the udp service context data.
198 IN UDP6_SERVICE_DATA
*Udp6Service
202 This function demultiplexes the received udp datagram to the apropriate instances.
204 @param[in] Udp6Service Pointer to the udp service context data.
205 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from
206 the received datagram.
207 @param[in] Packet Pointer to the buffer containing the received udp
213 IN UDP6_SERVICE_DATA
*Udp6Service
,
214 IN EFI_NET_SESSION_DATA
*NetSession
,
219 This function handles the received Icmp Error message and demultiplexes it to the
222 @param[in] Udp6Service Pointer to the udp service context data.
223 @param[in] IcmpError The icmp error code.
224 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
225 from the received Icmp Error packet.
226 @param[in, out] Packet Pointer to the Icmp Error packet.
231 IN UDP6_SERVICE_DATA
*Udp6Service
,
233 IN EFI_NET_SESSION_DATA
*NetSession
,
234 IN OUT NET_BUF
*Packet
238 This function builds and sends out a icmp port unreachable message.
240 @param[in] IpIo Pointer to the IP_IO instance.
241 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
242 causes this icmp error message.
243 @param[in] Udp6Header Pointer to the udp header of the datagram causes
244 this icmp error message.
248 Udp6SendPortUnreach (
250 IN EFI_NET_SESSION_DATA
*NetSession
,
255 Find the key in the netmap
257 @param[in] Map The netmap to search within.
258 @param[in] Key The key to search.
260 @return The point to the item contains the Key, or NULL if Key isn't in the map.
264 Udp6MapMultiCastAddr (
270 Create the Udp service context data.
272 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
273 @param[in] ImageHandle The image handle of this udp6 driver.
274 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
276 @retval EFI_SUCCESS The udp6 service context data was created and
278 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
279 @retval Others An error condition occurred.
284 IN UDP6_SERVICE_DATA
*Udp6Service
,
285 IN EFI_HANDLE ImageHandle
,
286 IN EFI_HANDLE ControllerHandle
290 IP_IO_OPEN_DATA OpenData
;
292 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
294 Udp6Service
->Signature
= UDP6_SERVICE_DATA_SIGNATURE
;
295 Udp6Service
->ServiceBinding
= mUdp6ServiceBinding
;
296 Udp6Service
->ImageHandle
= ImageHandle
;
297 Udp6Service
->ControllerHandle
= ControllerHandle
;
298 Udp6Service
->ChildrenNumber
= 0;
300 InitializeListHead (&Udp6Service
->ChildrenList
);
303 // Create the IpIo for this service context.
305 Udp6Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
, IP_VERSION_6
);
306 if (Udp6Service
->IpIo
== NULL
) {
307 return EFI_OUT_OF_RESOURCES
;
311 // Set the OpenData used to open the IpIo.
314 &OpenData
.IpConfigData
.Ip6CfgData
,
315 &mIp6IoDefaultIpConfigData
,
316 sizeof (EFI_IP6_CONFIG_DATA
)
318 OpenData
.RcvdContext
= (VOID
*) Udp6Service
;
319 OpenData
.SndContext
= NULL
;
320 OpenData
.PktRcvdNotify
= Udp6DgramRcvd
;
321 OpenData
.PktSentNotify
= Udp6DgramSent
;
324 // Configure and start the IpIo.
326 Status
= IpIoOpen (Udp6Service
->IpIo
, &OpenData
);
327 if (EFI_ERROR (Status
)) {
332 // Create the event for Udp timeout checking.
334 Status
= gBS
->CreateEvent (
335 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
339 &Udp6Service
->TimeoutEvent
341 if (EFI_ERROR (Status
)) {
346 // Start the timeout timer event.
348 Status
= gBS
->SetTimer (
349 Udp6Service
->TimeoutEvent
,
351 UDP6_TIMEOUT_INTERVAL
353 if (EFI_ERROR (Status
)) {
361 if (Udp6Service
->TimeoutEvent
!= NULL
) {
362 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
365 IpIoDestroy (Udp6Service
->IpIo
);
366 Udp6Service
->IpIo
= NULL
;
373 Clean the Udp service context data.
375 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
380 IN OUT UDP6_SERVICE_DATA
*Udp6Service
384 // Close the TimeoutEvent timer.
386 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
391 IpIoDestroy (Udp6Service
->IpIo
);
392 Udp6Service
->IpIo
= NULL
;
394 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
399 This function checks and times out the I/O datagrams listed in the
400 UDP6_SERVICE_DATA which is specified by the input parameter Context.
403 @param[in] Event The event this function registered to.
404 @param[in] Context The context data registered during the creation of
415 UDP6_SERVICE_DATA
*Udp6Service
;
417 UDP6_INSTANCE_DATA
*Instance
;
418 LIST_ENTRY
*WrapEntry
;
419 LIST_ENTRY
*NextEntry
;
420 UDP6_RXDATA_WRAP
*Wrap
;
422 Udp6Service
= (UDP6_SERVICE_DATA
*) Context
;
423 NET_CHECK_SIGNATURE (Udp6Service
, UDP6_SERVICE_DATA_SIGNATURE
);
425 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
427 // Iterate all the instances belonging to this service context.
429 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
430 NET_CHECK_SIGNATURE (Instance
, UDP6_INSTANCE_DATA_SIGNATURE
);
432 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
434 // Skip this instance if it's not configured or no receive timeout.
439 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
441 // Iterate all the rxdatas belonging to this udp instance.
443 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP6_RXDATA_WRAP
, Link
);
445 if (Wrap
->TimeoutTick
< UDP6_TIMEOUT_INTERVAL
/ 10) {
447 // Remove this RxData if it timeouts.
449 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
451 Wrap
->TimeoutTick
-= UDP6_TIMEOUT_INTERVAL
/ 10;
459 This function intializes the new created udp instance.
461 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
462 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
467 IN UDP6_SERVICE_DATA
*Udp6Service
,
468 IN OUT UDP6_INSTANCE_DATA
*Instance
472 // Set the signature.
474 Instance
->Signature
= UDP6_INSTANCE_DATA_SIGNATURE
;
479 InitializeListHead (&Instance
->Link
);
480 InitializeListHead (&Instance
->RcvdDgramQue
);
481 InitializeListHead (&Instance
->DeliveredDgramQue
);
484 // Init the NET_MAPs.
486 NetMapInit (&Instance
->TxTokens
);
487 NetMapInit (&Instance
->RxTokens
);
488 NetMapInit (&Instance
->McastIps
);
491 // Save the pointer to the UDP6_SERVICE_DATA, and initialize other members.
493 Instance
->Udp6Service
= Udp6Service
;
494 CopyMem (&Instance
->Udp6Proto
, &mUdp6Protocol
, sizeof (EFI_UDP6_PROTOCOL
));
495 Instance
->IcmpError
= EFI_SUCCESS
;
496 Instance
->Configured
= FALSE
;
497 Instance
->IsNoMapping
= FALSE
;
498 Instance
->InDestroy
= FALSE
;
503 This function cleans the udp instance.
505 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
510 IN OUT UDP6_INSTANCE_DATA
*Instance
513 NetMapClean (&Instance
->McastIps
);
514 NetMapClean (&Instance
->RxTokens
);
515 NetMapClean (&Instance
->TxTokens
);
520 This function finds the udp instance by the specified <Address, Port> pair.
522 @param[in] InstanceList Pointer to the head of the list linking the udp
524 @param[in] Address Pointer to the specified IPv6 address.
525 @param[in] Port The udp port number.
527 @retval TRUE The specified <Address, Port> pair is found.
528 @retval FALSE Otherwise.
532 Udp6FindInstanceByPort (
533 IN LIST_ENTRY
*InstanceList
,
534 IN EFI_IPv6_ADDRESS
*Address
,
539 UDP6_INSTANCE_DATA
*Instance
;
540 EFI_UDP6_CONFIG_DATA
*ConfigData
;
542 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
544 // Iterate all the udp instances.
546 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
547 ConfigData
= &Instance
->ConfigData
;
549 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
551 // If the instance is not configured, or the configdata of the instance indicates
552 // this instance accepts any port, skip it.
557 if (EFI_IP6_EQUAL (&ConfigData
->StationAddress
, Address
) &&
558 (ConfigData
->StationPort
== Port
)
561 // If both the address and the port are the same, return TRUE.
568 // Return FALSE when matching fails.
575 This function tries to bind the udp instance according to the configured port
578 @param[in] InstanceList Pointer to the head of the list linking the udp
580 @param[in] ConfigData Pointer to the ConfigData of the instance to be
583 @retval EFI_SUCCESS The bound operation completed successfully.
584 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
585 already used by other instance.
586 @retval EFI_OUT_OF_RESOURCES No available port resources.
591 IN LIST_ENTRY
*InstanceList
,
592 IN EFI_UDP6_CONFIG_DATA
*ConfigData
595 EFI_IPv6_ADDRESS
*StationAddress
;
598 if (ConfigData
->AcceptAnyPort
) {
602 StationAddress
= &ConfigData
->StationAddress
;
604 if (ConfigData
->StationPort
!= 0) {
606 if (!ConfigData
->AllowDuplicatePort
&&
607 Udp6FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)
610 // Do not allow duplicate ports and the port is already used by other instance.
612 return EFI_ACCESS_DENIED
;
616 // Select a random port for this instance.
618 if (ConfigData
->AllowDuplicatePort
) {
620 // Just pick up the random port if the instance allows duplicate port.
622 ConfigData
->StationPort
= mUdp6RandomPort
;
625 StartPort
= mUdp6RandomPort
;
627 while (Udp6FindInstanceByPort (InstanceList
, StationAddress
, mUdp6RandomPort
)) {
630 if (mUdp6RandomPort
== 0) {
631 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
634 if (mUdp6RandomPort
== StartPort
) {
636 // No available port.
638 return EFI_OUT_OF_RESOURCES
;
642 ConfigData
->StationPort
= mUdp6RandomPort
;
646 if (mUdp6RandomPort
== 0) {
647 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
655 This function is used to check whether the NewConfigData has any un-reconfigurable
656 parameters changed compared to the OldConfigData.
658 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
660 @param[in] NewConfigData Pointer to the new ConfigData.
662 @retval TRUE The instance is reconfigurable according to the NewConfigData.
663 @retval FALSE Otherwise.
667 Udp6IsReconfigurable (
668 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
669 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
672 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
673 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
674 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)
677 // The receiving filter parameters cannot be changed.
682 if ((!NewConfigData
->AcceptAnyPort
) &&
683 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)
686 // The port is not changeable.
691 if (!EFI_IP6_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
)) {
693 // The StationAddress is not the same.
699 if (!EFI_IP6_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
701 // The remoteaddress is not the same.
706 if (!NetIp6IsUnspecifiedAddr (&NewConfigData
->RemoteAddress
) &&
707 (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)
710 // The RemotePort differs if it's designated in the configdata.
716 // All checks pass, return TRUE.
723 This function builds the Ip6 configdata from the Udp6ConfigData.
725 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
726 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
730 Udp6BuildIp6ConfigData (
731 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
732 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
737 &mIp6IoDefaultIpConfigData
,
738 sizeof (EFI_IP6_CONFIG_DATA
)
740 Ip6ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
741 Ip6ConfigData
->AcceptPromiscuous
= Udp6ConfigData
->AcceptPromiscuous
;
742 IP6_COPY_ADDRESS (&Ip6ConfigData
->StationAddress
, &Udp6ConfigData
->StationAddress
);
743 IP6_COPY_ADDRESS (&Ip6ConfigData
->DestinationAddress
, &Udp6ConfigData
->RemoteAddress
);
745 // Use the -1 magic number to disable the receiving process of the ip instance.
747 Ip6ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
752 This function validates the TxToken. It returns the error code according to the spec.
754 @param[in] Instance Pointer to the udp instance context data.
755 @param[in] TxToken Pointer to the token to be checked.
757 @retval EFI_SUCCESS The TxToken is valid.
758 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
760 Token.Packet.TxData is NULL;
761 Token.Packet.TxData.FragmentCount is zero;
762 Token.Packet.TxData.DataLength is not equal to the
763 sum of fragment lengths;
765 Token.Packet.TxData.FragmentTable[].FragmentLength
768 Token.Packet.TxData.FragmentTable[].FragmentBuffer
770 UdpSessionData.DestinationAddress are not valid
771 unicast IPv6 addresses if the UdpSessionData is
773 UdpSessionData.DestinationPort and
774 ConfigData.RemotePort are all zero if the
775 UdpSessionData is not NULL.
776 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
781 Udp6ValidateTxToken (
782 IN UDP6_INSTANCE_DATA
*Instance
,
783 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
786 EFI_UDP6_TRANSMIT_DATA
*TxData
;
789 EFI_UDP6_CONFIG_DATA
*ConfigData
;
790 EFI_UDP6_SESSION_DATA
*UdpSessionData
;
793 if (TxToken
->Event
== NULL
) {
794 return EFI_INVALID_PARAMETER
;
797 TxData
= TxToken
->Packet
.TxData
;
799 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
800 return EFI_INVALID_PARAMETER
;
804 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
806 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
807 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)
810 // If the FragmentBuffer is NULL, or the FragmentLeng is zero.
812 return EFI_INVALID_PARAMETER
;
815 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
818 if (TotalLen
!= TxData
->DataLength
) {
820 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
823 return EFI_INVALID_PARAMETER
;
826 ConfigData
= &Instance
->ConfigData
;
827 UdpSessionData
= TxData
->UdpSessionData
;
829 if (UdpSessionData
!= NULL
) {
831 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
833 // Ambiguous; no avalaible DestinationPort for this token.
835 return EFI_INVALID_PARAMETER
;
838 if (NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
839 NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
842 // The DestinationAddress is not specificed.
844 return EFI_INVALID_PARAMETER
;
847 if (!NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
848 !NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
851 // The ConfigData.RemoteAddress is not zero and the UdpSessionData.DestinationAddress
854 return EFI_INVALID_PARAMETER
;
856 } else if (NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)) {
858 // The configured RemoteAddress is all zero, and the user doesn't override the
859 // destination address.
861 return EFI_INVALID_PARAMETER
;
864 if (TxData
->DataLength
> UDP6_MAX_DATA_SIZE
) {
865 return EFI_BAD_BUFFER_SIZE
;
873 This function checks whether the specified Token duplicates the one in the Map.
875 @param[in] Map Pointer to the NET_MAP.
876 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
878 @param[in] Context Pointer to the Token to be checked.
880 @retval EFI_SUCCESS The Token specified by Context differs from the
882 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
889 IN NET_MAP_ITEM
*Item
,
893 EFI_UDP6_COMPLETION_TOKEN
*Token
;
894 EFI_UDP6_COMPLETION_TOKEN
*TokenInItem
;
896 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) Context
;
897 TokenInItem
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
899 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
901 // The Token duplicates with the TokenInItem in case either the two pointers are the
902 // same, or the Events of these two tokens are the same.
904 return EFI_ACCESS_DENIED
;
912 This function calculates the checksum for the Packet, utilizing the pre-calculated
913 pseudo HeadSum to reduce some overhead.
915 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
916 @param[in] HeadSum Checksum of the pseudo header, execpt the length
919 @return The 16-bit checksum of this udp datagram.
930 Checksum
= NetbufChecksum (Packet
);
931 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
933 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
934 Checksum
= (UINT16
) (~Checksum
);
940 This function removes the specified Token from the TokenMap.
942 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
943 @param[in] Token Pointer to the Token to be removed.
945 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
946 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
951 IN NET_MAP
*TokenMap
,
952 IN EFI_UDP6_COMPLETION_TOKEN
*Token
958 // Find the Token first.
960 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
964 // Remove the token if it's found in the map.
966 NetMapRemoveItem (TokenMap
, Item
, NULL
);
970 return EFI_NOT_FOUND
;
975 This function is the packet transmitting notify function registered to the IpIo
976 interface. It's called to signal the udp TxToken when IpIo layer completes the
977 transmitting of the udp datagram.
979 @param[in] Status The completion status of the output udp datagram.
980 @param[in] Context Pointer to the context data.
981 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
982 @param[in] NotifyData Pointer to the notify data.
988 IN EFI_STATUS Status
,
990 IN IP_IO_IP_PROTOCOL Sender
,
994 UDP6_INSTANCE_DATA
*Instance
;
995 EFI_UDP6_COMPLETION_TOKEN
*Token
;
997 Instance
= (UDP6_INSTANCE_DATA
*) Context
;
998 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NotifyData
;
1000 if (Udp6RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
1002 // The token may be cancelled. Only signal it if the remove operation succeeds.
1004 Token
->Status
= Status
;
1005 gBS
->SignalEvent (Token
->Event
);
1012 This function processes the received datagram passed up by the IpIo layer.
1014 @param[in] Status The status of this udp datagram.
1015 @param[in] IcmpError The IcmpError code, only available when Status is
1017 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
1018 @param[in] Packet Pointer to the NET_BUF containing the received udp
1020 @param[in] Context Pointer to the context data.
1026 IN EFI_STATUS Status
,
1028 IN EFI_NET_SESSION_DATA
*NetSession
,
1033 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
1036 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
1038 if (Status
== EFI_SUCCESS
) {
1041 // Demultiplex the received datagram.
1043 Udp6Demultiplex ((UDP6_SERVICE_DATA
*) Context
, NetSession
, Packet
);
1046 // Handle the ICMP6 Error packet.
1048 Udp6IcmpHandler ((UDP6_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
1052 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
1053 // that are signaled with received data.
1060 This function removes the multicast group specified by Arg from the Map.
1062 @param[in] Map Pointer to the NET_MAP.
1063 @param[in] Item Pointer to the NET_MAP_ITEM.
1064 @param[in] Arg Pointer to the Arg, it's the pointer to a
1065 multicast IPv6 Address. This parameter is
1066 optional and may be NULL.
1068 @retval EFI_SUCCESS The multicast address is removed.
1069 @retval EFI_ABORTED The specified multicast address is removed, and the
1077 IN NET_MAP_ITEM
*Item
,
1078 IN VOID
*Arg OPTIONAL
1081 EFI_IPv6_ADDRESS
*McastIp
;
1085 if ((McastIp
!= NULL
) &&
1086 !EFI_IP6_EQUAL (McastIp
, ((EFI_IPv6_ADDRESS
*)Item
->Key
))
1089 // McastIp is not NULL and the multicast address contained in the Item
1090 // is not the same as McastIp.
1095 FreePool (Item
->Key
);
1098 // Remove this Item.
1100 NetMapRemoveItem (Map
, Item
, NULL
);
1102 if (McastIp
!= NULL
) {
1104 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
1114 This function cancle the token specified by Arg in the Map.
1116 @param[in] Map Pointer to the NET_MAP.
1117 @param[in] Item Pointer to the NET_MAP_ITEM.
1118 @param[in] Arg Pointer to the token to be cancelled. If NULL, all
1119 the tokens in this Map will be cancelled.
1120 This parameter is optional and may be NULL.
1122 @retval EFI_SUCCESS The token is cancelled if Arg is NULL, or the token
1123 is not the same as that in the Item, if Arg is not
1125 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1133 IN NET_MAP_ITEM
*Item
,
1134 IN VOID
*Arg OPTIONAL
1137 EFI_UDP6_COMPLETION_TOKEN
*TokenToCancel
;
1141 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1145 if (Item
->Value
!= NULL
) {
1147 // If the token is a transmit token, the corresponding Packet is recorded in
1148 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1149 // will invoke Udp6DgramSent, the token will be signaled and this Item will
1150 // be removed from the Map there.
1152 Packet
= (NET_BUF
*) (Item
->Value
);
1153 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1155 IpIoCancelTxToken (IpIo
, Packet
);
1158 // The token is a receive token. Abort it and remove it from the Map.
1160 TokenToCancel
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
1161 NetMapRemoveItem (Map
, Item
, NULL
);
1163 TokenToCancel
->Status
= EFI_ABORTED
;
1164 gBS
->SignalEvent (TokenToCancel
->Event
);
1176 This function removes all the Wrap datas in the RcvdDgramQue.
1178 @param[in] Instance Pointer to the Udp6 Instance.
1182 Udp6FlushRcvdDgram (
1183 IN UDP6_INSTANCE_DATA
*Instance
1186 UDP6_RXDATA_WRAP
*Wrap
;
1188 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1190 // Iterate all the Wraps in the RcvdDgramQue.
1192 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1195 // The Wrap will be removed from the RcvdDgramQue by this function call.
1197 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1204 Cancel Udp6 tokens from the Udp6 instance.
1206 @param[in] Instance Pointer to the udp instance context data.
1207 @param[in] Token Pointer to the token to be canceled. If NULL, all
1208 tokens in this instance will be cancelled.
1209 This parameter is optional and may be NULL.
1211 @retval EFI_SUCCESS The Token is cancelled.
1212 @retval EFI_NOT_FOUND The Token is not found.
1216 Udp6InstanceCancelToken (
1217 IN UDP6_INSTANCE_DATA
*Instance
,
1218 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
1224 // Cancel this token from the TxTokens map.
1226 Status
= NetMapIterate (&Instance
->TxTokens
, Udp6CancelTokens
, Token
);
1228 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1230 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1231 // the TxTokens and returns success.
1237 // Try to cancel this token from the RxTokens map in condition either the Token
1238 // is NULL or the specified Token is not in TxTokens.
1240 Status
= NetMapIterate (&Instance
->RxTokens
, Udp6CancelTokens
, Token
);
1242 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1244 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1245 // TxTokens nor the RxTokens, or say, it's not found.
1247 return EFI_NOT_FOUND
;
1250 ASSERT ((Token
!= NULL
) ||
1251 ((0 == NetMapGetCount (&Instance
->TxTokens
)) &&
1252 (0 == NetMapGetCount (&Instance
->RxTokens
)))
1260 This function checks if the received udp datagram matches with the Instance.
1262 @param[in] Instance Pointer to the udp instance context data.
1263 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
1264 from the received udp datagram.
1266 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
1267 @retval FALSE The udp datagram does not matche the receiving requirements of the Instance.
1272 IN UDP6_INSTANCE_DATA
*Instance
,
1273 IN EFI_UDP6_SESSION_DATA
*Udp6Session
1276 EFI_UDP6_CONFIG_DATA
*ConfigData
;
1277 EFI_IPv6_ADDRESS Destination
;
1279 ConfigData
= &Instance
->ConfigData
;
1281 if (ConfigData
->AcceptPromiscuous
) {
1283 // Always matches if this instance is in the promiscuous state.
1288 if ((!ConfigData
->AcceptAnyPort
&& (Udp6Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1289 ((ConfigData
->RemotePort
!= 0) && (Udp6Session
->SourcePort
!= ConfigData
->RemotePort
))
1292 // The local port or the remote port doesn't match.
1297 if (!NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
) &&
1298 !EFI_IP6_EQUAL (&ConfigData
->RemoteAddress
, &Udp6Session
->SourceAddress
)
1301 // This datagram doesn't come from the instance's specified sender.
1306 if (NetIp6IsUnspecifiedAddr (&ConfigData
->StationAddress
) ||
1307 EFI_IP6_EQUAL (&Udp6Session
->DestinationAddress
, &ConfigData
->StationAddress
)
1310 // The instance is configured to receive datagrams destinated to any station IP or
1311 // the destination address of this datagram matches the configured station IP.
1316 IP6_COPY_ADDRESS (&Destination
, &Udp6Session
->DestinationAddress
);
1318 if (IP6_IS_MULTICAST (&Destination
) &&
1319 (NULL
!= Udp6MapMultiCastAddr (&Instance
->McastIps
, &Destination
))
1322 // It's a multicast packet and the multicast address is accepted by this instance.
1332 This function removes the Wrap specified by Context and release relevant resources.
1334 @param[in] Event The Event this notify function registered to.
1335 @param[in] Context Pointer to the context data.
1340 Udp6RecycleRxDataWrap (
1345 UDP6_RXDATA_WRAP
*Wrap
;
1347 Wrap
= (UDP6_RXDATA_WRAP
*) Context
;
1350 // Remove the Wrap from the list it belongs to.
1352 RemoveEntryList (&Wrap
->Link
);
1355 // Free the Packet associated with this Wrap.
1357 NetbufFree (Wrap
->Packet
);
1362 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1369 This function wraps the Packet into RxData.
1371 @param[in] Instance Pointer to the instance context data.
1372 @param[in] Packet Pointer to the buffer containing the received
1374 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1377 @return Pointer to the structure wrapping the RxData and the Packet.
1382 IN UDP6_INSTANCE_DATA
*Instance
,
1384 IN EFI_UDP6_RECEIVE_DATA
*RxData
1388 UDP6_RXDATA_WRAP
*Wrap
;
1391 // Allocate buffer for the Wrap.
1393 Wrap
= AllocateZeroPool (sizeof (UDP6_RXDATA_WRAP
) +
1394 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP6_FRAGMENT_DATA
));
1399 InitializeListHead (&Wrap
->Link
);
1401 CopyMem (&Wrap
->RxData
, RxData
, sizeof(EFI_UDP6_RECEIVE_DATA
));
1403 // Create the Recycle event.
1405 Status
= gBS
->CreateEvent (
1408 Udp6RecycleRxDataWrap
,
1410 &Wrap
->RxData
.RecycleSignal
1412 if (EFI_ERROR (Status
)) {
1417 Wrap
->Packet
= Packet
;
1418 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1425 This function enqueues the received datagram into the instances' receiving queues.
1427 @param[in] Udp6Service Pointer to the udp service context data.
1428 @param[in] Packet Pointer to the buffer containing the received
1430 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1433 @return The times this datagram is enqueued.
1438 IN UDP6_SERVICE_DATA
*Udp6Service
,
1440 IN EFI_UDP6_RECEIVE_DATA
*RxData
1444 UDP6_INSTANCE_DATA
*Instance
;
1445 UDP6_RXDATA_WRAP
*Wrap
;
1450 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1452 // Iterate the instances.
1454 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1456 if (!Instance
->Configured
) {
1460 if (Udp6MatchDgram (Instance
, &RxData
->UdpSession
)) {
1462 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1464 Wrap
= Udp6WrapRxData (Instance
, Packet
, RxData
);
1469 NET_GET_REF (Packet
);
1471 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1482 This function delivers the received datagrams to the specified instance.
1484 @param[in] Instance Pointer to the instance context data.
1488 Udp6InstanceDeliverDgram (
1489 IN UDP6_INSTANCE_DATA
*Instance
1492 UDP6_RXDATA_WRAP
*Wrap
;
1493 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1495 EFI_UDP6_RECEIVE_DATA
*RxData
;
1498 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1499 !NetMapIsEmpty (&Instance
->RxTokens
)
1502 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1504 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1506 // Duplicate the Packet if it is shared between instances.
1508 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1513 NetbufFree (Wrap
->Packet
);
1518 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1520 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1523 // Build the FragmentTable and set the FragmentCount in RxData.
1525 RxData
= &Wrap
->RxData
;
1526 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1530 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1531 &RxData
->FragmentCount
1534 Token
->Status
= EFI_SUCCESS
;
1535 Token
->Packet
.RxData
= &Wrap
->RxData
;
1537 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1538 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1539 gBS
->RestoreTPL (OldTpl
);
1541 gBS
->SignalEvent (Token
->Event
);
1547 This function delivers the datagrams enqueued in the instances.
1549 @param[in] Udp6Service Pointer to the udp service context data.
1554 IN UDP6_SERVICE_DATA
*Udp6Service
1558 UDP6_INSTANCE_DATA
*Instance
;
1560 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1562 // Iterate the instances.
1564 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1566 if (!Instance
->Configured
) {
1571 // Deliver the datagrams of this instance.
1573 Udp6InstanceDeliverDgram (Instance
);
1579 This function demultiplexes the received udp datagram to the appropriate instances.
1581 @param[in] Udp6Service Pointer to the udp service context data.
1582 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from
1583 the received datagram.
1584 @param[in] Packet Pointer to the buffer containing the received udp
1590 IN UDP6_SERVICE_DATA
*Udp6Service
,
1591 IN EFI_NET_SESSION_DATA
*NetSession
,
1595 EFI_UDP_HEADER
*Udp6Header
;
1597 EFI_UDP6_RECEIVE_DATA RxData
;
1598 EFI_UDP6_SESSION_DATA
*Udp6Session
;
1602 // Get the datagram header from the packet buffer.
1604 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1605 ASSERT (Udp6Header
!= NULL
);
1607 if (Udp6Header
->Checksum
!= 0) {
1609 // check the checksum.
1611 HeadSum
= NetIp6PseudoHeadChecksum (
1612 &NetSession
->Source
.v6
,
1613 &NetSession
->Dest
.v6
,
1618 if (Udp6Checksum (Packet
, HeadSum
) != 0) {
1626 gRT
->GetTime (&RxData
.TimeStamp
, NULL
);
1628 Udp6Session
= &RxData
.UdpSession
;
1629 Udp6Session
->SourcePort
= NTOHS (Udp6Header
->SrcPort
);
1630 Udp6Session
->DestinationPort
= NTOHS (Udp6Header
->DstPort
);
1632 IP6_COPY_ADDRESS (&Udp6Session
->SourceAddress
, &NetSession
->Source
);
1633 IP6_COPY_ADDRESS (&Udp6Session
->DestinationAddress
, &NetSession
->Dest
);
1636 // Trim the UDP header.
1638 NetbufTrim (Packet
, UDP6_HEADER_SIZE
, TRUE
);
1640 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1643 // Try to enqueue this datagram into the instances.
1645 Enqueued
= Udp6EnqueueDgram (Udp6Service
, Packet
, &RxData
);
1647 if (Enqueued
== 0) {
1649 // Send the port unreachable ICMP packet before we free this NET_BUF
1651 Udp6SendPortUnreach (Udp6Service
->IpIo
, NetSession
, Udp6Header
);
1655 // Try to free the packet before deliver it.
1657 NetbufFree (Packet
);
1661 // Deliver the datagram.
1663 Udp6DeliverDgram (Udp6Service
);
1669 This function builds and sends out a icmp port unreachable message.
1671 @param[in] IpIo Pointer to the IP_IO instance.
1672 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1673 causes this icmp error message.
1674 @param[in] Udp6Header Pointer to the udp header of the datagram causes
1675 this icmp error message.
1679 Udp6SendPortUnreach (
1681 IN EFI_NET_SESSION_DATA
*NetSession
,
1687 IP6_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1689 IP_IO_OVERRIDE Override
;
1690 IP_IO_IP_INFO
*IpSender
;
1691 EFI_IP6_MODE_DATA
*Ip6ModeData
;
1693 EFI_IP6_PROTOCOL
*Ip6Protocol
;
1698 // An ICMPv6 error message MUST NOT be originated as A packet destined to
1699 // 1) an IPv6 multicast address 2) The IPv6 Unspecified Address
1701 if (NetSession
->IpVersion
== IP_VERSION_6
) {
1702 if (NetIp6IsUnspecifiedAddr (&NetSession
->Dest
.v6
) ||
1703 IP6_IS_MULTICAST (&NetSession
->Dest
.v6
)
1710 IpSender
= IpIoFindSender (&IpIo
, NetSession
->IpVersion
, &NetSession
->Dest
);
1713 // Get the Ipv6 Mode Data.
1715 Ip6ModeData
= AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA
));
1716 ASSERT (Ip6ModeData
!= NULL
);
1719 // If not finding the related IpSender use the default IpIo to send out
1720 // the port unreachable ICMP message.
1722 if (IpSender
== NULL
) {
1723 Ip6Protocol
= IpIo
->Ip
.Ip6
;
1725 Ip6Protocol
= IpSender
->Ip
.Ip6
;
1728 Status
= Ip6Protocol
->GetModeData (
1735 if (EFI_ERROR (Status
)) {
1739 // The ICMP6 packet length, includes whole invoking packet and ICMP6 error header.
1741 Len
= NetSession
->IpHdrLen
+
1742 NTOHS(((EFI_UDP_HEADER
*) Udp6Header
)->Length
) +
1743 sizeof (IP6_ICMP_ERROR_HEAD
);
1746 // If the ICMP6 packet length larger than IP MTU, adjust its length to MTU.
1748 if (Ip6ModeData
->MaxPacketSize
< Len
) {
1749 Len
= Ip6ModeData
->MaxPacketSize
;
1753 // Allocate buffer for the icmp error message.
1755 Packet
= NetbufAlloc (Len
);
1756 if (Packet
== NULL
) {
1761 // Allocate space for the IP6_ICMP_ERROR_HEAD.
1763 IcmpErrHdr
= (IP6_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1764 ASSERT (IcmpErrHdr
!= NULL
);
1767 // Set the required fields for the icmp port unreachable message.
1769 IcmpErrHdr
->Head
.Type
= ICMP_V6_DEST_UNREACHABLE
;
1770 IcmpErrHdr
->Head
.Code
= ICMP_V6_PORT_UNREACHABLE
;
1771 IcmpErrHdr
->Head
.Checksum
= 0;
1772 IcmpErrHdr
->Fourth
= 0;
1775 // Copy as much of invoking Packet as possible without the ICMPv6 packet
1776 // exceeding the minimum Ipv6 MTU. The length of IP6_ICMP_ERROR_HEAD contains
1777 // the length of EFI_IP6_HEADER, so when using the length of IP6_ICMP_ERROR_HEAD
1778 // for pointer movement that fact should be considered.
1780 Ptr
= (VOID
*) &IcmpErrHdr
->Head
;
1781 Ptr
= (UINT8
*) (UINTN
) ((UINTN
) Ptr
+ sizeof (IP6_ICMP_ERROR_HEAD
) - sizeof (EFI_IP6_HEADER
));
1782 CopyMem (Ptr
, NetSession
->IpHdr
.Ip6Hdr
, NetSession
->IpHdrLen
);
1784 Ptr
+ NetSession
->IpHdrLen
,
1786 Len
- NetSession
->IpHdrLen
- sizeof (IP6_ICMP_ERROR_HEAD
) + sizeof (EFI_IP6_HEADER
)
1790 // Set the checksum as zero, and IP6 driver will calcuate it with pseudo header.
1792 IcmpErrHdr
->Head
.Checksum
= 0;
1795 // Fill the override data.
1797 Override
.Ip6OverrideData
.FlowLabel
= 0;
1798 Override
.Ip6OverrideData
.HopLimit
= 255;
1799 Override
.Ip6OverrideData
.Protocol
= IP6_ICMP
;
1802 // Send out this icmp packet.
1804 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, &NetSession
->Source
, &Override
);
1806 NetbufFree (Packet
);
1809 if (Ip6ModeData
!= NULL
) {
1810 FreePool (Ip6ModeData
);
1816 This function handles the received Icmp Error message and de-multiplexes it to the
1819 @param[in] Udp6Service Pointer to the udp service context data.
1820 @param[in] IcmpError The icmp error code.
1821 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1822 from the received Icmp Error packet.
1823 @param[in, out] Packet Pointer to the Icmp Error packet.
1828 IN UDP6_SERVICE_DATA
*Udp6Service
,
1830 IN EFI_NET_SESSION_DATA
*NetSession
,
1831 IN OUT NET_BUF
*Packet
1834 EFI_UDP_HEADER
*Udp6Header
;
1835 EFI_UDP6_SESSION_DATA Udp6Session
;
1837 UDP6_INSTANCE_DATA
*Instance
;
1839 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1840 ASSERT (Udp6Header
!= NULL
);
1842 IP6_COPY_ADDRESS (&Udp6Session
.SourceAddress
, &NetSession
->Source
);
1843 IP6_COPY_ADDRESS (&Udp6Session
.DestinationAddress
, &NetSession
->Dest
);
1845 Udp6Session
.SourcePort
= NTOHS (Udp6Header
->DstPort
);
1846 Udp6Session
.DestinationPort
= NTOHS (Udp6Header
->SrcPort
);
1848 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1850 // Iterate all the instances.
1852 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1854 if (!Instance
->Configured
) {
1858 if (Udp6MatchDgram (Instance
, &Udp6Session
)) {
1860 // Translate the Icmp Error code according to the udp spec.
1862 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, IP_VERSION_6
, NULL
, NULL
);
1864 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1865 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1869 // Notify the instance with the received Icmp Error.
1871 Udp6ReportIcmpError (Instance
);
1877 NetbufFree (Packet
);
1882 This function reports the received ICMP error.
1884 @param[in] Instance Pointer to the udp instance context data.
1888 Udp6ReportIcmpError (
1889 IN UDP6_INSTANCE_DATA
*Instance
1892 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1894 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1896 // There are no receive tokens to deliver the ICMP error.
1901 if (EFI_ERROR (Instance
->IcmpError
)) {
1903 // Try to get a RxToken from the RxTokens map.
1905 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1907 if (Token
!= NULL
) {
1909 // Report the error through the Token.
1911 Token
->Status
= Instance
->IcmpError
;
1912 gBS
->SignalEvent (Token
->Event
);
1915 // Clear the IcmpError.
1917 Instance
->IcmpError
= EFI_SUCCESS
;
1924 This function is a dummy ext-free function for the NET_BUF created for the output
1927 @param[in] Context Pointer to the context data.
1932 Udp6NetVectorExtFree (
1940 Set the Udp6 variable data.
1942 @param[in] Udp6Service Udp6 service data.
1944 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the
1946 @retval other Set variable failed.
1950 Udp6SetVariableData (
1951 IN UDP6_SERVICE_DATA
*Udp6Service
1954 UINT32 NumConfiguredInstance
;
1956 UINTN VariableDataSize
;
1957 EFI_UDP6_VARIABLE_DATA
*Udp6VariableData
;
1958 EFI_UDP6_SERVICE_POINT
*Udp6ServicePoint
;
1959 UDP6_INSTANCE_DATA
*Udp6Instance
;
1960 CHAR16
*NewMacString
;
1963 NumConfiguredInstance
= 0;
1966 // Go through the children list to count the configured children.
1968 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1969 Udp6Instance
= NET_LIST_USER_STRUCT_S (
1973 UDP6_INSTANCE_DATA_SIGNATURE
1976 if (Udp6Instance
->Configured
) {
1977 NumConfiguredInstance
++;
1982 // Calculate the size of the Udp6VariableData. As there may be no Udp6 child,
1983 // we should add extra buffer for the service points only if the number of configured
1984 // children is more than 1.
1986 VariableDataSize
= sizeof (EFI_UDP6_VARIABLE_DATA
);
1988 if (NumConfiguredInstance
> 1) {
1989 VariableDataSize
+= sizeof (EFI_UDP6_SERVICE_POINT
) * (NumConfiguredInstance
- 1);
1992 Udp6VariableData
= AllocateZeroPool (VariableDataSize
);
1993 if (Udp6VariableData
== NULL
) {
1994 return EFI_OUT_OF_RESOURCES
;
1997 Udp6VariableData
->DriverHandle
= Udp6Service
->ImageHandle
;
1998 Udp6VariableData
->ServiceCount
= NumConfiguredInstance
;
2000 Udp6ServicePoint
= &Udp6VariableData
->Services
[0];
2003 // Go through the children list to fill the configured children's address pairs.
2005 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
2006 Udp6Instance
= NET_LIST_USER_STRUCT_S (
2010 UDP6_INSTANCE_DATA_SIGNATURE
2013 if (Udp6Instance
->Configured
) {
2014 Udp6ServicePoint
->InstanceHandle
= Udp6Instance
->ChildHandle
;
2015 Udp6ServicePoint
->LocalPort
= Udp6Instance
->ConfigData
.StationPort
;
2016 Udp6ServicePoint
->RemotePort
= Udp6Instance
->ConfigData
.RemotePort
;
2019 &Udp6ServicePoint
->LocalAddress
,
2020 &Udp6Instance
->ConfigData
.StationAddress
2023 &Udp6ServicePoint
->RemoteAddress
,
2024 &Udp6Instance
->ConfigData
.RemoteAddress
2031 // Get the MAC string.
2033 Status
= NetLibGetMacString (
2034 Udp6Service
->ControllerHandle
,
2035 Udp6Service
->ImageHandle
,
2038 if (EFI_ERROR (Status
)) {
2042 if (Udp6Service
->MacString
!= NULL
) {
2044 // The variable is set already, we're going to update it.
2046 if (StrCmp (Udp6Service
->MacString
, NewMacString
) != 0) {
2048 // The MAC address is changed, delete the previous variable first.
2051 Udp6Service
->MacString
,
2052 &gEfiUdp6ServiceBindingProtocolGuid
,
2053 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
2059 FreePool (Udp6Service
->MacString
);
2062 Udp6Service
->MacString
= NewMacString
;
2064 Status
= gRT
->SetVariable (
2065 Udp6Service
->MacString
,
2066 &gEfiUdp6ServiceBindingProtocolGuid
,
2067 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
2069 (VOID
*) Udp6VariableData
2074 FreePool (Udp6VariableData
);
2081 Clear the variable and free the resource.
2083 @param[in, out] Udp6Service Udp6 service data.
2087 Udp6ClearVariableData (
2088 IN OUT UDP6_SERVICE_DATA
*Udp6Service
2091 ASSERT (Udp6Service
->MacString
!= NULL
);
2094 Udp6Service
->MacString
,
2095 &gEfiUdp6ServiceBindingProtocolGuid
,
2096 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
2101 FreePool (Udp6Service
->MacString
);
2102 Udp6Service
->MacString
= NULL
;
2107 Find the key in the netmap.
2109 @param[in] Map The netmap to search within.
2110 @param[in] Key The key to search.
2112 @return The point to the item contains the Key, or NULL, if Key isn't in the map.
2116 Udp6MapMultiCastAddr (
2123 EFI_IPv6_ADDRESS
*Addr
;
2125 ASSERT (Map
!= NULL
);
2126 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
2127 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
2128 Addr
= (EFI_IPv6_ADDRESS
*) Item
->Key
;
2129 if (EFI_IP6_EQUAL (Addr
, Key
)) {