2 This library is used to share code between UEFI network stack modules.
3 It provides the helper routines to access UDP service. It is used by both DHCP and MTFTP.
5 Copyright (c) 2006 - 2008, Intel Corporation.<BR>
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<BR>
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.
19 #include <Protocol/Udp4.h>
21 #include <Library/NetLib.h>
23 typedef struct _UDP_IO_PORT UDP_IO_PORT
;
26 /// Signatures used by UdpIo Library.
29 UDP_IO_RX_SIGNATURE
= SIGNATURE_32 ('U', 'D', 'P', 'R'),
30 UDP_IO_TX_SIGNATURE
= SIGNATURE_32 ('U', 'D', 'P', 'T'),
31 UDP_IO_SIGNATURE
= SIGNATURE_32 ('U', 'D', 'P', 'I')
32 } UDP_IO_SIGNATURE_TYPE
;
35 /// The Udp4 address pair.
45 Prototype called when receiving or sending packets to or from a UDP point.
47 This prototype is used by both receive and sending when calling
48 UdpIoRecvDatagram() or UdpIoSendDatagram(). When receiving, Netbuf is allocated by the
49 UDP access point and released by the user. When sending, the user allocates the the NetBuf, which is then
50 provided to the callback as a reference.
52 @param[in] Packet Packet received or sent
53 @param[in] Points The Udp4 address pair corresponds to the Udp4 IO
54 @param[in] IoStatus Packet receiving or sending status
55 @param[in] Context User-defined data when calling UdpIoRecvDatagram() or
62 IN UDP_POINTS
*Points
,
63 IN EFI_STATUS IoStatus
,
68 /// This structure is used internally by the UdpIo Library.
70 /// Each receive request is wrapped in an UDP_RX_TOKEN. Upon completion,
71 /// the CallBack will be called. Only one receive request is sent to UDP at a
72 /// time. HeadLen gives the length of the application's header. UDP_IO will
73 /// make the application's header continuous before delivering up.
79 UDP_IO_CALLBACK CallBack
;
83 EFI_UDP4_COMPLETION_TOKEN UdpToken
;
87 /// This structure is used internally by UdpIo Library.
89 /// Each transmit request is wrapped in an UDP_TX_TOKEN. Upon completion,
90 /// the CallBack will be called. There can be several transmit requests. All transmit requests
91 /// are linked in a list.
98 UDP_IO_CALLBACK CallBack
;
102 EFI_UDP4_SESSION_DATA UdpSession
;
103 EFI_IPv4_ADDRESS Gateway
;
105 EFI_UDP4_COMPLETION_TOKEN UdpToken
;
106 EFI_UDP4_TRANSMIT_DATA UdpTxData
;
110 /// Type defined as UDP_IO_PORT.
112 /// This data structure wraps the Udp4 instance and configuration.
113 /// UdpIo Library uses this structure for all Udp4 operations.
115 struct _UDP_IO_PORT
{
121 // Handle used to create/destory UDP child
123 EFI_HANDLE Controller
;
125 EFI_HANDLE UdpHandle
;
127 EFI_UDP4_PROTOCOL
*Udp
; ///< The wrapped Udp4 instance.
128 EFI_UDP4_CONFIG_DATA UdpConfig
;
129 EFI_SIMPLE_NETWORK_MODE SnpMode
;
131 LIST_ENTRY SentDatagram
; ///< A list of UDP_TX_TOKEN.
132 UDP_RX_TOKEN
*RecvRequest
;
136 Prototype called when UdpIo Library configures a Udp4 instance.
138 The prototype is set and called when creating a UDP_IO_PORT in UdpIoCreatePort().
140 @param[in] UdpIo The UDP_IO_PORT to configure
141 @param[in] Context User-defined data when calling UdpIoCreatePort()
143 @retval EFI_SUCCESS The configuration succeeded
144 @retval Others The UDP_IO_PORT fails to configure indicating
145 UdpIoCreatePort() should fail
150 IN UDP_IO_PORT
*UdpIo
,
155 The select function to decide whether to cancel the UDP_TX_TOKEN.
157 @param[in] Token The UDP_TX_TOKEN to decide whether to cancel
158 @param[in] Context User-defined data in UdpIoCancelDgrams()
160 @retval TRUE Cancel the UDP_TX_TOKEN
161 @retval FALSE Do not cancel this UDP_TX_TOKEN
166 (*UDP_IO_TO_CANCEL
) (
167 IN UDP_TX_TOKEN
*Token
,
172 Cancel all sent datagrams selected by the parameter ToCancel.
173 If ToCancel is NULL, all the datagrams are cancelled.
175 @param[in] UdpIo The UDP_IO_PORT to cancel packet.
176 @param[in] IoStatus The IoStatus to return to the packet owners.
177 @param[in] ToCancel Sets the criteria for canceling a packet.
178 @param[in] Context The opaque parameter to the ToCancel.
184 IN UDP_IO_PORT
*UdpIo
,
185 IN EFI_STATUS IoStatus
,
186 IN UDP_IO_TO_CANCEL ToCancel
, OPTIONAL
191 Creates a UDP_IO_PORT to access the UDP service. It creates and configures
195 # locates the UDP service binding prototype on the Controller parameter
196 # uses the UDP service binding prototype to create a UDP child (also known as a UDP instance)
197 # configures the UDP child by calling Configure function prototype.
198 Any failures in creating or configuring the UDP child return NULL for failure.
200 @param[in] Controller The controller that has the UDP service binding.
202 @param[in] Image The image handle for the driver.
203 @param[in] Configure The function to configure the created UDP child.
204 @param[in] Context The opaque parameter for the Configure funtion.
206 @return Newly-created UDP_IO_PORT or NULL if failed.
212 IN EFI_HANDLE Controller
,
214 IN UDP_IO_CONFIG Configure
,
219 Free the UDP_IO_PORT and all its related resources.
221 The function cancels all sent datagrams and receive requests.
223 @param[in] UdpIo The UDP_IO_PORT to free.
225 @retval EFI_SUCCESS The UDP_IO_PORT is freed.
231 IN UDP_IO_PORT
*UdpIo
235 Cleans up the UDP_IO_PORT without freeing it. Call this function
236 if you intend to later re-use the UDP_IO_PORT.
238 This function releases all transmitted datagrams and receive requests and configures NULL for the UDP instance.
240 @param[in] UdpIo The UDP_IO_PORT to clean up.
246 IN UDP_IO_PORT
*UdpIo
250 Sends a packet through the UDP_IO_PORT.
252 The packet will be wrapped in UDP_TX_TOKEN. The function specific in the CallBack parameter will be called
253 when the packet is sent. If specified, the optional parameter EndPoint overrides the default
256 @param[in] UdpIo The UDP_IO_PORT to send the packet through.
257 @param[in] Packet The packet to send.
258 @param[in] EndPoint The local and remote access point. Overrides the
259 default address pair set during configuration.
260 @param[in] Gateway The gateway to use.
261 @param[in] CallBack The function being called when packet is
262 transmitted or failed.
263 @param[in] Context The opaque parameter passed to CallBack.
265 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet.
266 @retval EFI_SUCCESS The packet is successfully delivered to UDP for
273 IN UDP_IO_PORT
*UdpIo
,
275 IN UDP_POINTS
*EndPoint
, OPTIONAL
277 IN UDP_IO_CALLBACK CallBack
,
282 Cancel a single sent datagram.
284 @param[in] UdpIo The UDP_IO_PORT from which to cancel the packet
285 @param[in] Packet The packet to cancel
290 UdpIoCancelSentDatagram (
291 IN UDP_IO_PORT
*UdpIo
,
296 Issue a receive request to the UDP_IO_PORT.
298 This function is called when upper-layer needs packet from UDP for processing.
299 Only one receive request is acceptable at a time. Therefore, one common usage model is
300 to invoke this function inside its Callback function when the former packet
303 @param[in] UdpIo The UDP_IO_PORT to receive the packet from.
304 @param[in] CallBack The call back function to execute when the packet
306 @param[in] Context The opaque context passed to Callback.
307 @param[in] HeadLen The length of the upper-layer's protocol header.
309 @retval EFI_ALREADY_STARTED There is already a pending receive request. Only
310 one receive request is supported at a time.
311 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
312 @retval EFI_SUCCESS The receive request is issued successfully.
318 IN UDP_IO_PORT
*UdpIo
,
319 IN UDP_IO_CALLBACK CallBack
,