2 Udp6 driver's whole implementation.
4 Copyright (c) 2009 - 2018, 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 If Context is NULL, then ASSERT().
61 If NotifyData is NULL, then ASSERT().
63 @param[in] Status The completion status of the output udp datagram.
64 @param[in] Context Pointer to the context data.
65 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
66 @param[in] NotifyData Pointer to the notify data.
74 IN IP_IO_IP_PROTOCOL Sender
,
79 This function processes the received datagram passed up by the IpIo layer.
81 If NetSession is NULL, then ASSERT().
82 If Packet is NULL, then ASSERT().
83 If Context is NULL, then ASSERT().
85 @param[in] Status The status of this udp datagram.
86 @param[in] IcmpError The IcmpError code, only available when Status is
88 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
89 @param[in] Packet Pointer to the NET_BUF containing the received udp
91 @param[in] Context Pointer to the context data.
99 IN EFI_NET_SESSION_DATA
*NetSession
,
105 This function cancle the token specified by Arg in the Map.
107 @param[in] Map Pointer to the NET_MAP.
108 @param[in] Item Pointer to the NET_MAP_ITEM.
109 @param[in] Arg Pointer to the token to be cancelled, if NULL, all
110 the tokens in this Map will be cancelled.
111 This parameter is optional and may be NULL.
113 @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token
114 is not the same as that in the Item if Arg is not
116 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
124 IN NET_MAP_ITEM
*Item
,
125 IN VOID
*Arg OPTIONAL
129 This function check if the received udp datagram matches with the Instance.
131 @param[in] Instance Pointer to the udp instance context data.
132 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
133 from the received udp datagram.
135 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
136 @retval FALSE The udp datagram doe not match the receiving requirements of the Instance.
141 IN UDP6_INSTANCE_DATA
*Instance
,
142 IN EFI_UDP6_SESSION_DATA
*Udp6Session
146 This function removes the Wrap specified by Context and releases relevant resources.
148 @param[in] Event The Event this notify function is registered to.
149 @param[in] Context Pointer to the context data.
154 Udp6RecycleRxDataWrap (
160 This function wraps the Packet into RxData.
162 @param[in] Instance Pointer to the instance context data.
163 @param[in] Packet Pointer to the buffer containing the received
165 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
168 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
169 be returned if any error occurs.
174 IN UDP6_INSTANCE_DATA
*Instance
,
176 IN EFI_UDP6_RECEIVE_DATA
*RxData
180 This function enqueues the received datagram into the instances' receiving queues.
182 @param[in] Udp6Service Pointer to the udp service context data.
183 @param[in] Packet Pointer to the buffer containing the received
185 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
188 @return The times this datagram is enqueued.
193 IN UDP6_SERVICE_DATA
*Udp6Service
,
195 IN EFI_UDP6_RECEIVE_DATA
*RxData
199 This function delivers the datagrams enqueued in the instances.
201 @param[in] Udp6Service Pointer to the udp service context data.
206 IN UDP6_SERVICE_DATA
*Udp6Service
210 This function demultiplexes the received udp datagram to the appropriate instances.
212 @param[in] Udp6Service Pointer to the udp service context data.
213 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
214 the received datagram.
215 @param[in] Packet Pointer to the buffer containing the received udp
221 IN UDP6_SERVICE_DATA
*Udp6Service
,
222 IN EFI_NET_SESSION_DATA
*NetSession
,
227 This function handles the received Icmp Error message and demultiplexes it to the
230 @param[in] Udp6Service Pointer to the udp service context data.
231 @param[in] IcmpError The icmp error code.
232 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
233 from the received Icmp Error packet.
234 @param[in, out] Packet Pointer to the Icmp Error packet.
239 IN UDP6_SERVICE_DATA
*Udp6Service
,
241 IN EFI_NET_SESSION_DATA
*NetSession
,
242 IN OUT NET_BUF
*Packet
246 This function builds and sends out a icmp port unreachable message.
248 @param[in] IpIo Pointer to the IP_IO instance.
249 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
250 causes this icmp error message.
251 @param[in] Udp6Header Pointer to the udp header of the datagram causes
252 this icmp error message.
256 Udp6SendPortUnreach (
258 IN EFI_NET_SESSION_DATA
*NetSession
,
263 Find the key in the netmap
265 @param[in] Map The netmap to search within.
266 @param[in] Key The key to search.
268 @return The point to the item contains the Key, or NULL if Key isn't in the map.
272 Udp6MapMultiCastAddr (
278 Create the Udp service context data.
280 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
281 @param[in] ImageHandle The image handle of this udp6 driver.
282 @param[in] ControllerHandle The controller handle this udp6 driver binds on.
284 @retval EFI_SUCCESS The udp6 service context data was created and
286 @retval EFI_OUT_OF_RESOURCES Cannot allocate memory.
287 @retval Others An error condition occurred.
292 IN UDP6_SERVICE_DATA
*Udp6Service
,
293 IN EFI_HANDLE ImageHandle
,
294 IN EFI_HANDLE ControllerHandle
298 IP_IO_OPEN_DATA OpenData
;
300 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
302 Udp6Service
->Signature
= UDP6_SERVICE_DATA_SIGNATURE
;
303 Udp6Service
->ServiceBinding
= mUdp6ServiceBinding
;
304 Udp6Service
->ImageHandle
= ImageHandle
;
305 Udp6Service
->ControllerHandle
= ControllerHandle
;
306 Udp6Service
->ChildrenNumber
= 0;
308 InitializeListHead (&Udp6Service
->ChildrenList
);
311 // Create the IpIo for this service context.
313 Udp6Service
->IpIo
= IpIoCreate (ImageHandle
, ControllerHandle
, IP_VERSION_6
);
314 if (Udp6Service
->IpIo
== NULL
) {
315 return EFI_OUT_OF_RESOURCES
;
319 // Set the OpenData used to open the IpIo.
322 &OpenData
.IpConfigData
.Ip6CfgData
,
323 &mIp6IoDefaultIpConfigData
,
324 sizeof (EFI_IP6_CONFIG_DATA
)
326 OpenData
.RcvdContext
= (VOID
*) Udp6Service
;
327 OpenData
.SndContext
= NULL
;
328 OpenData
.PktRcvdNotify
= Udp6DgramRcvd
;
329 OpenData
.PktSentNotify
= Udp6DgramSent
;
332 // Configure and start the IpIo.
334 Status
= IpIoOpen (Udp6Service
->IpIo
, &OpenData
);
335 if (EFI_ERROR (Status
)) {
340 // Create the event for Udp timeout checking.
342 Status
= gBS
->CreateEvent (
343 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
347 &Udp6Service
->TimeoutEvent
349 if (EFI_ERROR (Status
)) {
354 // Start the timeout timer event.
356 Status
= gBS
->SetTimer (
357 Udp6Service
->TimeoutEvent
,
359 UDP6_TIMEOUT_INTERVAL
361 if (EFI_ERROR (Status
)) {
369 if (Udp6Service
->TimeoutEvent
!= NULL
) {
370 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
373 IpIoDestroy (Udp6Service
->IpIo
);
374 Udp6Service
->IpIo
= NULL
;
381 Clean the Udp service context data.
383 @param[in, out] Udp6Service Pointer to the UDP6_SERVICE_DATA.
388 IN OUT UDP6_SERVICE_DATA
*Udp6Service
392 // Close the TimeoutEvent timer.
394 gBS
->CloseEvent (Udp6Service
->TimeoutEvent
);
399 IpIoDestroy (Udp6Service
->IpIo
);
400 Udp6Service
->IpIo
= NULL
;
402 ZeroMem (Udp6Service
, sizeof (UDP6_SERVICE_DATA
));
407 This function checks and times out the I/O datagrams listed in the
408 UDP6_SERVICE_DATA which is specified by the input parameter Context.
411 @param[in] Event The event this function registered to.
412 @param[in] Context The context data registered during the creation of
423 UDP6_SERVICE_DATA
*Udp6Service
;
425 UDP6_INSTANCE_DATA
*Instance
;
426 LIST_ENTRY
*WrapEntry
;
427 LIST_ENTRY
*NextEntry
;
428 UDP6_RXDATA_WRAP
*Wrap
;
430 Udp6Service
= (UDP6_SERVICE_DATA
*) Context
;
431 NET_CHECK_SIGNATURE (Udp6Service
, UDP6_SERVICE_DATA_SIGNATURE
);
433 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
435 // Iterate all the instances belonging to this service context.
437 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
438 NET_CHECK_SIGNATURE (Instance
, UDP6_INSTANCE_DATA_SIGNATURE
);
440 if (!Instance
->Configured
|| (Instance
->ConfigData
.ReceiveTimeout
== 0)) {
442 // Skip this instance if it's not configured or no receive timeout.
447 NET_LIST_FOR_EACH_SAFE (WrapEntry
, NextEntry
, &Instance
->RcvdDgramQue
) {
449 // Iterate all the rxdatas belonging to this udp instance.
451 Wrap
= NET_LIST_USER_STRUCT (WrapEntry
, UDP6_RXDATA_WRAP
, Link
);
453 if (Wrap
->TimeoutTick
< UDP6_TIMEOUT_INTERVAL
/ 10) {
455 // Remove this RxData if it timeouts.
457 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
459 Wrap
->TimeoutTick
-= UDP6_TIMEOUT_INTERVAL
/ 10;
467 This function intializes the new created udp instance.
469 @param[in] Udp6Service Pointer to the UDP6_SERVICE_DATA.
470 @param[in, out] Instance Pointer to the un-initialized UDP6_INSTANCE_DATA.
475 IN UDP6_SERVICE_DATA
*Udp6Service
,
476 IN OUT UDP6_INSTANCE_DATA
*Instance
480 // Set the signature.
482 Instance
->Signature
= UDP6_INSTANCE_DATA_SIGNATURE
;
487 InitializeListHead (&Instance
->Link
);
488 InitializeListHead (&Instance
->RcvdDgramQue
);
489 InitializeListHead (&Instance
->DeliveredDgramQue
);
492 // Init the NET_MAPs.
494 NetMapInit (&Instance
->TxTokens
);
495 NetMapInit (&Instance
->RxTokens
);
496 NetMapInit (&Instance
->McastIps
);
499 // Save the pointer to the UDP6_SERVICE_DATA, and initialize other members.
501 Instance
->Udp6Service
= Udp6Service
;
502 CopyMem (&Instance
->Udp6Proto
, &mUdp6Protocol
, sizeof (EFI_UDP6_PROTOCOL
));
503 Instance
->IcmpError
= EFI_SUCCESS
;
504 Instance
->Configured
= FALSE
;
505 Instance
->IsNoMapping
= FALSE
;
506 Instance
->InDestroy
= FALSE
;
511 This function cleans the udp instance.
513 @param[in, out] Instance Pointer to the UDP6_INSTANCE_DATA to clean.
518 IN OUT UDP6_INSTANCE_DATA
*Instance
521 NetMapClean (&Instance
->McastIps
);
522 NetMapClean (&Instance
->RxTokens
);
523 NetMapClean (&Instance
->TxTokens
);
528 This function finds the udp instance by the specified <Address, Port> pair.
530 @param[in] InstanceList Pointer to the head of the list linking the udp
532 @param[in] Address Pointer to the specified IPv6 address.
533 @param[in] Port The udp port number.
535 @retval TRUE The specified <Address, Port> pair is found.
536 @retval FALSE Otherwise.
540 Udp6FindInstanceByPort (
541 IN LIST_ENTRY
*InstanceList
,
542 IN EFI_IPv6_ADDRESS
*Address
,
547 UDP6_INSTANCE_DATA
*Instance
;
548 EFI_UDP6_CONFIG_DATA
*ConfigData
;
550 NET_LIST_FOR_EACH (Entry
, InstanceList
) {
552 // Iterate all the udp instances.
554 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
555 ConfigData
= &Instance
->ConfigData
;
557 if (!Instance
->Configured
|| ConfigData
->AcceptAnyPort
) {
559 // If the instance is not configured, or the configdata of the instance indicates
560 // this instance accepts any port, skip it.
565 if (EFI_IP6_EQUAL (&ConfigData
->StationAddress
, Address
) &&
566 (ConfigData
->StationPort
== Port
)
569 // If both the address and the port are the same, return TRUE.
576 // Return FALSE when matching fails.
583 This function tries to bind the udp instance according to the configured port
586 @param[in] InstanceList Pointer to the head of the list linking the udp
588 @param[in] ConfigData Pointer to the ConfigData of the instance to be
591 @retval EFI_SUCCESS The bound operation completed successfully.
592 @retval EFI_ACCESS_DENIED The <Address, Port> specified by the ConfigData is
593 already used by other instance.
594 @retval EFI_OUT_OF_RESOURCES No available port resources.
599 IN LIST_ENTRY
*InstanceList
,
600 IN EFI_UDP6_CONFIG_DATA
*ConfigData
603 EFI_IPv6_ADDRESS
*StationAddress
;
606 if (ConfigData
->AcceptAnyPort
) {
610 StationAddress
= &ConfigData
->StationAddress
;
612 if (ConfigData
->StationPort
!= 0) {
614 if (!ConfigData
->AllowDuplicatePort
&&
615 Udp6FindInstanceByPort (InstanceList
, StationAddress
, ConfigData
->StationPort
)
618 // Do not allow duplicate ports and the port is already used by other instance.
620 return EFI_ACCESS_DENIED
;
624 // Select a random port for this instance.
626 if (ConfigData
->AllowDuplicatePort
) {
628 // Just pick up the random port if the instance allows duplicate port.
630 ConfigData
->StationPort
= mUdp6RandomPort
;
633 StartPort
= mUdp6RandomPort
;
635 while (Udp6FindInstanceByPort (InstanceList
, StationAddress
, mUdp6RandomPort
)) {
638 if (mUdp6RandomPort
== 0) {
639 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
642 if (mUdp6RandomPort
== StartPort
) {
644 // No available port.
646 return EFI_OUT_OF_RESOURCES
;
650 ConfigData
->StationPort
= mUdp6RandomPort
;
654 if (mUdp6RandomPort
== 0) {
655 mUdp6RandomPort
= UDP6_PORT_KNOWN
;
663 This function is used to check whether the NewConfigData has any un-reconfigurable
664 parameters changed compared to the OldConfigData.
666 @param[in] OldConfigData Pointer to the current ConfigData the udp instance
668 @param[in] NewConfigData Pointer to the new ConfigData.
670 @retval TRUE The instance is reconfigurable according to the NewConfigData.
671 @retval FALSE Otherwise.
675 Udp6IsReconfigurable (
676 IN EFI_UDP6_CONFIG_DATA
*OldConfigData
,
677 IN EFI_UDP6_CONFIG_DATA
*NewConfigData
680 if ((NewConfigData
->AcceptAnyPort
!= OldConfigData
->AcceptAnyPort
) ||
681 (NewConfigData
->AcceptPromiscuous
!= OldConfigData
->AcceptPromiscuous
) ||
682 (NewConfigData
->AllowDuplicatePort
!= OldConfigData
->AllowDuplicatePort
)
685 // The receiving filter parameters cannot be changed.
690 if ((!NewConfigData
->AcceptAnyPort
) &&
691 (NewConfigData
->StationPort
!= OldConfigData
->StationPort
)
694 // The port is not changeable.
699 if (!EFI_IP6_EQUAL (&NewConfigData
->StationAddress
, &OldConfigData
->StationAddress
)) {
701 // The StationAddress is not the same.
707 if (!EFI_IP6_EQUAL (&NewConfigData
->RemoteAddress
, &OldConfigData
->RemoteAddress
)) {
709 // The remoteaddress is not the same.
714 if (!NetIp6IsUnspecifiedAddr (&NewConfigData
->RemoteAddress
) &&
715 (NewConfigData
->RemotePort
!= OldConfigData
->RemotePort
)
718 // The RemotePort differs if it's designated in the configdata.
724 // All checks pass, return TRUE.
731 This function builds the Ip6 configdata from the Udp6ConfigData.
733 @param[in] Udp6ConfigData Pointer to the EFI_UDP6_CONFIG_DATA.
734 @param[in, out] Ip6ConfigData Pointer to the EFI_IP6_CONFIG_DATA.
738 Udp6BuildIp6ConfigData (
739 IN EFI_UDP6_CONFIG_DATA
*Udp6ConfigData
,
740 IN OUT EFI_IP6_CONFIG_DATA
*Ip6ConfigData
745 &mIp6IoDefaultIpConfigData
,
746 sizeof (EFI_IP6_CONFIG_DATA
)
748 Ip6ConfigData
->DefaultProtocol
= EFI_IP_PROTO_UDP
;
749 Ip6ConfigData
->AcceptPromiscuous
= Udp6ConfigData
->AcceptPromiscuous
;
750 IP6_COPY_ADDRESS (&Ip6ConfigData
->StationAddress
, &Udp6ConfigData
->StationAddress
);
751 IP6_COPY_ADDRESS (&Ip6ConfigData
->DestinationAddress
, &Udp6ConfigData
->RemoteAddress
);
753 // Use the -1 magic number to disable the receiving process of the ip instance.
755 Ip6ConfigData
->ReceiveTimeout
= (UINT32
) (-1);
760 This function validates the TxToken. It returns the error code according to the spec.
762 @param[in] Instance Pointer to the udp instance context data.
763 @param[in] TxToken Pointer to the token to be checked.
765 @retval EFI_SUCCESS The TxToken is valid.
766 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
768 Token.Packet.TxData is NULL;
769 Token.Packet.TxData.FragmentCount is zero;
770 Token.Packet.TxData.DataLength is not equal to the
771 sum of fragment lengths;
773 Token.Packet.TxData.FragmentTable[].FragmentLength
776 Token.Packet.TxData.FragmentTable[].FragmentBuffer
778 UdpSessionData.DestinationAddress are not valid
779 unicast IPv6 addresses if the UdpSessionData is
781 UdpSessionData.DestinationPort and
782 ConfigData.RemotePort are all zero if the
783 UdpSessionData is not NULL.
784 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP
789 Udp6ValidateTxToken (
790 IN UDP6_INSTANCE_DATA
*Instance
,
791 IN EFI_UDP6_COMPLETION_TOKEN
*TxToken
794 EFI_UDP6_TRANSMIT_DATA
*TxData
;
797 EFI_UDP6_CONFIG_DATA
*ConfigData
;
798 EFI_UDP6_SESSION_DATA
*UdpSessionData
;
801 if (TxToken
->Event
== NULL
) {
802 return EFI_INVALID_PARAMETER
;
805 TxData
= TxToken
->Packet
.TxData
;
807 if ((TxData
== NULL
) || (TxData
->FragmentCount
== 0)) {
808 return EFI_INVALID_PARAMETER
;
812 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
814 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
815 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)
818 // If the FragmentBuffer is NULL, or the FragmentLeng is zero.
820 return EFI_INVALID_PARAMETER
;
823 TotalLen
+= TxData
->FragmentTable
[Index
].FragmentLength
;
826 if (TotalLen
!= TxData
->DataLength
) {
828 // The TotalLen calculated by adding all the FragmentLeng doesn't equal to the
831 return EFI_INVALID_PARAMETER
;
834 ConfigData
= &Instance
->ConfigData
;
835 UdpSessionData
= TxData
->UdpSessionData
;
837 if (UdpSessionData
!= NULL
) {
839 if ((UdpSessionData
->DestinationPort
== 0) && (ConfigData
->RemotePort
== 0)) {
841 // Ambiguous; no avalaible DestinationPort for this token.
843 return EFI_INVALID_PARAMETER
;
846 if (NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
847 NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
850 // The DestinationAddress is not specificed.
852 return EFI_INVALID_PARAMETER
;
855 if (!NetIp6IsUnspecifiedAddr (&UdpSessionData
->DestinationAddress
) &&
856 !NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)
859 // The ConfigData.RemoteAddress is not zero and the UdpSessionData.DestinationAddress
862 return EFI_INVALID_PARAMETER
;
864 } else if (NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
)) {
866 // The configured RemoteAddress is all zero, and the user doesn't override the
867 // destination address.
869 return EFI_INVALID_PARAMETER
;
872 if (TxData
->DataLength
> UDP6_MAX_DATA_SIZE
) {
873 return EFI_BAD_BUFFER_SIZE
;
881 This function checks whether the specified Token duplicates the one in the Map.
883 @param[in] Map Pointer to the NET_MAP.
884 @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to
886 @param[in] Context Pointer to the Token to be checked.
888 @retval EFI_SUCCESS The Token specified by Context differs from the
890 @retval EFI_ACCESS_DENIED The Token duplicates with the one in the Item.
897 IN NET_MAP_ITEM
*Item
,
901 EFI_UDP6_COMPLETION_TOKEN
*Token
;
902 EFI_UDP6_COMPLETION_TOKEN
*TokenInItem
;
904 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) Context
;
905 TokenInItem
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
907 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
909 // The Token duplicates with the TokenInItem in case either the two pointers are the
910 // same, or the Events of these two tokens are the same.
912 return EFI_ACCESS_DENIED
;
920 This function calculates the checksum for the Packet, utilizing the pre-calculated
921 pseudo HeadSum to reduce some overhead.
923 @param[in] Packet Pointer to the NET_BUF contains the udp datagram.
924 @param[in] HeadSum Checksum of the pseudo header, execpt the length
927 @return The 16-bit checksum of this udp datagram.
938 Checksum
= NetbufChecksum (Packet
);
939 Checksum
= NetAddChecksum (Checksum
, HeadSum
);
941 Checksum
= NetAddChecksum (Checksum
, HTONS ((UINT16
) Packet
->TotalSize
));
942 Checksum
= (UINT16
) (~Checksum
);
948 This function removes the specified Token from the TokenMap.
950 @param[in] TokenMap Pointer to the NET_MAP containing the tokens.
951 @param[in] Token Pointer to the Token to be removed.
953 @retval EFI_SUCCESS The specified Token is removed from the TokenMap.
954 @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap.
959 IN NET_MAP
*TokenMap
,
960 IN EFI_UDP6_COMPLETION_TOKEN
*Token
966 // Find the Token first.
968 Item
= NetMapFindKey (TokenMap
, (VOID
*) Token
);
972 // Remove the token if it's found in the map.
974 NetMapRemoveItem (TokenMap
, Item
, NULL
);
978 return EFI_NOT_FOUND
;
983 This function is the packet transmitting notify function registered to the IpIo
984 interface. It's called to signal the udp TxToken when IpIo layer completes the
985 transmitting of the udp datagram.
987 If Context is NULL, then ASSERT().
988 If NotifyData is NULL, then ASSERT().
990 @param[in] Status The completion status of the output udp datagram.
991 @param[in] Context Pointer to the context data.
992 @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending.
993 @param[in] NotifyData Pointer to the notify data.
999 IN EFI_STATUS Status
,
1001 IN IP_IO_IP_PROTOCOL Sender
,
1005 UDP6_INSTANCE_DATA
*Instance
;
1006 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1008 ASSERT (Context
!= NULL
&& NotifyData
!= NULL
);
1010 Instance
= (UDP6_INSTANCE_DATA
*) Context
;
1011 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NotifyData
;
1013 if (Udp6RemoveToken (&Instance
->TxTokens
, Token
) == EFI_SUCCESS
) {
1015 // The token may be cancelled. Only signal it if the remove operation succeeds.
1017 Token
->Status
= Status
;
1018 gBS
->SignalEvent (Token
->Event
);
1025 This function processes the received datagram passed up by the IpIo layer.
1027 If NetSession is NULL, then ASSERT().
1028 If Packet is NULL, then ASSERT().
1029 If Context is NULL, then ASSERT().
1031 @param[in] Status The status of this udp datagram.
1032 @param[in] IcmpError The IcmpError code, only available when Status is
1034 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA.
1035 @param[in] Packet Pointer to the NET_BUF containing the received udp
1037 @param[in] Context Pointer to the context data.
1043 IN EFI_STATUS Status
,
1045 IN EFI_NET_SESSION_DATA
*NetSession
,
1050 ASSERT (NetSession
!= NULL
&& Packet
!= NULL
&& Context
!= NULL
);
1051 NET_CHECK_SIGNATURE (Packet
, NET_BUF_SIGNATURE
);
1054 // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR.
1056 if (Status
== EFI_SUCCESS
) {
1059 // Demultiplex the received datagram.
1061 Udp6Demultiplex ((UDP6_SERVICE_DATA
*) Context
, NetSession
, Packet
);
1064 // Handle the ICMP6 Error packet.
1066 Udp6IcmpHandler ((UDP6_SERVICE_DATA
*) Context
, IcmpError
, NetSession
, Packet
);
1070 // Dispatch the DPC queued by the NotifyFunction of the rx token's events
1071 // that are signaled with received data.
1078 This function removes the multicast group specified by Arg from the Map.
1080 @param[in] Map Pointer to the NET_MAP.
1081 @param[in] Item Pointer to the NET_MAP_ITEM.
1082 @param[in] Arg Pointer to the Arg, it's the pointer to a
1083 multicast IPv6 Address. This parameter is
1084 optional and may be NULL.
1086 @retval EFI_SUCCESS The multicast address is removed.
1087 @retval EFI_ABORTED The specified multicast address is removed, and the
1095 IN NET_MAP_ITEM
*Item
,
1096 IN VOID
*Arg OPTIONAL
1099 EFI_IPv6_ADDRESS
*McastIp
;
1103 if ((McastIp
!= NULL
) &&
1104 !EFI_IP6_EQUAL (McastIp
, ((EFI_IPv6_ADDRESS
*)Item
->Key
))
1107 // McastIp is not NULL and the multicast address contained in the Item
1108 // is not the same as McastIp.
1113 FreePool (Item
->Key
);
1116 // Remove this Item.
1118 NetMapRemoveItem (Map
, Item
, NULL
);
1120 if (McastIp
!= NULL
) {
1122 // Return EFI_ABORTED in case McastIp is not NULL to terminate the iteration.
1132 This function cancle the token specified by Arg in the Map.
1134 @param[in] Map Pointer to the NET_MAP.
1135 @param[in] Item Pointer to the NET_MAP_ITEM.
1136 @param[in] Arg Pointer to the token to be cancelled. If NULL, all
1137 the tokens in this Map will be cancelled.
1138 This parameter is optional and may be NULL.
1140 @retval EFI_SUCCESS The token is cancelled if Arg is NULL, or the token
1141 is not the same as that in the Item, if Arg is not
1143 @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is
1151 IN NET_MAP_ITEM
*Item
,
1152 IN VOID
*Arg OPTIONAL
1155 EFI_UDP6_COMPLETION_TOKEN
*TokenToCancel
;
1159 if ((Arg
!= NULL
) && (Item
->Key
!= Arg
)) {
1163 if (Item
->Value
!= NULL
) {
1165 // If the token is a transmit token, the corresponding Packet is recorded in
1166 // Item->Value, invoke IpIo to cancel this packet first. The IpIoCancelTxToken
1167 // will invoke Udp6DgramSent, the token will be signaled and this Item will
1168 // be removed from the Map there.
1170 Packet
= (NET_BUF
*) (Item
->Value
);
1171 IpIo
= (IP_IO
*) (*((UINTN
*) &Packet
->ProtoData
[0]));
1173 IpIoCancelTxToken (IpIo
, Packet
);
1176 // The token is a receive token. Abort it and remove it from the Map.
1178 TokenToCancel
= (EFI_UDP6_COMPLETION_TOKEN
*) Item
->Key
;
1179 NetMapRemoveItem (Map
, Item
, NULL
);
1181 TokenToCancel
->Status
= EFI_ABORTED
;
1182 gBS
->SignalEvent (TokenToCancel
->Event
);
1194 This function removes all the Wrap datas in the RcvdDgramQue.
1196 @param[in] Instance Pointer to the Udp6 Instance.
1200 Udp6FlushRcvdDgram (
1201 IN UDP6_INSTANCE_DATA
*Instance
1204 UDP6_RXDATA_WRAP
*Wrap
;
1206 while (!IsListEmpty (&Instance
->RcvdDgramQue
)) {
1208 // Iterate all the Wraps in the RcvdDgramQue.
1210 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1213 // The Wrap will be removed from the RcvdDgramQue by this function call.
1215 Udp6RecycleRxDataWrap (NULL
, (VOID
*) Wrap
);
1222 Cancel Udp6 tokens from the Udp6 instance.
1224 @param[in] Instance Pointer to the udp instance context data.
1225 @param[in] Token Pointer to the token to be canceled. If NULL, all
1226 tokens in this instance will be cancelled.
1227 This parameter is optional and may be NULL.
1229 @retval EFI_SUCCESS The Token is cancelled.
1230 @retval EFI_NOT_FOUND The Token is not found.
1234 Udp6InstanceCancelToken (
1235 IN UDP6_INSTANCE_DATA
*Instance
,
1236 IN EFI_UDP6_COMPLETION_TOKEN
*Token OPTIONAL
1242 // Cancel this token from the TxTokens map.
1244 Status
= NetMapIterate (&Instance
->TxTokens
, Udp6CancelTokens
, Token
);
1246 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1248 // If Token isn't NULL and Status is EFI_ABORTED, the token is cancelled from
1249 // the TxTokens and returns success.
1255 // Try to cancel this token from the RxTokens map in condition either the Token
1256 // is NULL or the specified Token is not in TxTokens.
1258 Status
= NetMapIterate (&Instance
->RxTokens
, Udp6CancelTokens
, Token
);
1260 if ((Token
!= NULL
) && (Status
== EFI_SUCCESS
)) {
1262 // If Token isn't NULL and Status is EFI_SUCCESS, the token is neither in the
1263 // TxTokens nor the RxTokens, or say, it's not found.
1265 return EFI_NOT_FOUND
;
1268 ASSERT ((Token
!= NULL
) ||
1269 ((0 == NetMapGetCount (&Instance
->TxTokens
)) &&
1270 (0 == NetMapGetCount (&Instance
->RxTokens
)))
1278 This function checks if the received udp datagram matches with the Instance.
1280 @param[in] Instance Pointer to the udp instance context data.
1281 @param[in] Udp6Session Pointer to the EFI_UDP6_SESSION_DATA abstracted
1282 from the received udp datagram.
1284 @retval TRUE The udp datagram matches the receiving requirements of the Instance.
1285 @retval FALSE The udp datagram does not matche the receiving requirements of the Instance.
1290 IN UDP6_INSTANCE_DATA
*Instance
,
1291 IN EFI_UDP6_SESSION_DATA
*Udp6Session
1294 EFI_UDP6_CONFIG_DATA
*ConfigData
;
1295 EFI_IPv6_ADDRESS Destination
;
1297 ConfigData
= &Instance
->ConfigData
;
1299 if (ConfigData
->AcceptPromiscuous
) {
1301 // Always matches if this instance is in the promiscuous state.
1306 if ((!ConfigData
->AcceptAnyPort
&& (Udp6Session
->DestinationPort
!= ConfigData
->StationPort
)) ||
1307 ((ConfigData
->RemotePort
!= 0) && (Udp6Session
->SourcePort
!= ConfigData
->RemotePort
))
1310 // The local port or the remote port doesn't match.
1315 if (!NetIp6IsUnspecifiedAddr (&ConfigData
->RemoteAddress
) &&
1316 !EFI_IP6_EQUAL (&ConfigData
->RemoteAddress
, &Udp6Session
->SourceAddress
)
1319 // This datagram doesn't come from the instance's specified sender.
1324 if (NetIp6IsUnspecifiedAddr (&ConfigData
->StationAddress
) ||
1325 EFI_IP6_EQUAL (&Udp6Session
->DestinationAddress
, &ConfigData
->StationAddress
)
1328 // The instance is configured to receive datagrams destinated to any station IP or
1329 // the destination address of this datagram matches the configured station IP.
1334 IP6_COPY_ADDRESS (&Destination
, &Udp6Session
->DestinationAddress
);
1336 if (IP6_IS_MULTICAST (&Destination
) &&
1337 (NULL
!= Udp6MapMultiCastAddr (&Instance
->McastIps
, &Destination
))
1340 // It's a multicast packet and the multicast address is accepted by this instance.
1350 This function removes the Wrap specified by Context and release relevant resources.
1352 @param[in] Event The Event this notify function registered to.
1353 @param[in] Context Pointer to the context data.
1358 Udp6RecycleRxDataWrap (
1363 UDP6_RXDATA_WRAP
*Wrap
;
1365 Wrap
= (UDP6_RXDATA_WRAP
*) Context
;
1368 // Remove the Wrap from the list it belongs to.
1370 RemoveEntryList (&Wrap
->Link
);
1373 // Free the Packet associated with this Wrap.
1375 NetbufFree (Wrap
->Packet
);
1380 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1387 This function wraps the Packet into RxData.
1389 @param[in] Instance Pointer to the instance context data.
1390 @param[in] Packet Pointer to the buffer containing the received
1392 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1395 @return Pointer to the structure wrapping the RxData and the Packet. NULL will
1396 be returned if any error occurs.
1401 IN UDP6_INSTANCE_DATA
*Instance
,
1403 IN EFI_UDP6_RECEIVE_DATA
*RxData
1407 UDP6_RXDATA_WRAP
*Wrap
;
1410 // Allocate buffer for the Wrap.
1412 Wrap
= AllocateZeroPool (sizeof (UDP6_RXDATA_WRAP
) +
1413 (Packet
->BlockOpNum
- 1) * sizeof (EFI_UDP6_FRAGMENT_DATA
));
1418 InitializeListHead (&Wrap
->Link
);
1420 CopyMem (&Wrap
->RxData
, RxData
, sizeof(EFI_UDP6_RECEIVE_DATA
));
1422 // Create the Recycle event.
1424 Status
= gBS
->CreateEvent (
1427 Udp6RecycleRxDataWrap
,
1429 &Wrap
->RxData
.RecycleSignal
1431 if (EFI_ERROR (Status
)) {
1436 Wrap
->Packet
= Packet
;
1437 Wrap
->TimeoutTick
= Instance
->ConfigData
.ReceiveTimeout
;
1444 This function enqueues the received datagram into the instances' receiving queues.
1446 @param[in] Udp6Service Pointer to the udp service context data.
1447 @param[in] Packet Pointer to the buffer containing the received
1449 @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this
1452 @return The times this datagram is enqueued.
1457 IN UDP6_SERVICE_DATA
*Udp6Service
,
1459 IN EFI_UDP6_RECEIVE_DATA
*RxData
1463 UDP6_INSTANCE_DATA
*Instance
;
1464 UDP6_RXDATA_WRAP
*Wrap
;
1469 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1471 // Iterate the instances.
1473 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1475 if (!Instance
->Configured
) {
1479 if (Udp6MatchDgram (Instance
, &RxData
->UdpSession
)) {
1481 // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
1483 Wrap
= Udp6WrapRxData (Instance
, Packet
, RxData
);
1488 NET_GET_REF (Packet
);
1490 InsertTailList (&Instance
->RcvdDgramQue
, &Wrap
->Link
);
1501 This function delivers the received datagrams to the specified instance.
1503 @param[in] Instance Pointer to the instance context data.
1507 Udp6InstanceDeliverDgram (
1508 IN UDP6_INSTANCE_DATA
*Instance
1511 UDP6_RXDATA_WRAP
*Wrap
;
1512 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1514 EFI_UDP6_RECEIVE_DATA
*RxData
;
1517 if (!IsListEmpty (&Instance
->RcvdDgramQue
) &&
1518 !NetMapIsEmpty (&Instance
->RxTokens
)
1521 Wrap
= NET_LIST_HEAD (&Instance
->RcvdDgramQue
, UDP6_RXDATA_WRAP
, Link
);
1523 if (NET_BUF_SHARED (Wrap
->Packet
)) {
1525 // Duplicate the Packet if it is shared between instances.
1527 Dup
= NetbufDuplicate (Wrap
->Packet
, NULL
, 0);
1532 NetbufFree (Wrap
->Packet
);
1537 NetListRemoveHead (&Instance
->RcvdDgramQue
);
1539 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1542 // Build the FragmentTable and set the FragmentCount in RxData.
1544 RxData
= &Wrap
->RxData
;
1545 RxData
->FragmentCount
= Wrap
->Packet
->BlockOpNum
;
1549 (NET_FRAGMENT
*) RxData
->FragmentTable
,
1550 &RxData
->FragmentCount
1553 Token
->Status
= EFI_SUCCESS
;
1554 Token
->Packet
.RxData
= &Wrap
->RxData
;
1556 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1557 InsertTailList (&Instance
->DeliveredDgramQue
, &Wrap
->Link
);
1558 gBS
->RestoreTPL (OldTpl
);
1560 gBS
->SignalEvent (Token
->Event
);
1566 This function delivers the datagrams enqueued in the instances.
1568 @param[in] Udp6Service Pointer to the udp service context data.
1573 IN UDP6_SERVICE_DATA
*Udp6Service
1577 UDP6_INSTANCE_DATA
*Instance
;
1579 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1581 // Iterate the instances.
1583 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1585 if (!Instance
->Configured
) {
1590 // Deliver the datagrams of this instance.
1592 Udp6InstanceDeliverDgram (Instance
);
1598 This function demultiplexes the received udp datagram to the appropriate instances.
1600 @param[in] Udp6Service Pointer to the udp service context data.
1601 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from
1602 the received datagram.
1603 @param[in] Packet Pointer to the buffer containing the received udp
1609 IN UDP6_SERVICE_DATA
*Udp6Service
,
1610 IN EFI_NET_SESSION_DATA
*NetSession
,
1614 EFI_UDP_HEADER
*Udp6Header
;
1616 EFI_UDP6_RECEIVE_DATA RxData
;
1617 EFI_UDP6_SESSION_DATA
*Udp6Session
;
1620 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1621 NetbufFree (Packet
);
1626 // Get the datagram header from the packet buffer.
1628 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1629 ASSERT (Udp6Header
!= NULL
);
1630 if (Udp6Header
== NULL
) {
1631 NetbufFree (Packet
);
1635 if (Udp6Header
->Checksum
!= 0) {
1637 // check the checksum.
1639 HeadSum
= NetIp6PseudoHeadChecksum (
1640 &NetSession
->Source
.v6
,
1641 &NetSession
->Dest
.v6
,
1646 if (Udp6Checksum (Packet
, HeadSum
) != 0) {
1650 NetbufFree (Packet
);
1655 Udp6Session
= &RxData
.UdpSession
;
1656 Udp6Session
->SourcePort
= NTOHS (Udp6Header
->SrcPort
);
1657 Udp6Session
->DestinationPort
= NTOHS (Udp6Header
->DstPort
);
1659 IP6_COPY_ADDRESS (&Udp6Session
->SourceAddress
, &NetSession
->Source
);
1660 IP6_COPY_ADDRESS (&Udp6Session
->DestinationAddress
, &NetSession
->Dest
);
1663 // Trim the UDP header.
1665 NetbufTrim (Packet
, UDP6_HEADER_SIZE
, TRUE
);
1667 RxData
.DataLength
= (UINT32
) Packet
->TotalSize
;
1670 // Try to enqueue this datagram into the instances.
1672 Enqueued
= Udp6EnqueueDgram (Udp6Service
, Packet
, &RxData
);
1674 if (Enqueued
== 0) {
1676 // Send the port unreachable ICMP packet before we free this NET_BUF
1678 Udp6SendPortUnreach (Udp6Service
->IpIo
, NetSession
, Udp6Header
);
1682 // Try to free the packet before deliver it.
1684 NetbufFree (Packet
);
1688 // Deliver the datagram.
1690 Udp6DeliverDgram (Udp6Service
);
1696 This function builds and sends out a icmp port unreachable message.
1698 @param[in] IpIo Pointer to the IP_IO instance.
1699 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet
1700 causes this icmp error message.
1701 @param[in] Udp6Header Pointer to the udp header of the datagram causes
1702 this icmp error message.
1706 Udp6SendPortUnreach (
1708 IN EFI_NET_SESSION_DATA
*NetSession
,
1714 IP6_ICMP_ERROR_HEAD
*IcmpErrHdr
;
1716 IP_IO_OVERRIDE Override
;
1717 IP_IO_IP_INFO
*IpSender
;
1718 EFI_IP6_MODE_DATA
*Ip6ModeData
;
1720 EFI_IP6_PROTOCOL
*Ip6Protocol
;
1725 // An ICMPv6 error message MUST NOT be originated as A packet destined to
1726 // 1) an IPv6 multicast address 2) The IPv6 Unspecified Address
1728 if (NetSession
->IpVersion
== IP_VERSION_6
) {
1729 if (NetIp6IsUnspecifiedAddr (&NetSession
->Dest
.v6
) ||
1730 IP6_IS_MULTICAST (&NetSession
->Dest
.v6
)
1737 IpSender
= IpIoFindSender (&IpIo
, NetSession
->IpVersion
, &NetSession
->Dest
);
1740 // Get the Ipv6 Mode Data.
1742 Ip6ModeData
= AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA
));
1743 ASSERT (Ip6ModeData
!= NULL
);
1744 if (Ip6ModeData
== NULL
) {
1749 // If not finding the related IpSender use the default IpIo to send out
1750 // the port unreachable ICMP message.
1752 if (IpSender
== NULL
) {
1753 Ip6Protocol
= IpIo
->Ip
.Ip6
;
1755 Ip6Protocol
= IpSender
->Ip
.Ip6
;
1758 Status
= Ip6Protocol
->GetModeData (
1765 if (EFI_ERROR (Status
)) {
1769 // The ICMP6 packet length, includes whole invoking packet and ICMP6 error header.
1771 Len
= NetSession
->IpHdrLen
+
1772 NTOHS(((EFI_UDP_HEADER
*) Udp6Header
)->Length
) +
1773 sizeof (IP6_ICMP_ERROR_HEAD
);
1776 // If the ICMP6 packet length larger than IP MTU, adjust its length to MTU.
1778 if (Ip6ModeData
->MaxPacketSize
< Len
) {
1779 Len
= Ip6ModeData
->MaxPacketSize
;
1783 // Allocate buffer for the icmp error message.
1785 Packet
= NetbufAlloc (Len
);
1786 if (Packet
== NULL
) {
1791 // Allocate space for the IP6_ICMP_ERROR_HEAD.
1793 IcmpErrHdr
= (IP6_ICMP_ERROR_HEAD
*) NetbufAllocSpace (Packet
, Len
, FALSE
);
1794 ASSERT (IcmpErrHdr
!= NULL
);
1795 if (IcmpErrHdr
== NULL
) {
1800 // Set the required fields for the icmp port unreachable message.
1802 IcmpErrHdr
->Head
.Type
= ICMP_V6_DEST_UNREACHABLE
;
1803 IcmpErrHdr
->Head
.Code
= ICMP_V6_PORT_UNREACHABLE
;
1804 IcmpErrHdr
->Head
.Checksum
= 0;
1805 IcmpErrHdr
->Fourth
= 0;
1808 // Copy as much of invoking Packet as possible without the ICMPv6 packet
1809 // exceeding the minimum Ipv6 MTU. The length of IP6_ICMP_ERROR_HEAD contains
1810 // the length of EFI_IP6_HEADER, so when using the length of IP6_ICMP_ERROR_HEAD
1811 // for pointer movement that fact should be considered.
1813 Ptr
= (VOID
*) &IcmpErrHdr
->Head
;
1814 Ptr
= (UINT8
*) (UINTN
) ((UINTN
) Ptr
+ sizeof (IP6_ICMP_ERROR_HEAD
) - sizeof (EFI_IP6_HEADER
));
1815 CopyMem (Ptr
, NetSession
->IpHdr
.Ip6Hdr
, NetSession
->IpHdrLen
);
1817 Ptr
+ NetSession
->IpHdrLen
,
1819 Len
- NetSession
->IpHdrLen
- sizeof (IP6_ICMP_ERROR_HEAD
) + sizeof (EFI_IP6_HEADER
)
1823 // Set the checksum as zero, and IP6 driver will calcuate it with pseudo header.
1825 IcmpErrHdr
->Head
.Checksum
= 0;
1828 // Fill the override data.
1830 Override
.Ip6OverrideData
.FlowLabel
= 0;
1831 Override
.Ip6OverrideData
.HopLimit
= 255;
1832 Override
.Ip6OverrideData
.Protocol
= IP6_ICMP
;
1835 // Send out this icmp packet.
1837 IpIoSend (IpIo
, Packet
, IpSender
, NULL
, NULL
, &NetSession
->Source
, &Override
);
1839 NetbufFree (Packet
);
1842 if (Ip6ModeData
!= NULL
) {
1843 FreePool (Ip6ModeData
);
1849 This function handles the received Icmp Error message and de-multiplexes it to the
1852 @param[in] Udp6Service Pointer to the udp service context data.
1853 @param[in] IcmpError The icmp error code.
1854 @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted
1855 from the received Icmp Error packet.
1856 @param[in, out] Packet Pointer to the Icmp Error packet.
1861 IN UDP6_SERVICE_DATA
*Udp6Service
,
1863 IN EFI_NET_SESSION_DATA
*NetSession
,
1864 IN OUT NET_BUF
*Packet
1867 EFI_UDP_HEADER
*Udp6Header
;
1868 EFI_UDP6_SESSION_DATA Udp6Session
;
1870 UDP6_INSTANCE_DATA
*Instance
;
1872 if (Packet
->TotalSize
< UDP6_HEADER_SIZE
) {
1873 NetbufFree (Packet
);
1877 Udp6Header
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
1878 ASSERT (Udp6Header
!= NULL
);
1879 if (Udp6Header
== NULL
) {
1880 NetbufFree (Packet
);
1884 IP6_COPY_ADDRESS (&Udp6Session
.SourceAddress
, &NetSession
->Source
);
1885 IP6_COPY_ADDRESS (&Udp6Session
.DestinationAddress
, &NetSession
->Dest
);
1887 Udp6Session
.SourcePort
= NTOHS (Udp6Header
->DstPort
);
1888 Udp6Session
.DestinationPort
= NTOHS (Udp6Header
->SrcPort
);
1890 NET_LIST_FOR_EACH (Entry
, &Udp6Service
->ChildrenList
) {
1892 // Iterate all the instances.
1894 Instance
= NET_LIST_USER_STRUCT (Entry
, UDP6_INSTANCE_DATA
, Link
);
1896 if (!Instance
->Configured
) {
1900 if (Udp6MatchDgram (Instance
, &Udp6Session
)) {
1902 // Translate the Icmp Error code according to the udp spec.
1904 Instance
->IcmpError
= IpIoGetIcmpErrStatus (IcmpError
, IP_VERSION_6
, NULL
, NULL
);
1906 if (IcmpError
> ICMP_ERR_UNREACH_PORT
) {
1907 Instance
->IcmpError
= EFI_ICMP_ERROR
;
1911 // Notify the instance with the received Icmp Error.
1913 Udp6ReportIcmpError (Instance
);
1919 NetbufFree (Packet
);
1924 This function reports the received ICMP error.
1926 @param[in] Instance Pointer to the udp instance context data.
1930 Udp6ReportIcmpError (
1931 IN UDP6_INSTANCE_DATA
*Instance
1934 EFI_UDP6_COMPLETION_TOKEN
*Token
;
1936 if (NetMapIsEmpty (&Instance
->RxTokens
)) {
1938 // There are no receive tokens to deliver the ICMP error.
1943 if (EFI_ERROR (Instance
->IcmpError
)) {
1945 // Try to get a RxToken from the RxTokens map.
1947 Token
= (EFI_UDP6_COMPLETION_TOKEN
*) NetMapRemoveHead (&Instance
->RxTokens
, NULL
);
1949 if (Token
!= NULL
) {
1951 // Report the error through the Token.
1953 Token
->Status
= Instance
->IcmpError
;
1954 gBS
->SignalEvent (Token
->Event
);
1957 // Clear the IcmpError.
1959 Instance
->IcmpError
= EFI_SUCCESS
;
1966 This function is a dummy ext-free function for the NET_BUF created for the output
1969 @param[in] Context Pointer to the context data.
1974 Udp6NetVectorExtFree (
1981 Find the key in the netmap.
1983 @param[in] Map The netmap to search within.
1984 @param[in] Key The key to search.
1986 @return The point to the item contains the Key, or NULL, if Key isn't in the map.
1990 Udp6MapMultiCastAddr (
1997 EFI_IPv6_ADDRESS
*Addr
;
1999 ASSERT (Map
!= NULL
);
2000 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
2001 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
2002 Addr
= (EFI_IPv6_ADDRESS
*) Item
->Key
;
2003 if (EFI_IP6_EQUAL (Addr
, Key
)) {