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
= {
23 Reads the current operational settings.
25 The GetModeData() function copies the current operational settings of this EFI
26 UDPv4 Protocol instance into user-supplied buffers. This function is used
27 optionally to retrieve the operational mode data of underlying networks or
30 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
31 @param[out] Udp4ConfigData Pointer to the buffer to receive the current configuration data.
32 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
33 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
34 @param[out] SnpModeData Pointer to the simple network mode data structure.
36 @retval EFI_SUCCESS The mode data was read.
37 @retval EFI_NOT_STARTED When Udp4ConfigData is queried, no configuration data is
38 available because this instance has not been started.
39 @retval EFI_INVALID_PARAMETER This is NULL.
45 IN EFI_UDP4_PROTOCOL
*This
,
46 OUT EFI_UDP4_CONFIG_DATA
*Udp4ConfigData OPTIONAL
,
47 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
48 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
49 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
52 UDP4_INSTANCE_DATA
*Instance
;
58 return EFI_INVALID_PARAMETER
;
61 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
63 if (!Instance
->Configured
&& (Udp4ConfigData
!= NULL
)) {
64 return EFI_NOT_STARTED
;
67 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
69 if (Udp4ConfigData
!= NULL
) {
71 // Set the Udp4ConfigData.
73 CopyMem (Udp4ConfigData
, &Instance
->ConfigData
, sizeof (*Udp4ConfigData
));
76 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
79 // Get the underlying Ip4ModeData, MnpConfigData and SnpModeData.
81 Status
= Ip
->GetModeData (Ip
, Ip4ModeData
, MnpConfigData
, SnpModeData
);
83 gBS
->RestoreTPL (OldTpl
);
89 Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4
92 The Configure() function is used to do the following:
93 * Initialize and start this instance of the EFI UDPv4 Protocol.
94 * Change the filtering rules and operational parameters.
95 * Reset this instance of the EFI UDPv4 Protocol.
96 Until these parameters are initialized, no network traffic can be sent or
97 received by this instance. This instance can be also reset by calling Configure()
98 with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting
99 queue are flushed and no traffic is allowed through this instance.
100 With different parameters in UdpConfigData, Configure() can be used to bind
101 this instance to specified port.
103 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
104 @param[in] UdpConfigData Pointer to the buffer to receive the current configuration data.
106 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
107 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
108 RARP, etc.) is not finished yet.
109 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
110 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
111 and must be stopped/reset before it can be reconfigured.
112 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
113 and UdpConfigData.StationPort is already used by
115 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
116 EFI UDPv4 Protocol instance.
117 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
124 IN EFI_UDP4_PROTOCOL
*This
,
125 IN EFI_UDP4_CONFIG_DATA
*UdpConfigData OPTIONAL
129 UDP4_INSTANCE_DATA
*Instance
;
130 UDP4_SERVICE_DATA
*Udp4Service
;
132 IP4_ADDR StationAddress
;
134 IP4_ADDR RemoteAddress
;
135 EFI_IP4_CONFIG_DATA Ip4ConfigData
;
140 return EFI_INVALID_PARAMETER
;
143 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
145 if (!Instance
->Configured
&& (UdpConfigData
== NULL
)) {
149 Udp4Service
= Instance
->Udp4Service
;
150 Status
= EFI_SUCCESS
;
152 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
154 if (UdpConfigData
!= NULL
) {
155 CopyMem (&StationAddress
, &UdpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
156 CopyMem (&SubnetMask
, &UdpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
157 CopyMem (&RemoteAddress
, &UdpConfigData
->RemoteAddress
, sizeof (IP4_ADDR
));
159 StationAddress
= NTOHL (StationAddress
);
160 SubnetMask
= NTOHL (SubnetMask
);
161 RemoteAddress
= NTOHL (RemoteAddress
);
163 if (!UdpConfigData
->UseDefaultAddress
&&
164 (!IP4_IS_VALID_NETMASK (SubnetMask
) ||
165 !((StationAddress
== 0) || ((SubnetMask
!= 0) && NetIp4IsUnicast (StationAddress
, SubnetMask
))) ||
166 IP4_IS_LOCAL_BROADCAST (RemoteAddress
)))
169 // Don't use default address, and subnet mask is invalid or StationAddress is not
170 // a valid unicast IPv4 address or RemoteAddress is not a valid unicast IPv4 address
173 Status
= EFI_INVALID_PARAMETER
;
177 if (Instance
->Configured
) {
179 // The instance is already configured, try to do the re-configuration.
181 if (!Udp4IsReconfigurable (&Instance
->ConfigData
, UdpConfigData
)) {
183 // If the new configuration data wants to change some unreconfigurable
184 // settings, return EFI_ALREADY_STARTED.
186 Status
= EFI_ALREADY_STARTED
;
191 // Save the reconfigurable parameters.
193 Instance
->ConfigData
.TypeOfService
= UdpConfigData
->TypeOfService
;
194 Instance
->ConfigData
.TimeToLive
= UdpConfigData
->TimeToLive
;
195 Instance
->ConfigData
.DoNotFragment
= UdpConfigData
->DoNotFragment
;
196 Instance
->ConfigData
.ReceiveTimeout
= UdpConfigData
->ReceiveTimeout
;
197 Instance
->ConfigData
.TransmitTimeout
= UdpConfigData
->TransmitTimeout
;
200 // Construct the Ip configuration data from the UdpConfigData.
202 Udp4BuildIp4ConfigData (UdpConfigData
, &Ip4ConfigData
);
205 // Configure the Ip instance wrapped in the IpInfo.
207 Status
= IpIoConfigIp (Instance
->IpInfo
, &Ip4ConfigData
);
208 if (EFI_ERROR (Status
)) {
209 if (Status
== EFI_NO_MAPPING
) {
210 Instance
->IsNoMapping
= TRUE
;
216 Instance
->IsNoMapping
= FALSE
;
219 // Save the configuration data.
221 CopyMem (&Instance
->ConfigData
, UdpConfigData
, sizeof (Instance
->ConfigData
));
222 IP4_COPY_ADDRESS (&Instance
->ConfigData
.StationAddress
, &Ip4ConfigData
.StationAddress
);
223 IP4_COPY_ADDRESS (&Instance
->ConfigData
.SubnetMask
, &Ip4ConfigData
.SubnetMask
);
226 // Try to allocate the required port resource.
228 Status
= Udp4Bind (&Udp4Service
->ChildrenList
, &Instance
->ConfigData
);
229 if (EFI_ERROR (Status
)) {
231 // Reset the ip instance if bind fails.
233 IpIoConfigIp (Instance
->IpInfo
, NULL
);
238 // Pre calculate the checksum for the pseudo head, ignore the UDP length first.
240 CopyMem (&LocalAddr
, &Instance
->ConfigData
.StationAddress
, sizeof (IP4_ADDR
));
241 CopyMem (&RemoteAddr
, &Instance
->ConfigData
.RemoteAddress
, sizeof (IP4_ADDR
));
242 Instance
->HeadSum
= NetPseudoHeadChecksum (
249 Instance
->Configured
= TRUE
;
253 // UdpConfigData is NULL, reset the instance.
255 Instance
->Configured
= FALSE
;
256 Instance
->IsNoMapping
= FALSE
;
259 // Reset the Ip instance wrapped in the IpInfo.
261 IpIoConfigIp (Instance
->IpInfo
, NULL
);
264 // Cancel all the user tokens.
266 Instance
->Udp4Proto
.Cancel (&Instance
->Udp4Proto
, NULL
);
269 // Remove the buffered RxData for this instance.
271 Udp4FlushRcvdDgram (Instance
);
273 ASSERT (IsListEmpty (&Instance
->DeliveredDgramQue
));
278 gBS
->RestoreTPL (OldTpl
);
284 Joins and leaves multicast groups.
286 The Groups() function is used to enable and disable the multicast group
287 filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all
288 currently joined groups are left.
290 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
291 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to FALSE to leave one
292 or all multicast groups.
293 @param[in] MulticastAddress Pointer to multicast group address to join or leave.
295 @retval EFI_SUCCESS The operation completed successfully.
296 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
297 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
298 RARP, etc.) is not finished yet.
299 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
300 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
302 - JoinFlag is TRUE and MulticastAddress is NULL.
303 - JoinFlag is TRUE and *MulticastAddress is not
304 a valid multicast address.
305 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
307 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is
309 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
315 IN EFI_UDP4_PROTOCOL
*This
,
317 IN EFI_IPv4_ADDRESS
*MulticastAddress OPTIONAL
321 UDP4_INSTANCE_DATA
*Instance
;
322 EFI_IP4_PROTOCOL
*Ip
;
326 if ((This
== NULL
) || (JoinFlag
&& (MulticastAddress
== NULL
))) {
327 return EFI_INVALID_PARAMETER
;
332 CopyMem (&McastIp
, MulticastAddress
, sizeof (IP4_ADDR
));
334 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
335 return EFI_INVALID_PARAMETER
;
339 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
341 if (Instance
->IsNoMapping
) {
342 return EFI_NO_MAPPING
;
345 if (!Instance
->Configured
) {
346 return EFI_NOT_STARTED
;
349 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
351 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
354 // Invoke the Ip instance the Udp4 instance consumes to do the group operation.
356 Status
= Ip
->Groups (Ip
, JoinFlag
, MulticastAddress
);
358 if (EFI_ERROR (Status
)) {
363 // Keep a local copy of the configured multicast IPs because IpIo receives
364 // datagrams from the 0 station address IP instance and then UDP delivers to
365 // the matched instance. This copy of multicast IPs is used to avoid receive
366 // the multicast datagrams destined to multicast IPs the other instances configured.
369 NetMapInsertTail (&Instance
->McastIps
, (VOID
*)(UINTN
)McastIp
, NULL
);
371 NetMapIterate (&Instance
->McastIps
, Udp4LeaveGroup
, MulticastAddress
);
376 gBS
->RestoreTPL (OldTpl
);
382 Adds and deletes routing table entries.
384 The Routes() function adds a route to or deletes a route from the routing table.
385 Routes are determined by comparing the SubnetAddress with the destination IP
386 address and arithmetically AND-ing it with the SubnetMask. The gateway address
387 must be on the same subnet as the configured station address.
388 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
389 The default route matches all destination IP addresses that do not match any
391 A zero GatewayAddress is a nonroute. Packets are sent to the destination IP
392 address if it can be found in the Address Resolution Protocol (ARP) cache or
393 on the local subnet. One automatic nonroute entry will be inserted into the
394 routing table for outgoing packets that are addressed to a local subnet
395 (gateway address of 0.0.0.0).
396 Each instance of the EFI UDPv4 Protocol has its own independent routing table.
397 Instances of the EFI UDPv4 Protocol that use the default IP address will also
398 have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These
399 copies will be updated automatically whenever the IP driver reconfigures its
400 instances; as a result, the previous modification to these copies will be lost.
402 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
403 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table.
404 Set to FALSE to add this route to the routing table.
405 @param[in] SubnetAddress The destination network address that needs to be routed.
406 @param[in] SubnetMask The subnet mask of SubnetAddress.
407 @param[in] GatewayAddress The gateway IP address for this route.
409 @retval EFI_SUCCESS The operation completed successfully.
410 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
411 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
412 - RARP, etc.) is not finished yet.
413 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
414 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
415 @retval EFI_NOT_FOUND This route is not in the routing table.
416 @retval EFI_ACCESS_DENIED The route is already defined in the routing table.
422 IN EFI_UDP4_PROTOCOL
*This
,
423 IN BOOLEAN DeleteRoute
,
424 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
425 IN EFI_IPv4_ADDRESS
*SubnetMask
,
426 IN EFI_IPv4_ADDRESS
*GatewayAddress
429 UDP4_INSTANCE_DATA
*Instance
;
430 EFI_IP4_PROTOCOL
*Ip
;
433 return EFI_INVALID_PARAMETER
;
436 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
438 if (Instance
->IsNoMapping
) {
439 return EFI_NO_MAPPING
;
442 if (!Instance
->Configured
) {
443 return EFI_NOT_STARTED
;
446 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
449 // Invoke the Ip instance the Udp4 instance consumes to do the actual operation.
451 return Ip
->Routes (Ip
, DeleteRoute
, SubnetAddress
, SubnetMask
, GatewayAddress
);
455 Queues outgoing data packets into the transmit queue.
457 The Transmit() function places a sending request to this instance of the EFI
458 UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever
459 the packet in the token is sent out or some errors occur, the Token.Event will
460 be signaled and Token.Status is updated. Providing a proper notification function
461 and context for the event will enable the user to receive the notification and
464 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
465 @param[in] Token Pointer to the completion token that will be placed into the
468 @retval EFI_SUCCESS The data has been queued for transmission.
469 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
470 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
471 RARP, etc.) is not finished yet.
472 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
473 @retval EFI_ACCESS_DENIED The transmit completion token with the same
474 Token.Event was already in the transmit queue.
475 @retval EFI_NOT_READY The completion token could not be queued because the
476 transmit queue is full.
477 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
478 @retval EFI_NOT_FOUND There is no route to the destination network or address.
479 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP packet
480 size. Or the length of the IP header + UDP header + data
481 length is greater than MTU if DoNotFragment is TRUE.
487 IN EFI_UDP4_PROTOCOL
*This
,
488 IN EFI_UDP4_COMPLETION_TOKEN
*Token
492 UDP4_INSTANCE_DATA
*Instance
;
495 EFI_UDP_HEADER
*Udp4Header
;
496 EFI_UDP4_CONFIG_DATA
*ConfigData
;
498 IP4_ADDR Destination
;
499 EFI_UDP4_TRANSMIT_DATA
*TxData
;
500 EFI_UDP4_SESSION_DATA
*UdpSessionData
;
501 UDP4_SERVICE_DATA
*Udp4Service
;
502 IP_IO_OVERRIDE Override
;
504 EFI_IP_ADDRESS IpDestAddr
;
506 if ((This
== NULL
) || (Token
== NULL
)) {
507 return EFI_INVALID_PARAMETER
;
510 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
512 if (Instance
->IsNoMapping
) {
513 return EFI_NO_MAPPING
;
516 if (!Instance
->Configured
) {
517 return EFI_NOT_STARTED
;
520 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
523 // Validate the Token, if the token is invalid return the error code.
525 Status
= Udp4ValidateTxToken (Instance
, Token
);
526 if (EFI_ERROR (Status
)) {
530 if (EFI_ERROR (NetMapIterate (&Instance
->TxTokens
, Udp4TokenExist
, Token
)) ||
531 EFI_ERROR (NetMapIterate (&Instance
->RxTokens
, Udp4TokenExist
, Token
)))
534 // Try to find a duplicate token in the two token maps, if found, return
535 // EFI_ACCESS_DENIED.
537 Status
= EFI_ACCESS_DENIED
;
541 TxData
= Token
->Packet
.TxData
;
544 // Create a net buffer to hold the user buffer and the udp header.
546 Packet
= NetbufFromExt (
547 (NET_FRAGMENT
*)TxData
->FragmentTable
,
548 TxData
->FragmentCount
,
551 Udp4NetVectorExtFree
,
554 if (Packet
== NULL
) {
555 Status
= EFI_OUT_OF_RESOURCES
;
560 // Store the IpIo in ProtoData.
562 Udp4Service
= Instance
->Udp4Service
;
563 *((UINTN
*)&Packet
->ProtoData
[0]) = (UINTN
)(Udp4Service
->IpIo
);
565 Udp4Header
= (EFI_UDP_HEADER
*)NetbufAllocSpace (Packet
, UDP4_HEADER_SIZE
, TRUE
);
566 ASSERT (Udp4Header
!= NULL
);
568 ConfigData
= &Instance
->ConfigData
;
571 // Fill the udp header.
573 Udp4Header
->SrcPort
= HTONS (ConfigData
->StationPort
);
574 Udp4Header
->DstPort
= HTONS (ConfigData
->RemotePort
);
575 Udp4Header
->Length
= HTONS ((UINT16
)Packet
->TotalSize
);
576 Udp4Header
->Checksum
= 0;
578 UdpSessionData
= TxData
->UdpSessionData
;
579 IP4_COPY_ADDRESS (&Override
.Ip4OverrideData
.SourceAddress
, &ConfigData
->StationAddress
);
581 if (UdpSessionData
!= NULL
) {
583 // Set the SourceAddress, SrcPort and Destination according to the specified
586 if (!EFI_IP4_EQUAL (&UdpSessionData
->SourceAddress
, &mZeroIp4Addr
)) {
587 IP4_COPY_ADDRESS (&Override
.Ip4OverrideData
.SourceAddress
, &UdpSessionData
->SourceAddress
);
590 if (UdpSessionData
->SourcePort
!= 0) {
591 Udp4Header
->SrcPort
= HTONS (UdpSessionData
->SourcePort
);
594 if (UdpSessionData
->DestinationPort
!= 0) {
595 Udp4Header
->DstPort
= HTONS (UdpSessionData
->DestinationPort
);
598 CopyMem (&Source
, &Override
.Ip4OverrideData
.SourceAddress
, sizeof (IP4_ADDR
));
599 CopyMem (&Destination
, &UdpSessionData
->DestinationAddress
, sizeof (IP4_ADDR
));
602 // calculate the pseudo head checksum using the overridden parameters.
604 HeadSum
= NetPseudoHeadChecksum (
612 // UdpSessionData is NULL, use the address and port information previously configured.
614 CopyMem (&Destination
, &ConfigData
->RemoteAddress
, sizeof (IP4_ADDR
));
616 HeadSum
= Instance
->HeadSum
;
620 // calculate the checksum.
622 Udp4Header
->Checksum
= Udp4Checksum (Packet
, HeadSum
);
623 if (Udp4Header
->Checksum
== 0) {
625 // If the calculated checksum is 0, fill the Checksum field with all ones.
627 Udp4Header
->Checksum
= 0xffff;
631 // Fill the IpIo Override data.
633 if (TxData
->GatewayAddress
!= NULL
) {
634 IP4_COPY_ADDRESS (&Override
.Ip4OverrideData
.GatewayAddress
, TxData
->GatewayAddress
);
636 ZeroMem (&Override
.Ip4OverrideData
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
639 Override
.Ip4OverrideData
.Protocol
= EFI_IP_PROTO_UDP
;
640 Override
.Ip4OverrideData
.TypeOfService
= ConfigData
->TypeOfService
;
641 Override
.Ip4OverrideData
.TimeToLive
= ConfigData
->TimeToLive
;
642 Override
.Ip4OverrideData
.DoNotFragment
= ConfigData
->DoNotFragment
;
645 // Save the token into the TxToken map.
647 Status
= NetMapInsertTail (&Instance
->TxTokens
, Token
, Packet
);
648 if (EFI_ERROR (Status
)) {
653 // Send out this datagram through IpIo.
655 IpDestAddr
.Addr
[0] = Destination
;
665 if (EFI_ERROR (Status
)) {
667 // Remove this token from the TxTokens.
669 Udp4RemoveToken (&Instance
->TxTokens
, Token
);
678 gBS
->RestoreTPL (OldTpl
);
684 Places an asynchronous receive request into the receiving queue.
686 The Receive() function places a completion token into the receive packet queue.
687 This function is always asynchronous.
688 The caller must fill in the Token.Event field in the completion token, and this
689 field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol
690 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
691 is signaled. Providing a proper notification function and context for the event
692 will enable the user to receive the notification and receiving status. That
693 notification function is guaranteed to not be re-entered.
695 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
696 @param[in] Token Pointer to a token that is associated with
697 the receive data descriptor.
699 @retval EFI_SUCCESS The receive completion token was cached.
700 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
701 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, RARP, etc.)
703 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
704 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
705 resources (usually memory).
706 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
707 @retval EFI_ACCESS_DENIED A receive completion token with the same Token.Event was already in
709 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
715 IN EFI_UDP4_PROTOCOL
*This
,
716 IN EFI_UDP4_COMPLETION_TOKEN
*Token
720 UDP4_INSTANCE_DATA
*Instance
;
723 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
724 return EFI_INVALID_PARAMETER
;
727 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
729 if (Instance
->IsNoMapping
) {
730 return EFI_NO_MAPPING
;
733 if (!Instance
->Configured
) {
734 return EFI_NOT_STARTED
;
737 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
739 if (EFI_ERROR (NetMapIterate (&Instance
->RxTokens
, Udp4TokenExist
, Token
)) ||
740 EFI_ERROR (NetMapIterate (&Instance
->TxTokens
, Udp4TokenExist
, Token
)))
743 // Return EFI_ACCESS_DENIED if the specified token is already in the TxTokens or
746 Status
= EFI_ACCESS_DENIED
;
750 Token
->Packet
.RxData
= NULL
;
753 // Save the token into the RxTokens map.
755 Status
= NetMapInsertTail (&Instance
->RxTokens
, Token
, NULL
);
756 if (EFI_ERROR (Status
)) {
757 Status
= EFI_NOT_READY
;
762 // If there is an icmp error, report it.
764 Udp4ReportIcmpError (Instance
);
767 // Try to deliver the received datagrams.
769 Udp4InstanceDeliverDgram (Instance
);
772 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
778 gBS
->RestoreTPL (OldTpl
);
784 Aborts an asynchronous transmit or receive request.
786 The Cancel() function is used to abort a pending transmit or receive request.
787 If the token is in the transmit or receive request queues, after calling this
788 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
789 signaled. If the token is not in one of the queues, which usually means that
790 the asynchronous operation has completed, this function will not signal the
791 token and EFI_NOT_FOUND is returned.
793 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
794 @param[in] Token Pointer to a token that has been issued by
795 EFI_UDP4_PROTOCOL.Transmit() or
796 EFI_UDP4_PROTOCOL.Receive().If NULL, all pending
799 @retval EFI_SUCCESS The asynchronous I/O request was aborted and Token.Event
800 was signaled. When Token is NULL, all pending requests are
801 aborted and their events are signaled.
802 @retval EFI_INVALID_PARAMETER This is NULL.
803 @retval EFI_NOT_STARTED This instance has not been started.
804 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
805 RARP, etc.) is not finished yet.
806 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
807 not found in the transmit or receive queue. It has either completed
808 or was not issued by Transmit() and Receive().
814 IN EFI_UDP4_PROTOCOL
*This
,
815 IN EFI_UDP4_COMPLETION_TOKEN
*Token OPTIONAL
819 UDP4_INSTANCE_DATA
*Instance
;
823 return EFI_INVALID_PARAMETER
;
826 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
828 if (Instance
->IsNoMapping
) {
829 return EFI_NO_MAPPING
;
832 if (!Instance
->Configured
) {
833 return EFI_NOT_STARTED
;
836 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
839 // Cancel the tokens specified by Token for this instance.
841 Status
= Udp4InstanceCancelToken (Instance
, Token
);
844 // Dispatch the DPC queued by the NotifyFunction of the cancelled token's events.
848 gBS
->RestoreTPL (OldTpl
);
854 Polls for incoming data packets and processes outgoing data packets.
856 The Poll() function can be used by network drivers and applications to increase
857 the rate that data packets are moved between the communications device and the
858 transmit and receive queues.
859 In some systems, the periodic timer event in the managed network driver may not
860 poll the underlying communications device fast enough to transmit and/or receive
861 all data packets without missing incoming packets or dropping outgoing packets.
862 Drivers and applications that are experiencing packet loss should try calling
863 the Poll() function more often.
865 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
867 @retval EFI_SUCCESS Incoming or outgoing data was processed.
868 @retval EFI_INVALID_PARAMETER This is NULL.
869 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
870 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
876 IN EFI_UDP4_PROTOCOL
*This
879 UDP4_INSTANCE_DATA
*Instance
;
880 EFI_IP4_PROTOCOL
*Ip
;
883 return EFI_INVALID_PARAMETER
;
886 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
887 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
890 // Invode the Ip instance consumed by the udp instance to do the poll operation.
892 return Ip
->Poll (Ip
);