2 The helper routines to access UDP service. It is used by both
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. 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.
21 #include <Protocol/Udp4.h>
23 #include <Library/UdpIoLib.h>
24 #include <Library/NetLib.h>
26 typedef struct _UDP_IO_PORT UDP_IO_PORT
;
29 UDP_IO_RX_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'D', 'P', 'R'),
30 UDP_IO_TX_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'D', 'P', 'T'),
31 UDP_IO_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'D', 'P', 'I'),
42 // This prototype is used by both receive and transmission.
43 // When receiving Netbuf is allocated by UDP access point, and
44 // released by user. When transmitting, the NetBuf is from user,
45 // and provided to the callback as a reference.
51 IN UDP_POINTS
*Points
,
52 IN EFI_STATUS IoStatus
,
57 // Each receive request is wrapped in an UDP_RX_TOKEN. Upon completion,
58 // the CallBack will be called. Only one receive request is send to UDP.
59 // HeadLen gives the length of the application's header. UDP_IO will
60 // make the application's header continous before delivery up.
66 UDP_IO_CALLBACK CallBack
;
70 EFI_UDP4_COMPLETION_TOKEN UdpToken
;
74 // Each transmit request is wrapped in an UDP_TX_TOKEN. Upon completion,
75 // the CallBack will be called. There can be several transmit requests.
82 UDP_IO_CALLBACK CallBack
;
86 EFI_UDP4_SESSION_DATA UdpSession
;
87 EFI_IPv4_ADDRESS Gateway
;
89 EFI_UDP4_COMPLETION_TOKEN UdpToken
;
90 EFI_UDP4_TRANSMIT_DATA UdpTxData
;
99 // Handle used to create/destory UDP child
101 EFI_HANDLE Controller
;
103 EFI_HANDLE UdpHandle
;
105 EFI_UDP4_PROTOCOL
*Udp
;
106 EFI_UDP4_CONFIG_DATA UdpConfig
;
107 EFI_SIMPLE_NETWORK_MODE SnpMode
;
109 LIST_ENTRY SentDatagram
;
110 UDP_RX_TOKEN
*RecvRequest
;
116 IN UDP_IO_PORT
*UdpIo
,
122 (*UDP_IO_TO_CANCEL
) (
123 IN UDP_TX_TOKEN
*Token
,
128 Create a UDP IO port to access the UDP service. It will
129 create and configure a UDP child.
131 @param Controller The controller that has the UDP service binding
133 @param Image The image handle for the driver.
134 @param Configure The function to configure the created UDP child
135 @param Context The opaque parameter for the Configure funtion.
137 @return A point to just created UDP IO port or NULL if failed.
143 IN EFI_HANDLE Controller
,
144 IN EFI_HANDLE ImageHandle
,
145 IN UDP_IO_CONFIG Configure
,
150 Free the UDP IO port and all its related resources including
151 all the transmitted packet.
153 @param UdpIo The UDP IO port to free.
155 @retval EFI_SUCCESS The UDP IO port is freed.
161 IN UDP_IO_PORT
*UdpIo
165 Clean up the UDP IO port. It will release all the transmitted
166 datagrams and receive request. It will also configure NULL the
169 @param UdpIo UDP IO port to clean up.
177 IN UDP_IO_PORT
*UdpIo
181 Send a packet through the UDP IO port.
183 @param UdpIo The UDP IO Port to send the packet through
184 @param Packet The packet to send
185 @param EndPoint The local and remote access point
186 @param Gateway The gateway to use
187 @param CallBack The call back function to call when packet is
188 transmitted or failed.
189 @param Context The opque parameter to the CallBack
191 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet
192 @retval EFI_SUCCESS The packet is successfully delivered to UDP for
199 IN UDP_IO_PORT
*UdpIo
,
201 IN UDP_POINTS
*EndPoint
, OPTIONAL
203 IN UDP_IO_CALLBACK CallBack
,
208 The selection function to cancel a single sent datagram.
210 @param Token The UDP TX token to test againist.
211 @param Context The context
213 @return TRUE if the packet is to be cancelled, otherwise FALSE.
218 UdpIoCancelSentDatagram (
219 IN UDP_IO_PORT
*UdpIo
,
224 Issue a receive request to the UDP IO port.
226 @param UdpIo The UDP IO port to recieve the packet from.
227 @param CallBack The call back function to execute when receive
229 @param Context The opque context to the call back
230 @param HeadLen The lenght of the application's header
232 @retval EFI_ALREADY_STARTED There is already a pending receive request. Only
233 one receive request is supported.
234 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource.
235 @retval EFI_SUCCESS The receive request is issued successfully.
241 IN UDP_IO_PORT
*UdpIo
,
242 IN UDP_IO_CALLBACK CallBack
,