3 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 EFI_UDP4_PROTOCOL mUdp4Protocol
= {
24 Reads the current operational settings.
26 The GetModeData() function copies the current operational settings of this EFI
27 UDPv4 Protocol instance into user-supplied buffers. This function is used
28 optionally to retrieve the operational mode data of underlying networks or
31 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
32 @param[out] Udp4ConfigData Pointer to the buffer to receive the current configuration data.
33 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
34 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
35 @param[out] SnpModeData Pointer to the simple network mode data structure.
37 @retval EFI_SUCCESS The mode data was read.
38 @retval EFI_NOT_STARTED When Udp4ConfigData is queried, no configuration data is
39 available because this instance has not been started.
40 @retval EFI_INVALID_PARAMETER This is NULL.
46 IN EFI_UDP4_PROTOCOL
*This
,
47 OUT EFI_UDP4_CONFIG_DATA
*Udp4ConfigData OPTIONAL
,
48 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
49 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
50 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
53 UDP4_INSTANCE_DATA
*Instance
;
59 return EFI_INVALID_PARAMETER
;
62 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
64 if (!Instance
->Configured
&& (Udp4ConfigData
!= NULL
)) {
65 return EFI_NOT_STARTED
;
68 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
70 if (Udp4ConfigData
!= NULL
) {
72 // Set the Udp4ConfigData.
74 CopyMem (Udp4ConfigData
, &Instance
->ConfigData
, sizeof (*Udp4ConfigData
));
77 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
80 // Get the underlying Ip4ModeData, MnpConfigData and SnpModeData.
82 Status
= Ip
->GetModeData (Ip
, Ip4ModeData
, MnpConfigData
, SnpModeData
);
84 gBS
->RestoreTPL (OldTpl
);
91 Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4
94 The Configure() function is used to do the following:
95 * Initialize and start this instance of the EFI UDPv4 Protocol.
96 * Change the filtering rules and operational parameters.
97 * Reset this instance of the EFI UDPv4 Protocol.
98 Until these parameters are initialized, no network traffic can be sent or
99 received by this instance. This instance can be also reset by calling Configure()
100 with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting
101 queue are flushed and no traffic is allowed through this instance.
102 With different parameters in UdpConfigData, Configure() can be used to bind
103 this instance to specified port.
105 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
106 @param[in] UdpConfigData Pointer to the buffer to receive the current configuration data.
108 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
109 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
110 RARP, etc.) is not finished yet.
111 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
112 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
113 and must be stopped/reset before it can be reconfigured.
114 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
115 and UdpConfigData.StationPort is already used by
117 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
118 EFI UDPv4 Protocol instance.
119 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
126 IN EFI_UDP4_PROTOCOL
*This
,
127 IN EFI_UDP4_CONFIG_DATA
*UdpConfigData OPTIONAL
131 UDP4_INSTANCE_DATA
*Instance
;
132 UDP4_SERVICE_DATA
*Udp4Service
;
134 IP4_ADDR StationAddress
;
136 IP4_ADDR RemoteAddress
;
137 EFI_IP4_CONFIG_DATA Ip4ConfigData
;
142 return EFI_INVALID_PARAMETER
;
145 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
147 if (!Instance
->Configured
&& (UdpConfigData
== NULL
)) {
151 Udp4Service
= Instance
->Udp4Service
;
152 Status
= EFI_SUCCESS
;
154 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
156 if (UdpConfigData
!= NULL
) {
158 CopyMem (&StationAddress
, &UdpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
159 CopyMem (&SubnetMask
, &UdpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
160 CopyMem (&RemoteAddress
, &UdpConfigData
->RemoteAddress
, sizeof (IP4_ADDR
));
162 StationAddress
= NTOHL (StationAddress
);
163 SubnetMask
= NTOHL (SubnetMask
);
164 RemoteAddress
= NTOHL (RemoteAddress
);
167 if (!UdpConfigData
->UseDefaultAddress
&&
168 (!IP4_IS_VALID_NETMASK (SubnetMask
) ||
169 !((StationAddress
== 0) || (SubnetMask
!= 0 && NetIp4IsUnicast (StationAddress
, SubnetMask
))) ||
170 IP4_IS_LOCAL_BROADCAST (RemoteAddress
))) {
172 // Don't use default address, and subnet mask is invalid or StationAddress is not
173 // a valid unicast IPv4 address or RemoteAddress is not a valid unicast IPv4 address
176 Status
= EFI_INVALID_PARAMETER
;
180 if (Instance
->Configured
) {
182 // The instance is already configured, try to do the re-configuration.
184 if (!Udp4IsReconfigurable (&Instance
->ConfigData
, UdpConfigData
)) {
186 // If the new configuration data wants to change some unreconfigurable
187 // settings, return EFI_ALREADY_STARTED.
189 Status
= EFI_ALREADY_STARTED
;
194 // Save the reconfigurable parameters.
196 Instance
->ConfigData
.TypeOfService
= UdpConfigData
->TypeOfService
;
197 Instance
->ConfigData
.TimeToLive
= UdpConfigData
->TimeToLive
;
198 Instance
->ConfigData
.DoNotFragment
= UdpConfigData
->DoNotFragment
;
199 Instance
->ConfigData
.ReceiveTimeout
= UdpConfigData
->ReceiveTimeout
;
200 Instance
->ConfigData
.TransmitTimeout
= UdpConfigData
->TransmitTimeout
;
203 // Construct the Ip configuration data from the UdpConfigData.
205 Udp4BuildIp4ConfigData (UdpConfigData
, &Ip4ConfigData
);
208 // Configure the Ip instance wrapped in the IpInfo.
210 Status
= IpIoConfigIp (Instance
->IpInfo
, &Ip4ConfigData
);
211 if (EFI_ERROR (Status
)) {
212 if (Status
== EFI_NO_MAPPING
) {
213 Instance
->IsNoMapping
= TRUE
;
219 Instance
->IsNoMapping
= FALSE
;
222 // Save the configuration data.
224 CopyMem (&Instance
->ConfigData
, UdpConfigData
, sizeof (Instance
->ConfigData
));
225 IP4_COPY_ADDRESS (&Instance
->ConfigData
.StationAddress
, &Ip4ConfigData
.StationAddress
);
226 IP4_COPY_ADDRESS (&Instance
->ConfigData
.SubnetMask
, &Ip4ConfigData
.SubnetMask
);
229 // Try to allocate the required port resource.
231 Status
= Udp4Bind (&Udp4Service
->ChildrenList
, &Instance
->ConfigData
);
232 if (EFI_ERROR (Status
)) {
234 // Reset the ip instance if bind fails.
236 IpIoConfigIp (Instance
->IpInfo
, NULL
);
241 // Pre calculate the checksum for the pseudo head, ignore the UDP length first.
243 CopyMem (&LocalAddr
, &Instance
->ConfigData
.StationAddress
, sizeof (IP4_ADDR
));
244 CopyMem (&RemoteAddr
, &Instance
->ConfigData
.RemoteAddress
, sizeof (IP4_ADDR
));
245 Instance
->HeadSum
= NetPseudoHeadChecksum (
252 Instance
->Configured
= TRUE
;
256 // UdpConfigData is NULL, reset the instance.
258 Instance
->Configured
= FALSE
;
259 Instance
->IsNoMapping
= FALSE
;
262 // Reset the Ip instance wrapped in the IpInfo.
264 IpIoConfigIp (Instance
->IpInfo
, NULL
);
267 // Cancel all the user tokens.
269 Instance
->Udp4Proto
.Cancel (&Instance
->Udp4Proto
, NULL
);
272 // Remove the buffered RxData for this instance.
274 Udp4FlushRcvdDgram (Instance
);
276 ASSERT (IsListEmpty (&Instance
->DeliveredDgramQue
));
281 gBS
->RestoreTPL (OldTpl
);
288 Joins and leaves multicast groups.
290 The Groups() function is used to enable and disable the multicast group
291 filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all
292 currently joined groups are left.
294 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
295 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to FALSE to leave one
296 or all multicast groups.
297 @param[in] MulticastAddress Pointer to multicast group address to join or leave.
299 @retval EFI_SUCCESS The operation completed successfully.
300 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
301 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
302 RARP, etc.) is not finished yet.
303 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
304 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
306 - JoinFlag is TRUE and MulticastAddress is NULL.
307 - JoinFlag is TRUE and *MulticastAddress is not
308 a valid multicast address.
309 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
311 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is
313 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
319 IN EFI_UDP4_PROTOCOL
*This
,
321 IN EFI_IPv4_ADDRESS
*MulticastAddress OPTIONAL
325 UDP4_INSTANCE_DATA
*Instance
;
326 EFI_IP4_PROTOCOL
*Ip
;
330 if ((This
== NULL
) || (JoinFlag
&& (MulticastAddress
== NULL
))) {
331 return EFI_INVALID_PARAMETER
;
336 CopyMem (&McastIp
, MulticastAddress
, sizeof (IP4_ADDR
));
338 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
339 return EFI_INVALID_PARAMETER
;
343 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
345 if (Instance
->IsNoMapping
) {
346 return EFI_NO_MAPPING
;
349 if (!Instance
->Configured
) {
350 return EFI_NOT_STARTED
;
353 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
355 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
358 // Invoke the Ip instance the Udp4 instance consumes to do the group operation.
360 Status
= Ip
->Groups (Ip
, JoinFlag
, MulticastAddress
);
362 if (EFI_ERROR (Status
)) {
367 // Keep a local copy of the configured multicast IPs because IpIo receives
368 // datagrams from the 0 station address IP instance and then UDP delivers to
369 // the matched instance. This copy of multicast IPs is used to avoid receive
370 // the mutlicast datagrams destined to multicast IPs the other instances configured.
374 NetMapInsertTail (&Instance
->McastIps
, (VOID
*) (UINTN
) McastIp
, NULL
);
377 NetMapIterate (&Instance
->McastIps
, Udp4LeaveGroup
, MulticastAddress
);
382 gBS
->RestoreTPL (OldTpl
);
389 Adds and deletes routing table entries.
391 The Routes() function adds a route to or deletes a route from the routing table.
392 Routes are determined by comparing the SubnetAddress with the destination IP
393 address and arithmetically AND-ing it with the SubnetMask. The gateway address
394 must be on the same subnet as the configured station address.
395 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
396 The default route matches all destination IP addresses that do not match any
398 A zero GatewayAddress is a nonroute. Packets are sent to the destination IP
399 address if it can be found in the Address Resolution Protocol (ARP) cache or
400 on the local subnet. One automatic nonroute entry will be inserted into the
401 routing table for outgoing packets that are addressed to a local subnet
402 (gateway address of 0.0.0.0).
403 Each instance of the EFI UDPv4 Protocol has its own independent routing table.
404 Instances of the EFI UDPv4 Protocol that use the default IP address will also
405 have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These
406 copies will be updated automatically whenever the IP driver reconfigures its
407 instances; as a result, the previous modification to these copies will be lost.
409 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
410 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table.
411 Set to FALSE to add this route to the routing table.
412 @param[in] SubnetAddress The destination network address that needs to be routed.
413 @param[in] SubnetMask The subnet mask of SubnetAddress.
414 @param[in] GatewayAddress The gateway IP address for this route.
416 @retval EFI_SUCCESS The operation completed successfully.
417 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
418 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
419 - RARP, etc.) is not finished yet.
420 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
421 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
422 @retval EFI_NOT_FOUND This route is not in the routing table.
423 @retval EFI_ACCESS_DENIED The route is already defined in the routing table.
429 IN EFI_UDP4_PROTOCOL
*This
,
430 IN BOOLEAN DeleteRoute
,
431 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
432 IN EFI_IPv4_ADDRESS
*SubnetMask
,
433 IN EFI_IPv4_ADDRESS
*GatewayAddress
436 UDP4_INSTANCE_DATA
*Instance
;
437 EFI_IP4_PROTOCOL
*Ip
;
440 return EFI_INVALID_PARAMETER
;
443 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
445 if (Instance
->IsNoMapping
) {
446 return EFI_NO_MAPPING
;
449 if (!Instance
->Configured
) {
450 return EFI_NOT_STARTED
;
453 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
456 // Invoke the Ip instance the Udp4 instance consumes to do the actual operation.
458 return Ip
->Routes (Ip
, DeleteRoute
, SubnetAddress
, SubnetMask
, GatewayAddress
);
463 Queues outgoing data packets into the transmit queue.
465 The Transmit() function places a sending request to this instance of the EFI
466 UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever
467 the packet in the token is sent out or some errors occur, the Token.Event will
468 be signaled and Token.Status is updated. Providing a proper notification function
469 and context for the event will enable the user to receive the notification and
472 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
473 @param[in] Token Pointer to the completion token that will be placed into the
476 @retval EFI_SUCCESS The data has been queued for transmission.
477 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
478 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
479 RARP, etc.) is not finished yet.
480 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
481 @retval EFI_ACCESS_DENIED The transmit completion token with the same
482 Token.Event was already in the transmit queue.
483 @retval EFI_NOT_READY The completion token could not be queued because the
484 transmit queue is full.
485 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
486 @retval EFI_NOT_FOUND There is no route to the destination network or address.
487 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP packet
488 size. Or the length of the IP header + UDP header + data
489 length is greater than MTU if DoNotFragment is TRUE.
495 IN EFI_UDP4_PROTOCOL
*This
,
496 IN EFI_UDP4_COMPLETION_TOKEN
*Token
500 UDP4_INSTANCE_DATA
*Instance
;
503 EFI_UDP_HEADER
*Udp4Header
;
504 EFI_UDP4_CONFIG_DATA
*ConfigData
;
506 IP4_ADDR Destination
;
507 EFI_UDP4_TRANSMIT_DATA
*TxData
;
508 EFI_UDP4_SESSION_DATA
*UdpSessionData
;
509 UDP4_SERVICE_DATA
*Udp4Service
;
510 IP_IO_OVERRIDE Override
;
512 EFI_IP_ADDRESS IpDestAddr
;
514 if ((This
== NULL
) || (Token
== NULL
)) {
515 return EFI_INVALID_PARAMETER
;
518 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
520 if (Instance
->IsNoMapping
) {
521 return EFI_NO_MAPPING
;
524 if (!Instance
->Configured
) {
525 return EFI_NOT_STARTED
;
528 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
531 // Validate the Token, if the token is invalid return the error code.
533 Status
= Udp4ValidateTxToken (Instance
, Token
);
534 if (EFI_ERROR (Status
)) {
538 if (EFI_ERROR (NetMapIterate (&Instance
->TxTokens
, Udp4TokenExist
, Token
)) ||
539 EFI_ERROR (NetMapIterate (&Instance
->RxTokens
, Udp4TokenExist
, Token
))) {
541 // Try to find a duplicate token in the two token maps, if found, return
542 // EFI_ACCESS_DENIED.
544 Status
= EFI_ACCESS_DENIED
;
548 TxData
= Token
->Packet
.TxData
;
551 // Create a net buffer to hold the user buffer and the udp header.
553 Packet
= NetbufFromExt (
554 (NET_FRAGMENT
*)TxData
->FragmentTable
,
555 TxData
->FragmentCount
,
558 Udp4NetVectorExtFree
,
561 if (Packet
== NULL
) {
562 Status
= EFI_OUT_OF_RESOURCES
;
567 // Store the IpIo in ProtoData.
569 Udp4Service
= Instance
->Udp4Service
;
570 *((UINTN
*) &Packet
->ProtoData
[0]) = (UINTN
) (Udp4Service
->IpIo
);
572 Udp4Header
= (EFI_UDP_HEADER
*) NetbufAllocSpace (Packet
, UDP4_HEADER_SIZE
, TRUE
);
573 ASSERT (Udp4Header
!= NULL
);
575 ConfigData
= &Instance
->ConfigData
;
578 // Fill the udp header.
580 Udp4Header
->SrcPort
= HTONS (ConfigData
->StationPort
);
581 Udp4Header
->DstPort
= HTONS (ConfigData
->RemotePort
);
582 Udp4Header
->Length
= HTONS ((UINT16
) Packet
->TotalSize
);
583 Udp4Header
->Checksum
= 0;
585 UdpSessionData
= TxData
->UdpSessionData
;
586 IP4_COPY_ADDRESS (&Override
.Ip4OverrideData
.SourceAddress
, &ConfigData
->StationAddress
);
588 if (UdpSessionData
!= NULL
) {
590 // Set the SourceAddress, SrcPort and Destination according to the specified
593 if (!EFI_IP4_EQUAL (&UdpSessionData
->SourceAddress
, &mZeroIp4Addr
)) {
594 IP4_COPY_ADDRESS (&Override
.Ip4OverrideData
.SourceAddress
, &UdpSessionData
->SourceAddress
);
597 if (UdpSessionData
->SourcePort
!= 0) {
598 Udp4Header
->SrcPort
= HTONS (UdpSessionData
->SourcePort
);
601 if (UdpSessionData
->DestinationPort
!= 0) {
602 Udp4Header
->DstPort
= HTONS (UdpSessionData
->DestinationPort
);
605 CopyMem (&Source
, &Override
.Ip4OverrideData
.SourceAddress
, sizeof (IP4_ADDR
));
606 CopyMem (&Destination
, &UdpSessionData
->DestinationAddress
, sizeof (IP4_ADDR
));
609 // calculate the pseudo head checksum using the overridden parameters.
611 HeadSum
= NetPseudoHeadChecksum (
619 // UdpSessionData is NULL, use the address and port information previously configured.
621 CopyMem (&Destination
, &ConfigData
->RemoteAddress
, sizeof (IP4_ADDR
));
623 HeadSum
= Instance
->HeadSum
;
627 // calculate the checksum.
629 Udp4Header
->Checksum
= Udp4Checksum (Packet
, HeadSum
);
630 if (Udp4Header
->Checksum
== 0) {
632 // If the calculated checksum is 0, fill the Checksum field with all ones.
634 Udp4Header
->Checksum
= 0xffff;
638 // Fill the IpIo Override data.
640 if (TxData
->GatewayAddress
!= NULL
) {
641 IP4_COPY_ADDRESS (&Override
.Ip4OverrideData
.GatewayAddress
, TxData
->GatewayAddress
);
643 ZeroMem (&Override
.Ip4OverrideData
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
646 Override
.Ip4OverrideData
.Protocol
= EFI_IP_PROTO_UDP
;
647 Override
.Ip4OverrideData
.TypeOfService
= ConfigData
->TypeOfService
;
648 Override
.Ip4OverrideData
.TimeToLive
= ConfigData
->TimeToLive
;
649 Override
.Ip4OverrideData
.DoNotFragment
= ConfigData
->DoNotFragment
;
652 // Save the token into the TxToken map.
654 Status
= NetMapInsertTail (&Instance
->TxTokens
, Token
, Packet
);
655 if (EFI_ERROR (Status
)) {
660 // Send out this datagram through IpIo.
662 IpDestAddr
.Addr
[0] = Destination
;
672 if (EFI_ERROR (Status
)) {
674 // Remove this token from the TxTokens.
676 Udp4RemoveToken (&Instance
->TxTokens
, Token
);
685 gBS
->RestoreTPL (OldTpl
);
692 Places an asynchronous receive request into the receiving queue.
694 The Receive() function places a completion token into the receive packet queue.
695 This function is always asynchronous.
696 The caller must fill in the Token.Event field in the completion token, and this
697 field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol
698 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
699 is signaled. Providing a proper notification function and context for the event
700 will enable the user to receive the notification and receiving status. That
701 notification function is guaranteed to not be re-entered.
703 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
704 @param[in] Token Pointer to a token that is associated with
705 the receive data descriptor.
707 @retval EFI_SUCCESS The receive completion token was cached.
708 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
709 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, RARP, etc.)
711 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
712 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
713 resources (usually memory).
714 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
715 @retval EFI_ACCESS_DENIED A receive completion token with the same Token.Event was already in
717 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
723 IN EFI_UDP4_PROTOCOL
*This
,
724 IN EFI_UDP4_COMPLETION_TOKEN
*Token
728 UDP4_INSTANCE_DATA
*Instance
;
731 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
732 return EFI_INVALID_PARAMETER
;
735 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
737 if (Instance
->IsNoMapping
) {
738 return EFI_NO_MAPPING
;
741 if (!Instance
->Configured
) {
742 return EFI_NOT_STARTED
;
745 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
747 if (EFI_ERROR (NetMapIterate (&Instance
->RxTokens
, Udp4TokenExist
, Token
))||
748 EFI_ERROR (NetMapIterate (&Instance
->TxTokens
, Udp4TokenExist
, Token
))) {
750 // Return EFI_ACCESS_DENIED if the specified token is already in the TxTokens or
753 Status
= EFI_ACCESS_DENIED
;
757 Token
->Packet
.RxData
= NULL
;
760 // Save the token into the RxTokens map.
762 Status
= NetMapInsertTail (&Instance
->RxTokens
, Token
, NULL
);
763 if (EFI_ERROR (Status
)) {
764 Status
= EFI_NOT_READY
;
769 // If there is an icmp error, report it.
771 Udp4ReportIcmpError (Instance
);
774 // Try to deliver the received datagrams.
776 Udp4InstanceDeliverDgram (Instance
);
779 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
785 gBS
->RestoreTPL (OldTpl
);
792 Aborts an asynchronous transmit or receive request.
794 The Cancel() function is used to abort a pending transmit or receive request.
795 If the token is in the transmit or receive request queues, after calling this
796 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
797 signaled. If the token is not in one of the queues, which usually means that
798 the asynchronous operation has completed, this function will not signal the
799 token and EFI_NOT_FOUND is returned.
801 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
802 @param[in] Token Pointer to a token that has been issued by
803 EFI_UDP4_PROTOCOL.Transmit() or
804 EFI_UDP4_PROTOCOL.Receive().If NULL, all pending
807 @retval EFI_SUCCESS The asynchronous I/O request was aborted and Token.Event
808 was signaled. When Token is NULL, all pending requests are
809 aborted and their events are signaled.
810 @retval EFI_INVALID_PARAMETER This is NULL.
811 @retval EFI_NOT_STARTED This instance has not been started.
812 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
813 RARP, etc.) is not finished yet.
814 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
815 not found in the transmit or receive queue. It has either completed
816 or was not issued by Transmit() and Receive().
822 IN EFI_UDP4_PROTOCOL
*This
,
823 IN EFI_UDP4_COMPLETION_TOKEN
*Token OPTIONAL
827 UDP4_INSTANCE_DATA
*Instance
;
831 return EFI_INVALID_PARAMETER
;
834 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
836 if (Instance
->IsNoMapping
) {
837 return EFI_NO_MAPPING
;
840 if (!Instance
->Configured
) {
841 return EFI_NOT_STARTED
;
844 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
847 // Cancle the tokens specified by Token for this instance.
849 Status
= Udp4InstanceCancelToken (Instance
, Token
);
852 // Dispatch the DPC queued by the NotifyFunction of the cancelled token's events.
856 gBS
->RestoreTPL (OldTpl
);
863 Polls for incoming data packets and processes outgoing data packets.
865 The Poll() function can be used by network drivers and applications to increase
866 the rate that data packets are moved between the communications device and the
867 transmit and receive queues.
868 In some systems, the periodic timer event in the managed network driver may not
869 poll the underlying communications device fast enough to transmit and/or receive
870 all data packets without missing incoming packets or dropping outgoing packets.
871 Drivers and applications that are experiencing packet loss should try calling
872 the Poll() function more often.
874 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
876 @retval EFI_SUCCESS Incoming or outgoing data was processed.
877 @retval EFI_INVALID_PARAMETER This is NULL.
878 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
879 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
885 IN EFI_UDP4_PROTOCOL
*This
888 UDP4_INSTANCE_DATA
*Instance
;
889 EFI_IP4_PROTOCOL
*Ip
;
892 return EFI_INVALID_PARAMETER
;
895 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
896 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
899 // Invode the Ip instance consumed by the udp instance to do the poll operation.
901 return Ip
->Poll (Ip
);