3 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 EFI_UDP4_PROTOCOL mUdp4Protocol
= {
29 Reads the current operational settings.
31 The GetModeData() function copies the current operational settings of this EFI
32 UDPv4 Protocol instance into user-supplied buffers. This function is used
33 optionally to retrieve the operational mode data of underlying networks or
36 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
37 @param[out] Udp4ConfigData Pointer to the buffer to receive the current configuration data.
38 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
39 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
40 @param[out] SnpModeData Pointer to the simple network mode data structure.
42 @retval EFI_SUCCESS The mode data was read.
43 @retval EFI_NOT_STARTED When Udp4ConfigData is queried, no configuration data is
44 available because this instance has not been started.
45 @retval EFI_INVALID_PARAMETER This is NULL.
51 IN EFI_UDP4_PROTOCOL
*This
,
52 OUT EFI_UDP4_CONFIG_DATA
*Udp4ConfigData OPTIONAL
,
53 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
54 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
55 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
58 UDP4_INSTANCE_DATA
*Instance
;
64 return EFI_INVALID_PARAMETER
;
67 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
69 if (!Instance
->Configured
&& (Udp4ConfigData
!= NULL
)) {
70 return EFI_NOT_STARTED
;
73 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
75 if (Udp4ConfigData
!= NULL
) {
77 // Set the Udp4ConfigData.
79 CopyMem (Udp4ConfigData
, &Instance
->ConfigData
, sizeof (*Udp4ConfigData
));
82 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
85 // Get the underlying Ip4ModeData, MnpConfigData and SnpModeData.
87 Status
= Ip
->GetModeData (Ip
, Ip4ModeData
, MnpConfigData
, SnpModeData
);
89 gBS
->RestoreTPL (OldTpl
);
96 Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4
99 The Configure() function is used to do the following:
100 * Initialize and start this instance of the EFI UDPv4 Protocol.
101 * Change the filtering rules and operational parameters.
102 * Reset this instance of the EFI UDPv4 Protocol.
103 Until these parameters are initialized, no network traffic can be sent or
104 received by this instance. This instance can be also reset by calling Configure()
105 with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting
106 queue are flushed and no traffic is allowed through this instance.
107 With different parameters in UdpConfigData, Configure() can be used to bind
108 this instance to specified port.
110 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
111 @param[in] UdpConfigData Pointer to the buffer to receive the current configuration data.
113 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
114 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
115 RARP, etc.) is not finished yet.
116 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
117 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
118 and must be stopped/reset before it can be reconfigured.
119 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
120 and UdpConfigData.StationPort is already used by
122 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
123 EFI UDPv4 Protocol instance.
124 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
131 IN EFI_UDP4_PROTOCOL
*This
,
132 IN EFI_UDP4_CONFIG_DATA
*UdpConfigData OPTIONAL
136 UDP4_INSTANCE_DATA
*Instance
;
137 UDP4_SERVICE_DATA
*Udp4Service
;
139 IP4_ADDR StationAddress
;
141 IP4_ADDR RemoteAddress
;
142 EFI_IP4_CONFIG_DATA Ip4ConfigData
;
147 return EFI_INVALID_PARAMETER
;
150 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
152 if (!Instance
->Configured
&& (UdpConfigData
== NULL
)) {
156 Udp4Service
= Instance
->Udp4Service
;
157 Status
= EFI_SUCCESS
;
159 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
161 if (UdpConfigData
!= NULL
) {
163 CopyMem (&StationAddress
, &UdpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
164 CopyMem (&SubnetMask
, &UdpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
165 CopyMem (&RemoteAddress
, &UdpConfigData
->RemoteAddress
, sizeof (IP4_ADDR
));
167 StationAddress
= NTOHL (StationAddress
);
168 SubnetMask
= NTOHL (SubnetMask
);
169 RemoteAddress
= NTOHL (RemoteAddress
);
172 if (!UdpConfigData
->UseDefaultAddress
&&
173 (!IP4_IS_VALID_NETMASK (SubnetMask
) ||
174 !((StationAddress
== 0) || NetIp4IsUnicast (StationAddress
, SubnetMask
)) ||
175 !((RemoteAddress
== 0) || NetIp4IsUnicast (RemoteAddress
, 0)))) {
177 // Don't use default address, and subnet mask is invalid or StationAddress is not
178 // a valid unicast IPv4 address or RemoteAddress is not a valid unicast IPv4 address
181 Status
= EFI_INVALID_PARAMETER
;
185 if (Instance
->Configured
) {
187 // The instance is already configured, try to do the re-configuration.
189 if (!Udp4IsReconfigurable (&Instance
->ConfigData
, UdpConfigData
)) {
191 // If the new configuration data wants to change some unreconfigurable
192 // settings, return EFI_ALREADY_STARTED.
194 Status
= EFI_ALREADY_STARTED
;
199 // Save the reconfigurable parameters.
201 Instance
->ConfigData
.TypeOfService
= UdpConfigData
->TypeOfService
;
202 Instance
->ConfigData
.TimeToLive
= UdpConfigData
->TimeToLive
;
203 Instance
->ConfigData
.DoNotFragment
= UdpConfigData
->DoNotFragment
;
204 Instance
->ConfigData
.ReceiveTimeout
= UdpConfigData
->ReceiveTimeout
;
205 Instance
->ConfigData
.TransmitTimeout
= UdpConfigData
->TransmitTimeout
;
208 // Construct the Ip configuration data from the UdpConfigData.
210 Udp4BuildIp4ConfigData (UdpConfigData
, &Ip4ConfigData
);
213 // Configure the Ip instance wrapped in the IpInfo.
215 Status
= IpIoConfigIp (Instance
->IpInfo
, &Ip4ConfigData
);
216 if (EFI_ERROR (Status
)) {
217 if (Status
== EFI_NO_MAPPING
) {
218 Instance
->IsNoMapping
= TRUE
;
224 Instance
->IsNoMapping
= FALSE
;
227 // Save the configuration data.
229 CopyMem (&Instance
->ConfigData
, UdpConfigData
, sizeof (Instance
->ConfigData
));
230 Instance
->ConfigData
.StationAddress
= Ip4ConfigData
.StationAddress
;
231 Instance
->ConfigData
.SubnetMask
= Ip4ConfigData
.SubnetMask
;
234 // Try to allocate the required port resource.
236 Status
= Udp4Bind (&Udp4Service
->ChildrenList
, &Instance
->ConfigData
);
237 if (EFI_ERROR (Status
)) {
239 // Reset the ip instance if bind fails.
241 IpIoConfigIp (Instance
->IpInfo
, NULL
);
246 // Pre calculate the checksum for the pseudo head, ignore the UDP length first.
248 CopyMem (&LocalAddr
, &Instance
->ConfigData
.StationAddress
, sizeof (IP4_ADDR
));
249 CopyMem (&RemoteAddr
, &Instance
->ConfigData
.RemoteAddress
, sizeof (IP4_ADDR
));
250 Instance
->HeadSum
= NetPseudoHeadChecksum (
257 Instance
->Configured
= TRUE
;
261 // UdpConfigData is NULL, reset the instance.
263 Instance
->Configured
= FALSE
;
264 Instance
->IsNoMapping
= FALSE
;
267 // Reset the Ip instance wrapped in the IpInfo.
269 IpIoConfigIp (Instance
->IpInfo
, NULL
);
272 // Cancel all the user tokens.
274 Instance
->Udp4Proto
.Cancel (&Instance
->Udp4Proto
, NULL
);
277 // Remove the buffered RxData for this instance.
279 Udp4FlushRcvdDgram (Instance
);
281 ASSERT (IsListEmpty (&Instance
->DeliveredDgramQue
));
286 gBS
->RestoreTPL (OldTpl
);
293 Joins and leaves multicast groups.
295 The Groups() function is used to enable and disable the multicast group
296 filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all
297 currently joined groups are left.
299 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
300 @param[in] JoinFlag Set to TRUE to join a multicast group. Set to FALSE to leave one
301 or all multicast groups.
302 @param[in] MulticastAddress Pointer to multicast group address to join or leave.
304 @retval EFI_SUCCESS The operation completed successfully.
305 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
306 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
307 RARP, etc.) is not finished yet.
308 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
309 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
311 - JoinFlag is TRUE and MulticastAddress is NULL.
312 - JoinFlag is TRUE and *MulticastAddress is not
313 a valid multicast address.
314 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
316 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is
318 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
324 IN EFI_UDP4_PROTOCOL
*This
,
326 IN EFI_IPv4_ADDRESS
*MulticastAddress OPTIONAL
330 UDP4_INSTANCE_DATA
*Instance
;
331 EFI_IP4_PROTOCOL
*Ip
;
335 if ((This
== NULL
) || (JoinFlag
&& (MulticastAddress
== NULL
))) {
336 return EFI_INVALID_PARAMETER
;
341 CopyMem (&McastIp
, MulticastAddress
, sizeof (IP4_ADDR
));
343 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
344 return EFI_INVALID_PARAMETER
;
348 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
350 if (Instance
->IsNoMapping
) {
351 return EFI_NO_MAPPING
;
354 if (!Instance
->Configured
) {
355 return EFI_NOT_STARTED
;
358 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
360 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
363 // Invoke the Ip instance the Udp4 instance consumes to do the group operation.
365 Status
= Ip
->Groups (Ip
, JoinFlag
, MulticastAddress
);
367 if (EFI_ERROR (Status
)) {
372 // Keep a local copy of the configured multicast IPs because IpIo receives
373 // datagrams from the 0 station address IP instance and then UDP delivers to
374 // the matched instance. This copy of multicast IPs is used to avoid receive
375 // the mutlicast datagrams destined to multicast IPs the other instances configured.
379 NetMapInsertTail (&Instance
->McastIps
, (VOID
*) (UINTN
) McastIp
, NULL
);
382 NetMapIterate (&Instance
->McastIps
, Udp4LeaveGroup
, MulticastAddress
);
387 gBS
->RestoreTPL (OldTpl
);
394 Adds and deletes routing table entries.
396 The Routes() function adds a route to or deletes a route from the routing table.
397 Routes are determined by comparing the SubnetAddress with the destination IP
398 address and arithmetically AND-ing it with the SubnetMask. The gateway address
399 must be on the same subnet as the configured station address.
400 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
401 The default route matches all destination IP addresses that do not match any
403 A zero GatewayAddress is a nonroute. Packets are sent to the destination IP
404 address if it can be found in the Address Resolution Protocol (ARP) cache or
405 on the local subnet. One automatic nonroute entry will be inserted into the
406 routing table for outgoing packets that are addressed to a local subnet
407 (gateway address of 0.0.0.0).
408 Each instance of the EFI UDPv4 Protocol has its own independent routing table.
409 Instances of the EFI UDPv4 Protocol that use the default IP address will also
410 have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These
411 copies will be updated automatically whenever the IP driver reconfigures its
412 instances; as a result, the previous modification to these copies will be lost.
414 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
415 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table.
416 Set to FALSE to add this route to the routing table.
417 @param[in] SubnetAddress The destination network address that needs to be routed.
418 @param[in] SubnetMask The subnet mask of SubnetAddress.
419 @param[in] GatewayAddress The gateway IP address for this route.
421 @retval EFI_SUCCESS The operation completed successfully.
422 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
423 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
424 - RARP, etc.) is not finished yet.
425 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
426 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
427 @retval EFI_NOT_FOUND This route is not in the routing table.
428 @retval EFI_ACCESS_DENIED The route is already defined in the routing table.
434 IN EFI_UDP4_PROTOCOL
*This
,
435 IN BOOLEAN DeleteRoute
,
436 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
437 IN EFI_IPv4_ADDRESS
*SubnetMask
,
438 IN EFI_IPv4_ADDRESS
*GatewayAddress
441 UDP4_INSTANCE_DATA
*Instance
;
442 EFI_IP4_PROTOCOL
*Ip
;
445 return EFI_INVALID_PARAMETER
;
448 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
450 if (Instance
->IsNoMapping
) {
451 return EFI_NO_MAPPING
;
454 if (!Instance
->Configured
) {
455 return EFI_NOT_STARTED
;
458 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
461 // Invoke the Ip instance the Udp4 instance consumes to do the actual operation.
463 return Ip
->Routes (Ip
, DeleteRoute
, SubnetAddress
, SubnetMask
, GatewayAddress
);
468 Queues outgoing data packets into the transmit queue.
470 The Transmit() function places a sending request to this instance of the EFI
471 UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever
472 the packet in the token is sent out or some errors occur, the Token.Event will
473 be signaled and Token.Status is updated. Providing a proper notification function
474 and context for the event will enable the user to receive the notification and
477 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
478 @param[in] Token Pointer to the completion token that will be placed into the
481 @retval EFI_SUCCESS The data has been queued for transmission.
482 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
483 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
484 RARP, etc.) is not finished yet.
485 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
486 @retval EFI_ACCESS_DENIED The transmit completion token with the same
487 Token.Event was already in the transmit queue.
488 @retval EFI_NOT_READY The completion token could not be queued because the
489 transmit queue is full.
490 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
491 @retval EFI_NOT_FOUND There is no route to the destination network or address.
492 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP packet
493 size. Or the length of the IP header + UDP header + data
494 length is greater than MTU if DoNotFragment is TRUE.
500 IN EFI_UDP4_PROTOCOL
*This
,
501 IN EFI_UDP4_COMPLETION_TOKEN
*Token
505 UDP4_INSTANCE_DATA
*Instance
;
508 EFI_UDP_HEADER
*Udp4Header
;
509 EFI_UDP4_CONFIG_DATA
*ConfigData
;
511 IP4_ADDR Destination
;
512 EFI_UDP4_TRANSMIT_DATA
*TxData
;
513 EFI_UDP4_SESSION_DATA
*UdpSessionData
;
514 UDP4_SERVICE_DATA
*Udp4Service
;
515 IP_IO_OVERRIDE Override
;
517 EFI_IP_ADDRESS IpDestAddr
;
519 if ((This
== NULL
) || (Token
== NULL
)) {
520 return EFI_INVALID_PARAMETER
;
523 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
525 if (Instance
->IsNoMapping
) {
526 return EFI_NO_MAPPING
;
529 if (!Instance
->Configured
) {
530 return EFI_NOT_STARTED
;
533 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
536 // Validate the Token, if the token is invalid return the error code.
538 Status
= Udp4ValidateTxToken (Instance
, Token
);
539 if (EFI_ERROR (Status
)) {
543 if (EFI_ERROR (NetMapIterate (&Instance
->TxTokens
, Udp4TokenExist
, Token
)) ||
544 EFI_ERROR (NetMapIterate (&Instance
->RxTokens
, Udp4TokenExist
, Token
))) {
546 // Try to find a duplicate token in the two token maps, if found, return
547 // EFI_ACCESS_DENIED.
549 Status
= EFI_ACCESS_DENIED
;
553 TxData
= Token
->Packet
.TxData
;
556 // Create a net buffer to hold the user buffer and the udp header.
558 Packet
= NetbufFromExt (
559 (NET_FRAGMENT
*)TxData
->FragmentTable
,
560 TxData
->FragmentCount
,
563 Udp4NetVectorExtFree
,
566 if (Packet
== NULL
) {
567 Status
= EFI_OUT_OF_RESOURCES
;
572 // Store the IpIo in ProtoData.
574 Udp4Service
= Instance
->Udp4Service
;
575 *((UINTN
*) &Packet
->ProtoData
[0]) = (UINTN
) (Udp4Service
->IpIo
);
577 Udp4Header
= (EFI_UDP_HEADER
*) NetbufAllocSpace (Packet
, UDP4_HEADER_SIZE
, TRUE
);
578 ASSERT (Udp4Header
!= NULL
);
580 ConfigData
= &Instance
->ConfigData
;
583 // Fill the udp header.
585 Udp4Header
->SrcPort
= HTONS (ConfigData
->StationPort
);
586 Udp4Header
->DstPort
= HTONS (ConfigData
->RemotePort
);
587 Udp4Header
->Length
= HTONS ((UINT16
) Packet
->TotalSize
);
588 Udp4Header
->Checksum
= 0;
590 UdpSessionData
= TxData
->UdpSessionData
;
591 Override
.Ip4OverrideData
.SourceAddress
= ConfigData
->StationAddress
;
593 if (UdpSessionData
!= NULL
) {
595 // Set the SourceAddress, SrcPort and Destination according to the specified
598 if (!EFI_IP4_EQUAL (&UdpSessionData
->SourceAddress
, &mZeroIp4Addr
)) {
599 CopyMem (&Override
.Ip4OverrideData
.SourceAddress
, &UdpSessionData
->SourceAddress
, sizeof (EFI_IPv4_ADDRESS
));
602 if (UdpSessionData
->SourcePort
!= 0) {
603 Udp4Header
->SrcPort
= HTONS (UdpSessionData
->SourcePort
);
606 if (UdpSessionData
->DestinationPort
!= 0) {
607 Udp4Header
->DstPort
= HTONS (UdpSessionData
->DestinationPort
);
610 CopyMem (&Source
, &Override
.Ip4OverrideData
.SourceAddress
, sizeof (IP4_ADDR
));
611 CopyMem (&Destination
, &UdpSessionData
->DestinationAddress
, sizeof (IP4_ADDR
));
614 // calculate the pseudo head checksum using the overridden parameters.
616 HeadSum
= NetPseudoHeadChecksum (
624 // UdpSessionData is NULL, use the address and port information previously configured.
626 CopyMem (&Destination
, &ConfigData
->RemoteAddress
, sizeof (IP4_ADDR
));
628 HeadSum
= Instance
->HeadSum
;
632 // calculate the checksum.
634 Udp4Header
->Checksum
= Udp4Checksum (Packet
, HeadSum
);
635 if (Udp4Header
->Checksum
== 0) {
637 // If the calculated checksum is 0, fill the Checksum field with all ones.
639 Udp4Header
->Checksum
= 0xffff;
643 // Fill the IpIo Override data.
645 if (TxData
->GatewayAddress
!= NULL
) {
646 CopyMem (&Override
.Ip4OverrideData
.GatewayAddress
, TxData
->GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
648 ZeroMem (&Override
.Ip4OverrideData
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
651 Override
.Ip4OverrideData
.Protocol
= EFI_IP_PROTO_UDP
;
652 Override
.Ip4OverrideData
.TypeOfService
= ConfigData
->TypeOfService
;
653 Override
.Ip4OverrideData
.TimeToLive
= ConfigData
->TimeToLive
;
654 Override
.Ip4OverrideData
.DoNotFragment
= ConfigData
->DoNotFragment
;
657 // Save the token into the TxToken map.
659 Status
= NetMapInsertTail (&Instance
->TxTokens
, Token
, Packet
);
660 if (EFI_ERROR (Status
)) {
665 // Send out this datagram through IpIo.
667 IpDestAddr
.Addr
[0] = Destination
;
677 if (EFI_ERROR (Status
)) {
679 // Remove this token from the TxTokens.
681 Udp4RemoveToken (&Instance
->TxTokens
, Token
);
690 gBS
->RestoreTPL (OldTpl
);
697 Places an asynchronous receive request into the receiving queue.
699 The Receive() function places a completion token into the receive packet queue.
700 This function is always asynchronous.
701 The caller must fill in the Token.Event field in the completion token, and this
702 field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol
703 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
704 is signaled. Providing a proper notification function and context for the event
705 will enable the user to receive the notification and receiving status. That
706 notification function is guaranteed to not be re-entered.
708 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
709 @param[in] Token Pointer to a token that is associated with
710 the receive data descriptor.
712 @retval EFI_SUCCESS The receive completion token was cached.
713 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
714 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, RARP, etc.)
716 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
717 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
718 resources (usually memory).
719 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
720 @retval EFI_ACCESS_DENIED A receive completion token with the same Token.Event was already in
722 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
728 IN EFI_UDP4_PROTOCOL
*This
,
729 IN EFI_UDP4_COMPLETION_TOKEN
*Token
733 UDP4_INSTANCE_DATA
*Instance
;
736 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
737 return EFI_INVALID_PARAMETER
;
740 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
742 if (Instance
->IsNoMapping
) {
743 return EFI_NO_MAPPING
;
746 if (!Instance
->Configured
) {
747 return EFI_NOT_STARTED
;
750 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
752 if (EFI_ERROR (NetMapIterate (&Instance
->RxTokens
, Udp4TokenExist
, Token
))||
753 EFI_ERROR (NetMapIterate (&Instance
->TxTokens
, Udp4TokenExist
, Token
))) {
755 // Return EFI_ACCESS_DENIED if the specified token is already in the TxTokens or
758 Status
= EFI_ACCESS_DENIED
;
762 Token
->Packet
.RxData
= NULL
;
765 // Save the token into the RxTokens map.
767 Status
= NetMapInsertTail (&Instance
->RxTokens
, Token
, NULL
);
768 if (EFI_ERROR (Status
)) {
769 Status
= EFI_NOT_READY
;
774 // If there is an icmp error, report it.
776 Udp4ReportIcmpError (Instance
);
779 // Try to deliver the received datagrams.
781 Udp4InstanceDeliverDgram (Instance
);
784 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
790 gBS
->RestoreTPL (OldTpl
);
797 Aborts an asynchronous transmit or receive request.
799 The Cancel() function is used to abort a pending transmit or receive request.
800 If the token is in the transmit or receive request queues, after calling this
801 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
802 signaled. If the token is not in one of the queues, which usually means that
803 the asynchronous operation has completed, this function will not signal the
804 token and EFI_NOT_FOUND is returned.
806 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
807 @param[in] Token Pointer to a token that has been issued by
808 EFI_UDP4_PROTOCOL.Transmit() or
809 EFI_UDP4_PROTOCOL.Receive().If NULL, all pending
812 @retval EFI_SUCCESS The asynchronous I/O request was aborted and Token.Event
813 was signaled. When Token is NULL, all pending requests are
814 aborted and their events are signaled.
815 @retval EFI_INVALID_PARAMETER This is NULL.
816 @retval EFI_NOT_STARTED This instance has not been started.
817 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
818 RARP, etc.) is not finished yet.
819 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
820 not found in the transmit or receive queue. It has either completed
821 or was not issued by Transmit() and Receive().
827 IN EFI_UDP4_PROTOCOL
*This
,
828 IN EFI_UDP4_COMPLETION_TOKEN
*Token OPTIONAL
832 UDP4_INSTANCE_DATA
*Instance
;
836 return EFI_INVALID_PARAMETER
;
839 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
841 if (Instance
->IsNoMapping
) {
842 return EFI_NO_MAPPING
;
845 if (!Instance
->Configured
) {
846 return EFI_NOT_STARTED
;
849 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
852 // Cancle the tokens specified by Token for this instance.
854 Status
= Udp4InstanceCancelToken (Instance
, Token
);
857 // Dispatch the DPC queued by the NotifyFunction of the cancelled token's events.
861 gBS
->RestoreTPL (OldTpl
);
868 Polls for incoming data packets and processes outgoing data packets.
870 The Poll() function can be used by network drivers and applications to increase
871 the rate that data packets are moved between the communications device and the
872 transmit and receive queues.
873 In some systems, the periodic timer event in the managed network driver may not
874 poll the underlying communications device fast enough to transmit and/or receive
875 all data packets without missing incoming packets or dropping outgoing packets.
876 Drivers and applications that are experiencing packet loss should try calling
877 the Poll() function more often.
879 @param[in] This Pointer to the EFI_UDP4_PROTOCOL instance.
881 @retval EFI_SUCCESS Incoming or outgoing data was processed.
882 @retval EFI_INVALID_PARAMETER This is NULL.
883 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
884 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
890 IN EFI_UDP4_PROTOCOL
*This
893 UDP4_INSTANCE_DATA
*Instance
;
894 EFI_IP4_PROTOCOL
*Ip
;
897 return EFI_INVALID_PARAMETER
;
900 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (This
);
901 Ip
= Instance
->IpInfo
->Ip
.Ip4
;
904 // Invode the Ip instance consumed by the udp instance to do the poll operation.
906 return Ip
->Poll (Ip
);